結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 H20H20
提出日時 2022-09-02 22:30:58
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,492 ms / 3,000 ms
コード長 768 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 441,160 KB
最終ジャッジ日時 2023-08-10 04:47:10
合計ジャッジ時間 24,437 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,364 KB
testcase_01 AC 64 ms
71,420 KB
testcase_02 AC 67 ms
71,340 KB
testcase_03 AC 66 ms
71,448 KB
testcase_04 AC 67 ms
71,436 KB
testcase_05 AC 67 ms
71,636 KB
testcase_06 AC 65 ms
71,348 KB
testcase_07 AC 67 ms
71,336 KB
testcase_08 AC 67 ms
71,420 KB
testcase_09 AC 68 ms
71,364 KB
testcase_10 AC 67 ms
71,396 KB
testcase_11 AC 65 ms
71,440 KB
testcase_12 AC 69 ms
71,416 KB
testcase_13 AC 70 ms
76,092 KB
testcase_14 AC 72 ms
76,164 KB
testcase_15 AC 69 ms
76,432 KB
testcase_16 AC 73 ms
76,164 KB
testcase_17 AC 698 ms
426,484 KB
testcase_18 AC 673 ms
426,508 KB
testcase_19 AC 673 ms
426,464 KB
testcase_20 AC 1,868 ms
437,284 KB
testcase_21 AC 2,003 ms
437,932 KB
testcase_22 AC 1,457 ms
435,796 KB
testcase_23 AC 1,587 ms
436,924 KB
testcase_24 AC 1,560 ms
436,924 KB
testcase_25 AC 1,580 ms
437,180 KB
testcase_26 AC 2,441 ms
441,160 KB
testcase_27 AC 2,492 ms
440,944 KB
testcase_28 AC 683 ms
426,524 KB
testcase_29 AC 2,250 ms
381,740 KB
testcase_30 AC 650 ms
403,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()+'~'))
S.append(list('~'*(W+2)))

pos = set()
pos.add(0)
ANS = [S[0][0]]

while len(ANS)<H+W-1:
    alphabet = 'z'
    nextPos = set()
    for xy in list(pos):
        x,y = xy%W,xy//W
        if S[y][x+1]==alphabet:
            nextPos.add(xy+1)
        elif S[y][x+1]<alphabet:
            alphabet = S[y][x+1]
            nextPos = set()
            nextPos.add(xy+1)
        if not xy+W in nextPos:
            if S[y+1][x]==alphabet:
                nextPos.add(xy+W)
            elif S[y+1][x]<alphabet:
                alphabet = S[y+1][x]
                nextPos = set()
                nextPos.add(xy+W)
    ANS.append(alphabet)
    pos = nextPos
print(''.join(map(str, ANS)))
0