시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 189 57 47 27.976%

문제

고고학자는 초기 문명을 이해하기 위해서 고대 언어로 된 글을 공부하기도 한다.

이집트는 3000년전에 각종 동물이나 사물, 신체의 모습을 본딴 고대 언어 "신성 문자"를 만들었다.

이 문제에서, 아래와 같은 글자 여섯개를 인식하는 프로그램을 작성하시오.

입력

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 하나 또는 그 이상의 신성 문자를 포함하는 그림으로 이루어져 있다. 그림은 1 또는 0으로 이루어져 있고, 1은 검정 픽셀, 0은 흰색 픽셀이다.

입력 데이터에서 각각의 줄은 16진수로 인코딩 되어 있다. 예를 들어, 여덟 픽셀 10011100은 9c로 인코딩 되어 있다. 16진수 인코딩에서 사용되는 문자는 0-9와 a-f이다.

첫 줄은 H와 W로 이루어져 있다. H(0 < H ≤ 200)는 줄의 수, W(0 < W ≤ 50)는 각 줄에 있는 16진수 문자의 개수이다. 다음 H개의 줄에는 그림이 주어진다. 입력으로 주어지는 그림은 다음과 같은 규칙을 만족한다.

  1. 이미지는 문제의 설명에 주어진 6개의 신성 문자만 포함한다.
  2. 모든 이미지는 적어도 1개의 올바른 신성 문자를 포함한다.
  3. 모든 검정 픽셀은 올바른 신성 문자의 일부이다.
  4. 신성 문자는 검정 픽셀이 이어진 형태이다. 모든 검정 픽셀의 위, 아래, 왼쪽, 오른쪽 픽셀 중 하나는 검정 픽셀이다.
  5. 신성 문자는 서로 접하지 않으며, 한 문자 안에 또다른 문자가 포함된 경우는 없다.
  6. 두 검정 픽셀이 대각선 방향으로 접한다면, 항상 두 픽셀은 공통으로 접하는 검정 픽셀이 있다.
  7. 신성 문자는 비뚤어져 있을 수도 있다. 하지만, 그 모양은 항상 문제에 주어진 그림과 같다.

마지막 테스트 케이스의 다음에는 0 2개가 주어진다.

출력

각각의 테스트 케이스에 대해서, 케이스 번호를 출력한 뒤, 이미지에 써 있는 신성 문자를 출력하나. 이 때, 다음과 같은 코드를 사용한다.

  • Ankh: A
  • Wedjat: J
  • Djed: D
  • Scarab: S
  • Was: W
  • Akhet: K

이미지에 써있는 문자를 알파벳 순서대로 출력하며, 예제 출력의 형식을 따르면 된다.

예제 입력

100 25
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
00000f8000000000000000000
00001fe000000000000000000
00007ff000000000000000000
00007ff800000000000000000
0000f8f800000000000000000
0001f07c00000000000000000
0001e03c00000000001800000
0001e01c00000000003c00000
0001c01c00000000007c00000
0003c01e0000000000f800000
0003c01e0000000001f000000
0001c01c0000000003f000000
0001c01c0000000007e000000
0001e01c000000000fc000000
0001e03c000000001fc000000
0000e03c000000001fc000000
0000f038000000003ff000000
0000f078000000003ff800000
00007870000000007ff800000
000038f0000000007cfc00000
00003ce0000000007c7c00000
00781fc0f0000000f87c00000
007ffffff0000000f07c00000
007ffffff0000000f07c00000
007ffffff0000001f07c00000
007ffffff0000000e03e00000
007fcf81f0000000603e00000
00000f8000000000003e00000
00000f8000000000003e00000
00000f8000000000003e00000
00000f8000000000001e00000
00000f8000000000001f00000
00000fc000000000001f00000
00000fc000000000001f00000
00000fc000000000001f00000
00000fc000000000000f00000
00001fc000000000000f80000
00001fc000000000000f80000
00001fc000000000000f80000
00001fc000000000000f80000
00001fe000000000000f80000
00001fe000000000000780000
00001fe0000000000007c0000
00001fe0000000000007c0000
00003fe0000000000007c0000
00003fe0000000000007c0000
00003fe0000000000007c0000
00003fe0000c00000003c0000
00000000003ff0000003c0000
00000000007ff8000003e0000
0000000001fffc000003e0000
0000000003e03f000003e0000
0000000007c00f000003e0000
000000000f0003800003f0000
000000000e0001c00003fc000
000000001c0001e00007fe000
000000003c0000e0000fff000
000000073c000070000fdf000
0000001ff8000070001f0f800
0000001ff8000070001e07800
0000003cf0000078001e03800
0000003870000033001e03800
000000307800003fc01e03800
000000703800007fe00e03800
000000703800007ce00e03800
000000703c000078700703800
000000701e0000f0700701000
000000701e0000e0700300000
000000700f0001c0700000000
0000006007800380600000000
000000e003e00700600000000
000000e001fe7e00600000000
000000e000fffc00e00000000
000000e0000ff000e00000000
000000f800038000e00000000
000000fff0000000e00000000
000000fffff00000e00000000
00000003ffffe000c00000000
0000000007ffffc0c00000000
000000000007ffffc00000000
0000000000000fffc00000000
000000000000001fc00000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
150 38
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000f80000000001fff000000000000000000
00001fe0000000007fff800000000000000000
00007ff000000000ffffe00000000000000000
00007ff800000003fffff0000000007c000000
0000f8f800000007fffffc00000000fe000000
0001f07c0000000ffffffe00000001ff000000
0001e03c0000001fffffff00000003ff800000
0001e01c0000003fffffff00000003ffc00000
0001c01c0000003fffffff80000007efc00000
0003c01e0000007fffffffc000000783c00000
0003c01e000000ffffffffc000000f81e00000
0001c01c000000fffc0fffe000000f01e00000
0001c01c000001fff003ffe000000f01e00000
0001e01c000001ffe001fff000000f00e00000
0001e03c000003ffc0007ff000001e00f00000
0000e03c000003ff80007ff800001e00f00000
0000f038000007ff80003ff800001e00f00000
0000f078000007ff00003ff800001e00f00000
00007870000007ff00001ffc00000e00e00000
000038f000000fff00001ffc00000e00e00000
00003ce000000ffe00000ffc00000e00e00000
00781fc0f0000ffe00000ffc00000f00e00000
007ffffff0000ffc00000ffc00000f01e00000
007ffffff0000ffc00000ffc00000f01e00000
007ffffff0000ffc00000ffc00000701c00000
007ffffff0000ffc00000ffc00000781c00000
007fcf81f0000ffc000007fc00000783c00000
00000f8000000ffc000007fc00000383800000
00000f8000000ffc000007fc000003c7800000
00000f8000000ffc000007fc000001c7800000
00000f8000000ffc000007fc000001e7000000
00000f8000000ffc000007fc000200ef008000
00000fc000000ffc00000ffc0003f8fe3f8000
00000fc000000ffc00000ffc0003ffffff8000
00000fc000000ffc00000ffc0003ffffff8000
00000fc000000ffc00000ffc0003ffffff8000
00001fc000000ffc00000ffc0003ffffff8000
00001fc0000007fe00000ff80003ffffff8000
00001fc0000007fe00000ff80003fffdff8000
00001fc0000007fe00000ff80003c03c000000
00001fe0000007ff00001ff80000007c000000
00001fe0000003ff00001ff00000007c000000
00001fe0000003ff00001ff00000007c000000
00001fe0000001ff80003ff00000007c000000
00003fe0000001ff80003fe00000007c000000
00003fe0000001ff80003fe00000007c000000
00003fe0000000ffc0007fe00000007c000000
00003fe0000000ffc0007fc00000007e000000
000000000000007fe0007fc00000007e000000
000000000000007fe000ff800000007e000000
000000000000007ff001ff800000007e000000
000000000000003ff001ff80000000fe000000
000000000000001ff803ff00000000fe000000
000000000000001ff803ff00000000fe000000
000000000000000ffc07fe00000000fe000000
000000000000000ffc0ffc00000000fe000000
000000000000000ffe0ffc00000000fe000000
0000000000000007ff0ff800000000fe000000
0000000000000003ff1ff000000000ff000000
0000000003c00001ffbff00000f000ff000000
0000000003ffc001ffffe0007ff000ff000000
0000000003fffff1ffffe3fffff000ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff001ff000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffffffffffffff00000000000
0000000003fffffc1ffe0007fff00000000000
0000000003ff80000ffe000000f00000000000
00000000038000000ffe000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000001fff000000000000000000
00000000000000003fff000000000000000000
00000000000000003fff000000000000000000
00000000000000003fff0000000fc000000000
000000000fe000003fff8000003ff000000000
000000003ffc00003fff8000007ffc00000000
00000000fffe00003fff800000fcfc00000000
00000001f01f00003fff800001f03e00000000
00000003e00f80003fff800003e01f00000000
00000003e00780003fff800003e00f00000000
00000003e00780003fff800003c00f00000000
00000003e00f80003fff800003c00f00000000
00000001f00f00007fff800003c00f00000000
00000000f81e00007fffc00003e00f00000000
000000007c3c00007fffc00001e01e00000000
000000003e7800007fffc00000f01e00000000
000000fffffffe007fffc00000f03c00000000
000000fffffffe007fffc00000787800000000
000000fffffffe007fffc000003cf000000000
0000000007c000007fffe000f81fe07c000000
0000000007e000007fffe000fffffffc000000
0000000007e000007fffe000fffffffc000000
000000000fe000007fffe000fffffffc000000
000000000ff00000ffffe000ffc7c0fc000000
000000000ff00000ffffe0000007c000000000
000000001ff00000ffffe000000fc000000000
000000001ff00000ffffe000000fc000000000
000000001ff80000ffffe000000fc000000000
000000001ff80000ffffe000000fc000000000
000000003ff80001ffffe000000fe000000000
000000003ff80001ffffe000000fe000000000
0000000000000001fffff000001fe000000000
0000000000000001fffff000001fe000000000
0000000000000001fffff000001fe000000000
0000000000000001fffff000001ff000000000
0000000000000001fffff000001ff000000000
0000000000000001fffff000001ff000000000
0000000000000001fffff000003ff000000000
0000000000000001fffff000003ff000000000
0000000000000001fffff000003ff000000000
0000000000000001fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffff80000000000000000
0000000000000003fffffc0000000000000000
0000000000000003fffffc0000000000000000
0000000000000007fffffc0000000000000000
0000000000000007fffffc0000000000000000
0000000000000007fffffc0000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
0 0

예제 출력

Case 1: AKW
Case 2: AAAAA

힌트

첫번째 예제: 

두번째 예제: 

출처

ACM-ICPC > World Finals > 2011 World Finals C번

  • 문제를 번역한 사람: baekjoon
  • 잘못된 조건을 찾은 사람: pichulia