結果
問題 |
No.205 マージして辞書順最小
|
ユーザー |
![]() |
提出日時 | 2021-08-30 22:20:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 88 ms / 5,000 ms |
コード長 | 1,025 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 76,800 KB |
最終ジャッジ日時 | 2024-11-24 06:42:05 |
合計ジャッジ時間 | 2,124 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
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)