結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー |
|
提出日時 | 2022-09-02 22:12:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,035 ms / 3,000 ms |
コード長 | 708 bytes |
コンパイル時間 | 540 ms |
コンパイル使用メモリ | 82,064 KB |
実行使用メモリ | 177,352 KB |
最終ジャッジ日時 | 2024-11-16 03:53:25 |
合計ジャッジ時間 | 11,208 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
h,w = map(int,input().split())S = [input() for i in range(h)]ans = []vis = [[0]*w for i in range(h)]ans.append(S[0][0])l = [[0,0]]for i in range(h+w-1):cands = [[] for j in range(26)]for x,y in l:nx,ny = x+1,yif 0 <= nx < h and 0 <= ny < w and vis[nx][ny] == 0:cands[ord(S[nx][ny])-ord("a")].append([nx,ny])vis[nx][ny] = 1nx,ny = x,y+1if 0 <= nx < h and 0 <= ny < w and vis[nx][ny] == 0:cands[ord(S[nx][ny])-ord("a")].append([nx,ny])vis[nx][ny] = 1for j in range(26):if cands[j] != []:l = cands[j]ans.append(chr(j+ord("a")))breakprint(*ans,sep="")