結果

問題 No.205 マージして辞書順最小
ユーザー rpy3cpprpy3cpp
提出日時 2015-05-08 23:17:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 999 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 343,096 KB
最終ジャッジ日時 2023-09-19 08:30:47
合計ジャッジ時間 6,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,676 KB
testcase_01 AC 17 ms
7,808 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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
    frontiers = [cursor]
    T = []
    while True:
        next_c = SENTINEL
        next_frontiers = []
        for cursor in frontiers:            
            for i, s in enumerate(S):
                c = s[cursor[i]]
                if c < next_c:
                    next_c = c
                    cursor[i] += 1
                    next_frontiers = [cursor[:]]
                    cursor[i] -= 1
                elif c == next_c:
                    cursor[i] += 1
                    next_frontiers.append(cursor[:])
                    cursor[i] -= 1
        if next_c == SENTINEL:
            return T
        T.append(next_c)
        frontiers = next_frontiers


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