結果

問題 No.2064 Smallest Sequence on Grid
ユーザー lloyzlloyz
提出日時 2022-09-02 22:50:27
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,474 ms / 3,000 ms
コード長 615 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 170,272 KB
最終ジャッジ日時 2023-08-10 05:10:20
合計ジャッジ時間 15,959 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,548 KB
testcase_01 AC 68 ms
71,644 KB
testcase_02 AC 66 ms
71,368 KB
testcase_03 AC 67 ms
71,296 KB
testcase_04 AC 67 ms
71,356 KB
testcase_05 AC 66 ms
71,300 KB
testcase_06 AC 66 ms
71,396 KB
testcase_07 AC 67 ms
71,368 KB
testcase_08 AC 71 ms
75,480 KB
testcase_09 AC 70 ms
75,440 KB
testcase_10 AC 69 ms
75,224 KB
testcase_11 AC 77 ms
76,776 KB
testcase_12 AC 72 ms
76,548 KB
testcase_13 AC 76 ms
76,608 KB
testcase_14 AC 80 ms
76,616 KB
testcase_15 AC 75 ms
76,696 KB
testcase_16 AC 76 ms
76,776 KB
testcase_17 AC 346 ms
162,824 KB
testcase_18 AC 343 ms
163,004 KB
testcase_19 AC 340 ms
162,580 KB
testcase_20 AC 1,032 ms
167,392 KB
testcase_21 AC 1,149 ms
167,856 KB
testcase_22 AC 838 ms
166,180 KB
testcase_23 AC 938 ms
166,272 KB
testcase_24 AC 942 ms
166,336 KB
testcase_25 AC 912 ms
166,236 KB
testcase_26 AC 1,459 ms
169,776 KB
testcase_27 AC 1,474 ms
170,272 KB
testcase_28 AC 346 ms
162,808 KB
testcase_29 AC 1,305 ms
148,944 KB
testcase_30 AC 347 ms
148,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
S = [list(map(ord, list(input()))) for _ in range(h)]
Directions = [(1, 0), (0, 1)]

ans = chr(S[0][0])
C = set([0])
for _ in range(h + w - 2):
    minT = 10**18
    NC = set()
    for c in C:
        ci, cj = divmod(c, w)
        for di, dj in Directions:
            ni = ci + di
            nj = cj + dj
            if ni < h and nj < w:
                if S[ni][nj] == minT:
                    NC.add(ni * w + nj)
                elif S[ni][nj] < minT:
                    minT = S[ni][nj]
                    NC = set([ni * w + nj])
    ans += chr(minT)
    C = NC
print(ans)
0