結果

問題 No.2064 Smallest Sequence on Grid
ユーザー lloyzlloyz
提出日時 2022-09-02 22:50:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,591 ms / 3,000 ms
コード長 615 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 168,576 KB
最終ジャッジ日時 2024-04-27 22:29:54
合計ジャッジ時間 15,629 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,712 KB
testcase_01 AC 40 ms
51,968 KB
testcase_02 AC 40 ms
51,840 KB
testcase_03 AC 40 ms
52,096 KB
testcase_04 AC 41 ms
51,712 KB
testcase_05 AC 41 ms
52,352 KB
testcase_06 AC 41 ms
51,968 KB
testcase_07 AC 41 ms
51,968 KB
testcase_08 AC 46 ms
58,068 KB
testcase_09 AC 44 ms
57,856 KB
testcase_10 AC 47 ms
58,624 KB
testcase_11 AC 48 ms
60,672 KB
testcase_12 AC 51 ms
60,800 KB
testcase_13 AC 54 ms
61,824 KB
testcase_14 AC 55 ms
62,976 KB
testcase_15 AC 54 ms
61,824 KB
testcase_16 AC 56 ms
62,464 KB
testcase_17 AC 371 ms
160,716 KB
testcase_18 AC 373 ms
160,900 KB
testcase_19 AC 371 ms
160,896 KB
testcase_20 AC 1,190 ms
165,704 KB
testcase_21 AC 1,280 ms
166,144 KB
testcase_22 AC 918 ms
164,224 KB
testcase_23 AC 961 ms
164,608 KB
testcase_24 AC 976 ms
164,428 KB
testcase_25 AC 981 ms
164,608 KB
testcase_26 AC 1,591 ms
168,576 KB
testcase_27 AC 1,584 ms
168,320 KB
testcase_28 AC 363 ms
160,800 KB
testcase_29 AC 1,369 ms
147,364 KB
testcase_30 AC 341 ms
147,052 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