結果

問題 No.2064 Smallest Sequence on Grid
ユーザー tassei903tassei903
提出日時 2022-09-02 22:05:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,111 ms / 3,000 ms
コード長 979 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 270,884 KB
最終ジャッジ日時 2023-08-10 04:08:43
合計ジャッジ時間 19,299 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
71,804 KB
testcase_01 AC 87 ms
71,828 KB
testcase_02 AC 89 ms
71,772 KB
testcase_03 AC 89 ms
71,460 KB
testcase_04 AC 89 ms
71,888 KB
testcase_05 AC 86 ms
71,904 KB
testcase_06 AC 84 ms
71,648 KB
testcase_07 AC 87 ms
71,448 KB
testcase_08 AC 86 ms
71,584 KB
testcase_09 AC 85 ms
71,612 KB
testcase_10 AC 87 ms
71,648 KB
testcase_11 AC 92 ms
72,320 KB
testcase_12 AC 97 ms
77,456 KB
testcase_13 AC 105 ms
77,392 KB
testcase_14 AC 102 ms
77,532 KB
testcase_15 AC 100 ms
77,456 KB
testcase_16 AC 102 ms
77,416 KB
testcase_17 AC 205 ms
157,448 KB
testcase_18 AC 206 ms
157,432 KB
testcase_19 AC 209 ms
157,508 KB
testcase_20 AC 1,539 ms
268,952 KB
testcase_21 AC 1,672 ms
268,956 KB
testcase_22 AC 1,193 ms
267,332 KB
testcase_23 AC 1,224 ms
270,560 KB
testcase_24 AC 1,224 ms
270,544 KB
testcase_25 AC 1,213 ms
270,456 KB
testcase_26 AC 2,111 ms
270,468 KB
testcase_27 AC 2,106 ms
270,456 KB
testcase_28 AC 208 ms
157,872 KB
testcase_29 AC 1,747 ms
270,884 KB
testcase_30 AC 202 ms
147,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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))
0