結果

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

ソースコード

diff #

def read_data():
    N = int(input())
    S = [input() for _ in range(N)]
    return N, S

def solve(N, S):
    sentinel = chr(ord('z')+1)
    S = [s + sentinel for s in S]
    ret = ''
    cursor = [0] * N

    while True:
        next_c, next_i = sentinel, 0
        for i, s in enumerate(S):
            c = s[cursor[i]:]
            if c < next_c:
                next_c, next_i = c, i
        if next_c == sentinel:
            return ret
        else:
            ret += next_c[0]
            cursor[next_i] += 1

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