結果

問題 No.2064 Smallest Sequence on Grid
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-09-03 18:26:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,614 ms / 3,000 ms
コード長 982 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 503,668 KB
最終ジャッジ日時 2024-04-28 15:50:23
合計ジャッジ時間 32,246 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,996 KB
testcase_01 AC 35 ms
54,736 KB
testcase_02 AC 36 ms
55,132 KB
testcase_03 AC 35 ms
54,484 KB
testcase_04 AC 37 ms
54,692 KB
testcase_05 AC 38 ms
54,684 KB
testcase_06 AC 39 ms
54,132 KB
testcase_07 AC 42 ms
55,272 KB
testcase_08 AC 46 ms
62,152 KB
testcase_09 AC 44 ms
61,440 KB
testcase_10 AC 46 ms
63,288 KB
testcase_11 AC 50 ms
66,052 KB
testcase_12 AC 52 ms
65,856 KB
testcase_13 AC 54 ms
67,124 KB
testcase_14 AC 53 ms
67,564 KB
testcase_15 AC 51 ms
65,472 KB
testcase_16 AC 52 ms
65,932 KB
testcase_17 AC 1,514 ms
503,220 KB
testcase_18 AC 1,740 ms
503,408 KB
testcase_19 AC 1,490 ms
503,520 KB
testcase_20 AC 2,354 ms
503,180 KB
testcase_21 AC 2,447 ms
503,228 KB
testcase_22 AC 2,214 ms
502,828 KB
testcase_23 AC 2,147 ms
503,656 KB
testcase_24 AC 2,146 ms
503,444 KB
testcase_25 AC 2,137 ms
503,668 KB
testcase_26 AC 2,614 ms
502,956 KB
testcase_27 AC 2,591 ms
503,088 KB
testcase_28 AC 1,482 ms
503,648 KB
testcase_29 AC 2,046 ms
435,184 KB
testcase_30 AC 1,648 ms
465,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
vis = [[-1] * w for _ in range(h)]
vis[0][0] = 0
vecs = [(0,1),(1,0)]
mark = s[0][0]
for n in range(h+w):
    n_mark = '{'
    for i in range(n+1):
        j = n-i
        if not (0 <= i <= h-1 and 0 <= j <= w-1):continue
        if s[i][j] == mark and vis[i][j] == 0:
            vis[i][j] = 1
            for vi,vj in vecs:
                ni,nj = i + vi,j + vj
                if not (0 <= ni <= h-1 and 0 <= nj <= w-1):continue
                vis[ni][nj] = 0
                if n_mark > s[ni][nj]:
                    n_mark = s[ni][nj]
                    
    mark = n_mark
ans = [s[h-1][w-1]]
from collections import deque
vecs = [(0,-1),(-1,0)]
i,j = h-1,w-1
while (i+j):
    for vi,vj in vecs:
        ni = i+vi
        nj = j+vj
        if not (0 <= ni <= h-1 and 0 <= nj <= w-1):continue
        if vis[ni][nj] != 1:continue
        i ,j = ni,nj
        ans.append(s[ni][nj])
print("".join(ans[::-1]))
0