結果

問題 No.205 マージして辞書順最小
ユーザー rpy3cpprpy3cpp
提出日時 2015-05-08 23:29:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 651 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 7,980 KB
最終ジャッジ日時 2023-09-19 08:53:14
合計ジャッジ時間 1,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,756 KB
testcase_01 AC 15 ms
7,952 KB
testcase_02 AC 25 ms
7,804 KB
testcase_03 AC 24 ms
7,844 KB
testcase_04 AC 24 ms
7,868 KB
testcase_05 AC 24 ms
7,756 KB
testcase_06 AC 16 ms
7,844 KB
testcase_07 AC 37 ms
7,952 KB
testcase_08 AC 37 ms
7,804 KB
testcase_09 AC 37 ms
7,780 KB
testcase_10 AC 36 ms
7,836 KB
testcase_11 AC 36 ms
7,760 KB
testcase_12 AC 35 ms
7,820 KB
testcase_13 AC 32 ms
7,852 KB
testcase_14 AC 16 ms
7,732 KB
testcase_15 AC 16 ms
7,812 KB
testcase_16 AC 16 ms
7,808 KB
testcase_17 AC 16 ms
7,980 KB
testcase_18 AC 16 ms
7,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N = int(input())
    S= []
    for i in range(N):
        S.append(input().rstrip())
    return N, S

def solve(N, S):
    SENTINEL = chr(ord('z') + 1)
    S = [s + SENTINEL for s in S]
    cursor = [0] * N
    T = []
    while True:
        next_c = SENTINEL
        next_i = 0
        for i, s in enumerate(S):
            c = s[cursor[i]:]
            if c < next_c:
                next_c = c
                next_i = i
        if next_c == SENTINEL:
            return T
        T.append(next_c[0])
        cursor[next_i] += 1

if __name__ == '__main__':
    N, S = read_data()
    minT = solve(N, S)
    print(''.join(minT))
0