結果

問題 No.2064 Smallest Sequence on Grid
ユーザー とりゐ
提出日時 2022-08-27 11:37:19
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 546 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 856,156 KB
最終ジャッジ日時 2024-11-16 01:35:57
合計ジャッジ時間 69,714 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 MLE * 1
other AC * 10 TLE * 10 MLE * 9
権限があれば一括ダウンロードができます

ソースコード

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=[]
  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.append((x+dx,y+dy))
print(*ans,sep='')
0