結果

問題 No.2064 Smallest Sequence on Grid
ユーザー vwxyzvwxyz
提出日時 2023-01-14 23:46:34
言語 PyPy2
(7.3.15)
結果
MLE  
実行時間 -
コード長 677 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 77,524 KB
実行使用メモリ 813,280 KB
最終ジャッジ日時 2023-08-27 04:23:08
合計ジャッジ時間 12,091 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
76,108 KB
testcase_01 AC 71 ms
76,208 KB
testcase_02 AC 70 ms
76,104 KB
testcase_03 AC 71 ms
76,332 KB
testcase_04 AC 72 ms
76,332 KB
testcase_05 AC 72 ms
76,336 KB
testcase_06 AC 72 ms
76,308 KB
testcase_07 AC 72 ms
76,336 KB
testcase_08 AC 72 ms
76,260 KB
testcase_09 AC 72 ms
76,112 KB
testcase_10 AC 73 ms
76,272 KB
testcase_11 AC 96 ms
78,716 KB
testcase_12 AC 96 ms
81,184 KB
testcase_13 MLE -
testcase_14 MLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

H,W=map(int,readline().split())
S=[readline().rstrip() for h in range(H)]
ans_lst=[S[0][0]]
queue=[(0,0)]
for _ in range(H+W-2):
    s="{"
    for h,w in queue:
        if h+1<H:
            s=min(s,S[h+1][w])
        if w+1<W:
            s=min(s,S[h][w+1])
    ans_lst.append(s)
    prev=queue
    queue=[]
    for h,w in prev[::-1]:
        if w+1<W and S[h][w+1]==s:
            if queue and (h,w+1)==queue[-1]:
                continue
            queue.append((h,w+1))
        if h+1<H and S[h+1][w]==s:
            if queue and (h+1,w)==queue[-1]:
                continue
            queue.append((h+1,w))
print("".join(ans_lst))
0