結果

問題 No.2064 Smallest Sequence on Grid
ユーザー AkariAkari
提出日時 2022-09-02 22:32:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,012 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 237,620 KB
最終ジャッジ日時 2024-04-27 22:08:09
合計ジャッジ時間 6,158 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
17,692 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 30 ms
10,752 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