結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-02 22:05:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,223 ms / 3,000 ms |
| コード長 | 979 bytes |
| コンパイル時間 | 313 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 269,824 KB |
| 最終ジャッジ日時 | 2024-11-16 03:38:04 |
| 合計ジャッジ時間 | 18,707 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
h, w = na()
dist = ["{"] * (h + w - 1)
s = [input() for i in range(h)]
from collections import deque
d = deque([(0, 0, s[0][0])])
dist[0] = s[0][0]
f = [[0] * w for i in range(h)]
while d:
x, y, z = d.popleft()
if dist[x+y] != z or f[x][y]:
continue
f[x][y] = 1
#print(x,y,z)
nx = x + 1
ny = y
if nx < h and ny < w and s[nx][ny] <= dist[nx+ny]:
dist[nx+ny] = s[nx][ny]
d.append((nx,ny,dist[nx+ny]))
nx = x
ny = y + 1
if nx < h and ny < w and s[nx][ny] <= dist[nx+ny]:
dist[nx+ny] = s[nx][ny]
d.append((nx,ny,dist[nx+ny]))
print("".join(dist))