結果

問題 No.2064 Smallest Sequence on Grid
ユーザー lloyzlloyz
提出日時 2022-09-02 22:47:42
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 695 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 82,152 KB
実行使用メモリ 439,724 KB
最終ジャッジ日時 2024-04-27 22:26:06
合計ジャッジ時間 27,606 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,828 KB
testcase_01 AC 38 ms
53,384 KB
testcase_02 AC 36 ms
52,836 KB
testcase_03 AC 37 ms
52,580 KB
testcase_04 AC 35 ms
52,120 KB
testcase_05 AC 35 ms
52,180 KB
testcase_06 AC 36 ms
52,272 KB
testcase_07 AC 35 ms
53,580 KB
testcase_08 AC 35 ms
53,116 KB
testcase_09 AC 37 ms
52,572 KB
testcase_10 AC 36 ms
53,336 KB
testcase_11 AC 41 ms
60,260 KB
testcase_12 AC 41 ms
60,168 KB
testcase_13 AC 43 ms
62,044 KB
testcase_14 AC 44 ms
62,844 KB
testcase_15 AC 43 ms
61,328 KB
testcase_16 AC 42 ms
63,540 KB
testcase_17 AC 715 ms
432,328 KB
testcase_18 AC 699 ms
431,940 KB
testcase_19 AC 708 ms
432,204 KB
testcase_20 AC 2,314 ms
436,396 KB
testcase_21 AC 2,481 ms
436,988 KB
testcase_22 AC 1,702 ms
434,952 KB
testcase_23 AC 1,842 ms
435,440 KB
testcase_24 AC 1,885 ms
435,196 KB
testcase_25 AC 1,847 ms
435,572 KB
testcase_26 AC 2,991 ms
439,724 KB
testcase_27 TLE -
testcase_28 AC 681 ms
432,212 KB
testcase_29 AC 2,512 ms
380,160 KB
testcase_30 AC 637 ms
400,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ans = S[0][0]
C = set([0])
for _ in range(h + w - 2):
    minT = ''
    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 minT == '':
                    minT = S[ni][nj]
                    NC.add(ni * w + nj)
                elif S[ni][nj] == minT:
                    NC.add(ni * w + nj)
                elif S[ni][nj] < minT:
                    minT = S[ni][nj]
                    NC = set([ni * w + nj])
    ans += minT
    C = NC
print(ans)
0