結果

問題 No.2064 Smallest Sequence on Grid
ユーザー とりゐ
提出日時 2022-08-27 12:01:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,034 ms / 3,000 ms
コード長 583 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 170,592 KB
最終ジャッジ日時 2024-11-16 01:34:46
合計ジャッジ時間 11,963 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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=[]
  ok=[0]*h
  for x,y in d:
    for dx,dy in dxdy:
      if 0<=x+dx<h and 0<=y+dy<w:
        ok[x+dx]=1
  for x in range(h):
    if ok[x]:
      todo.append((x,i+1-x))
print(*ans,sep='')
0