結果

問題 No.2064 Smallest Sequence on Grid
ユーザー AkariAkari
提出日時 2022-09-02 22:33:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,012 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,760 KB
実行使用メモリ 60,124 KB
最終ジャッジ日時 2024-04-27 22:09:47
合計ジャッジ時間 6,209 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
60,124 KB
testcase_01 AC 40 ms
52,404 KB
testcase_02 AC 38 ms
52,492 KB
testcase_03 AC 39 ms
53,320 KB
testcase_04 AC 38 ms
53,024 KB
testcase_05 AC 38 ms
53,416 KB
testcase_06 AC 40 ms
52,136 KB
testcase_07 AC 39 ms
53,504 KB
testcase_08 AC 40 ms
53,996 KB
testcase_09 AC 38 ms
52,400 KB
testcase_10 AC 40 ms
53,748 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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 #

def main():
    h, w = map(int, input().split())
    A = ''.join([input() for _ in range(h)])
    d = {A[0][0]: [0]}
    B = [0] * (h * w)
    for _ in range(h + w - 1):
        s = min(d)
        q = [k for k in d[s]]
        d.clear()
        while q:
            k = q.pop()
            B[k] = 1
            i, j = divmod(k, w)
            if i < h - 1:
                ni = (i + 1) * w + j
                a = A[ni]
                if a in d:
                    d[a].append(ni)
                else:
                    d[a] = [ni]
            if j < w - 1:
                nj = i * w + (j + 1)
                a = A[nj]
                if a in d:
                    d[a].append(nj)
                else:
                    d[a] = [nj]
    ans = []
    i, j = h - 1, w - 1
    for _ in range(h + w - 1):
        ans.append(A[i * w + j])
        if i > 0 and B[(i - 1) * w + j]:
            i -= 1
        else:
            j -= 1
    print(''.join(reversed(ans)))




if __name__ == '__main__':
    main()
0