結果

問題 No.205 マージして辞書順最小
ユーザー nebukuro09nebukuro09
提出日時 2016-09-27 11:31:33
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 498 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-05-01 05:41:44
合計ジャッジ時間 1,297 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,528 KB
testcase_01 AC 12 ms
6,272 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 10 ms
6,272 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 52 ms
6,528 KB
testcase_11 AC 64 ms
6,400 KB
testcase_12 WA -
testcase_13 AC 37 ms
6,400 KB
testcase_14 AC 11 ms
6,528 KB
testcase_15 AC 11 ms
6,272 KB
testcase_16 AC 10 ms
6,400 KB
testcase_17 AC 10 ms
6,400 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()
S = [raw_input()[::-1] for _ in xrange(N)]

ans = ''
while len(S) > 0:
    min_s = 'zzz'
    min_i = []
    for i, s in enumerate(S):
        if s[-1] < min_s:
            min_s = s[-1]
            min_i = [i]
        elif s[-1] == min_s:
            min_i.append(i)
            
    min_i = min(min_i, key=lambda i:S[i][::-1]) if len(min_i) > 1 else min_i[0]
    ans += S[min_i][-1]
    if len(S[min_i]) == 1:
        S.pop(min_i)
    else:
        S[min_i] = S[min_i][:-1]

print ans
0