結果

問題 No.205 マージして辞書順最小
ユーザー ayaoniayaoni
提出日時 2021-08-30 22:20:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,025 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 76,700 KB
最終ジャッジ日時 2024-05-03 08:20:03
合計ジャッジ時間 1,929 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,644 KB
testcase_01 AC 33 ms
53,372 KB
testcase_02 AC 58 ms
73,572 KB
testcase_03 AC 67 ms
76,564 KB
testcase_04 AC 68 ms
76,556 KB
testcase_05 AC 68 ms
76,700 KB
testcase_06 AC 35 ms
54,280 KB
testcase_07 AC 69 ms
76,588 KB
testcase_08 AC 73 ms
76,324 KB
testcase_09 AC 63 ms
76,224 KB
testcase_10 AC 67 ms
76,612 KB
testcase_11 AC 81 ms
76,300 KB
testcase_12 AC 81 ms
76,508 KB
testcase_13 AC 68 ms
76,628 KB
testcase_14 AC 41 ms
62,588 KB
testcase_15 AC 32 ms
52,628 KB
testcase_16 AC 34 ms
53,624 KB
testcase_17 AC 34 ms
53,788 KB
testcase_18 AC 33 ms
53,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N = I()
S = [S()+'{' for _ in range(N)]
S.sort()

ANS = []
while True:
    L = [[] for _ in range(26)]
    for s in S:
        L[ord(s[0])-97].append(s)
    for i in range(26):
        if L[i]:
            L[i].sort()
            ANS.append(L[i][0][0])
            new = []
            if len(L[i][0]) >= 3:
                new.append(L[i][0][1:])
            for s in L[i][1:]:
                new.append(s)
            for j in range(i+1,26):
                for s in L[j]:
                    new.append(s)
            S = new
            break
    else:
        break

ans = ''.join(ANS)
print(ans)
0