#880
Silver IV
PRVA
시간 제한
1s
메모리 제한
32MB
제출
1
정답
1
맞힌 사람
1
정답 비율
100.0%

문제

Little Ivica solves crossword puzzles every day. In case you haven't seen one, a crossword puzzle starts on a grid of R×C squares, each of which is either empty or blocked. The player's task is to write words in consecutive empty squares vertically (top down) or horizontally (left to right). Ivica's sister has a strange habit of looking at crosswords Ivica has finished solving, and finding the lexicographically smallest word in it. She only considers words at least 2 characters long. Write a program that, given a crossword puzzle, finds that word.

입력

The first line contains two integers R and C (2 ≤ R, C ≤ 20), the number of rows and columns in the crossword. Each of the following R lines contains a string of C characters. Each of those characters is either a lowercase letter of the English alphabet, or the character '#' representing a blocked square. The input will be such that a solution will always exist.

출력

Output the lexicographically smallest word in the crossword.

예제 입력 1

4 4
luka
o#a#
kula
i#a#

예제 출력 1

kala

예제 입력 2

4 4
luka
o#a#
kula
i#as

예제 출력 2

as

예제 입력 3

4 5
adaca
da##b
abb#b
abbac

예제 출력 3

abb
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
#순위사용자언어시간메모리코드 길이
9479🥇
안우진
PyPy24ms49492KB664B
난이도 투표
Silver IV2명 투표· 8일 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
#사용자문제결과언어시간메모리코드 길이제출 시간
9479
맞았습니다
PyPy24ms49492KB664B2026. 07. 13. 16:30