結果
| 問題 | 
                            No.2064 Smallest Sequence on Grid
                             | 
                    
| コンテスト | |
| ユーザー | 
                             とりゐ
                         | 
                    
| 提出日時 | 2021-08-10 05:06:04 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,948 ms / 3,000 ms | 
| コード長 | 533 bytes | 
| コンパイル時間 | 162 ms | 
| コンパイル使用メモリ | 81,920 KB | 
| 実行使用メモリ | 162,936 KB | 
| 最終ジャッジ日時 | 2024-11-16 01:32:44 | 
| 合計ジャッジ時間 | 18,848 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 29 | 
ソースコード
from collections import defaultdict
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=[]
for i in range(h+w-1):
  d=defaultdict(list)
  t=set()
  for y in range(max(0,i-h+1),min(i+1,w)):
    x=i-y
    #print(i,x,y)
    if a[x][y]==1:
      d[s[x][y]].append((x,y))
      t.add(s[x][y])
  t=sorted(list(t))
  u=t[0]
  ans.append(u)
  for x,y in d[u]:
    for dx,dy in dxdy:
      if 0<=x+dx<h and 0<=y+dy<w:
        a[x+dx][y+dy]=1
print(*ans,sep='')
            
            
            
        
            
とりゐ