結果

問題 No.2064 Smallest Sequence on Grid
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-09-03 18:10:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 908 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 82,968 KB
最終ジャッジ日時 2024-04-28 15:37:30
合計ジャッジ時間 5,965 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,760 KB
testcase_01 AC 37 ms
55,068 KB
testcase_02 AC 38 ms
54,376 KB
testcase_03 AC 39 ms
54,436 KB
testcase_04 AC 37 ms
54,008 KB
testcase_05 AC 40 ms
54,232 KB
testcase_06 AC 38 ms
54,824 KB
testcase_07 AC 36 ms
54,788 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
vis = [[0] * w for _ in range(h)]
vis[0][0] = 1
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:
            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
                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 not vis[ni][nj]:continue
        i ,j = ni,nj
        ans.append(s[ni][nj])
print("".join(ans[::-1]))
0