結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kozy
提出日時 2022-09-02 22:15:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,328 ms / 3,000 ms
コード長 488 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 119,632 KB
最終ジャッジ日時 2024-11-16 03:58:47
合計ジャッジ時間 17,425 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
L=list()
for i in range(H):
  s=input()
  L.append(s)
ans=list()
ans.append(L[0][0])
A=[0,0]
def f(x,y):
  if 0<=x<H and 0<=y<W:
    return True
  return False
stack=[[0,0]]
for i in range(H+W-2):
  s="z"
  S=set()
  while stack:
    a,b=stack.pop()
    for da,db in [[1,0],[0,1]]:
      if f(a+da,b+db):
        s=min(s,L[a+da][b+db])
        S.add((a+da,b+db))
  for a,b in S:
    if L[a][b]==s:
      stack.append((a,b))
  ans.append(s)
print("".join(ans))
0