結果
| 問題 | 
                            No.2064 Smallest Sequence on Grid
                             | 
                    
| コンテスト | |
| ユーザー | 
                             titia
                         | 
                    
| 提出日時 | 2022-09-09 07:30:50 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2,019 ms / 3,000 ms | 
| コード長 | 507 bytes | 
| コンパイル時間 | 242 ms | 
| コンパイル使用メモリ | 82,512 KB | 
| 実行使用メモリ | 102,400 KB | 
| 最終ジャッジ日時 | 2024-11-25 05:04:15 | 
| 合計ジャッジ時間 | 17,370 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 29 | 
ソースコード
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[input().strip() for i in range(H)]
Q=[(0,0)]
ANS=[S[0][0]]
while Q:
    D=[set() for i in range(26)]
    
    while Q:
        x,y=Q.pop()
        for z,w in [(x+1,y),(x,y+1)]:
            if 0<=z<H and 0<=w<W:
                k=S[z][w]
                D[ord(k)-97].add((z,w))
    for i in range(26):
        if D[i]!=set():
            ANS.append(chr(i+97))
            break
            
    Q=D[i]
        
print("".join(ANS))  
            
            
            
        
            
titia