結果

問題 No.2064 Smallest Sequence on Grid
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-09-03 18:24:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 969 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 503,908 KB
最終ジャッジ日時 2024-04-28 15:48:21
合計ジャッジ時間 29,497 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
54,248 KB
testcase_01 AC 43 ms
54,476 KB
testcase_02 AC 42 ms
54,260 KB
testcase_03 AC 42 ms
54,384 KB
testcase_04 AC 42 ms
53,868 KB
testcase_05 AC 43 ms
55,404 KB
testcase_06 AC 43 ms
54,916 KB
testcase_07 AC 43 ms
55,332 KB
testcase_08 AC 51 ms
61,948 KB
testcase_09 AC 50 ms
61,240 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1,875 ms
502,984 KB
testcase_27 WA -
testcase_28 AC 1,660 ms
503,908 KB
testcase_29 AC 1,492 ms
435,084 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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
                if n_mark > s[ni][nj]:
                    n_mark = s[ni][nj]
                    vis[ni][nj] = 0
    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] == 1:continue
        i ,j = ni,nj
        ans.append(s[ni][nj])
print("".join(ans[::-1]))
0