結果

問題 No.2064 Smallest Sequence on Grid
ユーザー tassei903tassei903
提出日時 2022-09-02 22:05:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,207 ms / 3,000 ms
コード長 979 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 269,908 KB
最終ジャッジ日時 2024-04-27 21:40:05
合計ジャッジ時間 18,716 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,816 KB
testcase_01 AC 43 ms
53,816 KB
testcase_02 AC 43 ms
54,800 KB
testcase_03 AC 43 ms
54,196 KB
testcase_04 AC 42 ms
55,228 KB
testcase_05 AC 42 ms
53,976 KB
testcase_06 AC 43 ms
53,724 KB
testcase_07 AC 42 ms
54,440 KB
testcase_08 AC 44 ms
55,172 KB
testcase_09 AC 44 ms
54,540 KB
testcase_10 AC 44 ms
54,640 KB
testcase_11 AC 47 ms
55,696 KB
testcase_12 AC 51 ms
62,116 KB
testcase_13 AC 55 ms
65,120 KB
testcase_14 AC 57 ms
65,932 KB
testcase_15 AC 56 ms
65,424 KB
testcase_16 AC 56 ms
65,384 KB
testcase_17 AC 175 ms
153,804 KB
testcase_18 AC 174 ms
153,920 KB
testcase_19 AC 176 ms
153,860 KB
testcase_20 AC 1,720 ms
269,348 KB
testcase_21 AC 1,812 ms
268,732 KB
testcase_22 AC 1,267 ms
266,748 KB
testcase_23 AC 1,257 ms
268,276 KB
testcase_24 AC 1,265 ms
268,660 KB
testcase_25 AC 1,241 ms
268,452 KB
testcase_26 AC 2,169 ms
268,416 KB
testcase_27 AC 2,207 ms
268,932 KB
testcase_28 AC 179 ms
154,332 KB
testcase_29 AC 1,856 ms
269,908 KB
testcase_30 AC 176 ms
149,332 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