結果

問題 No.2064 Smallest Sequence on Grid
ユーザー とりゐ
提出日時 2022-08-27 11:38:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,650 ms / 3,000 ms
コード長 546 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 177,536 KB
最終ジャッジ日時 2024-11-16 01:37:24
合計ジャッジ時間 21,509 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def f(x):
  return ord(x)-97

h,w=map(int,input().split())
s=[]
for i in range(h):
  s.append(input())
a=[[0]*w for i in range(h)]
a[0][0]=1
dxdy=[(0,1),(1,0)]
ans=[]
todo=[(0,0)]
for i in range(h+w-1):
  d=[]
  mn='z'
  for x,y in todo:
    if mn==s[x][y]:
      d.append((x,y))
    elif mn>s[x][y]:
      d=[(x,y)]
      mn=s[x][y]
  ans.append(mn)
  todo=set()
  for x,y in d:
    for dx,dy in dxdy:
      if 0<=x+dx<h and 0<=y+dy<w:
        a[x+dx][y+dy]=1
        todo.add((x+dx,y+dy))
print(*ans,sep='')
0