結果

問題 No.2064 Smallest Sequence on Grid
ユーザー AkariAkari
提出日時 2022-09-02 22:36:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,027 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,072 KB
実行使用メモリ 428,004 KB
最終ジャッジ日時 2024-04-27 22:12:34
合計ジャッジ時間 6,019 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
60,236 KB
testcase_01 AC 35 ms
53,724 KB
testcase_02 AC 32 ms
52,580 KB
testcase_03 AC 33 ms
53,252 KB
testcase_04 AC 33 ms
52,980 KB
testcase_05 AC 32 ms
53,012 KB
testcase_06 AC 34 ms
52,936 KB
testcase_07 AC 31 ms
52,136 KB
testcase_08 AC 32 ms
53,224 KB
testcase_09 AC 31 ms
52,824 KB
testcase_10 AC 33 ms
54,076 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 = []
    for _ in range(h): A += list(input())
    d = {A[0][0]: [0]}
    for _ in range(h + w - 1):
        s = min(d)
        q = [k for k in d[s]]
        d.clear()
        while q:
            k = q.pop()
            A[k] = A[k].upper()
            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].lower())
        if i > 0 and A[(i - 1) * w + j].isupper():
            i -= 1
        else:
            j -= 1
    print(''.join(reversed(ans)))




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