結果

問題 No.205 マージして辞書順最小
ユーザー rpy3cpp
提出日時 2015-05-08 23:29:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 651 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-05 20:40:20
合計ジャッジ時間 1,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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