RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 ICPC00151

M. Fantasmagorie

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
설명

1

Émile's dreams often feature people or animals who become distorted into others. Émile would like to show the enchanting world of his dreams to everybody by creating the very first animated cartoon, in black and white of course. After waking up, Émile only remembers the initial and final forms appearing in his dream, not the transformation itself, so he's asking you to reproduce these "morphings" by detailing the steps taken for transforming the first image into the second.

The images in Émile's dreams are not just any black and white image, they respect the following three constraints. First, all pixels on the border of the image – the leftmost and righmost columns, and the top and the bottom rows – have the same color. Second, the image does not contain any \(2 \times 2\) square of the form tikzpicture[scale=0.15] (0,0) – (0,2) – (2,2) – (2,0) – cycle (1,0) – (1,2) (0,1) – (2,1); [black] (0,0) – (0,1) – (1,1) – (1,0) – cycle (2,2) – (2,1) – (1,1) – (1,2) – cycle; tikzpicture or tikzpicture[scale=0.15] (0,0) – (0,2) – (2,2) – (2,0) – cycle (1,0) – (1,2) (0,1) – (2,1); [black] (2,0) – (2,1) – (1,1) – (1,0) – cycle (0,2) – (0,1) – (1,1) – (1,2) – cycle; tikzpicture.

The third constraint is more complex, and can be described as follows. Let us subdivide the image into regions, which are defined as the connected monochromatic areas of the image, i.e., they form the finest partition of the pixels such that any two adjacent pixels of the same color are in the same region. Two regions are considered adjacent if they contain adjacent pixels. In Émile's images, every region is adjacent to at most two other regions, and the region containing border pixels is adjacent to at most one other region.

You are given two black and white images of the same size \(W \times H\), and your goal is to find a "morphing" transforming the first image into the second one. A morphing from image \(A\) to image \(B\) is a sequence of images starting with \(A\) and ending with \(B\) such that:
- each image (except the first) can be obtained from the previous one by flipping one bit;
- each image respects the three above constraints;
- the number of regions of each color does not change during the morphing.

제약
입력 형식

The first line of the input contains two space-separated integers: \(W\) and \(H\). Then come \(H\) lines that describe the first image row by row, from top to bottom. Each of these lines is composed of \(W\) characters describing the row's \(W\) pixels, from left to right: the \(k\)-th character of the line is '.' if the \(k\)-th pixel of the row is white, and it is '#' if that pixel is black. Finally come \(H\) lines that describe the second image row by row, following the same format as above.

출력 형식

If no morphing exists, the output should contain the word "IMPOSSIBLE" on a single line. Otherwise, the output should describe one possible morphing as follows: if the \((k+1)\)-th image is obtained from the \(k\)-th image by flipping the pixel in column \(c\) and row \(r\) (with \(0 \le c < W\) and \(0 \le r < H\), where \(c = 0\) represents the leftmost column and \(r = 0\) represents the topmost row), the \(k\)-th output line contains the pair \((c,r)\).

예제 1
입력
4 3
....
.#..
....
....
..#.
....
출력
2 1
1 1
예제 2
입력
9 12
.........
...###...
...#.#...
.#######.
...###...
...###...
.#..#....
.#######.
...###.#.
...###...
..##.##..
.........
.........
..#####..
..##.##..
..#...#..
..#.#.#..
..#...#..
..#####..
...#.#...
...#.#...
...#.#...
.###.###.
.........
출력
IMPOSSIBLE
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC SWERC 2020

평가 및 의견

M. Fantasmagorie

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

M. Fantasmagorie

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8