結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-23 21:02:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 892 bytes |
| コンパイル時間 | 811 ms |
| コンパイル使用メモリ | 76,296 KB |
| 実行使用メモリ | 43,040 KB |
| 最終ジャッジ日時 | 2024-11-19 04:43:49 |
| 合計ジャッジ時間 | 55,701 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 6 TLE * 9 |
ソースコード
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >> n;
string s;
multiset<string> ms;
for(int i = 0; i < n; i++){
cin >> s;
ms.insert(s);
}
string ret = "";
while(ms.size()){
set<string>::iterator it = ms.begin();
string choose = *it;
auto tmp = it;
for(tmp++; tmp != ms.end();tmp++){
if(choose[0] != (*tmp)[0]) break;
string tmpc = choose, tmps = *tmp;
reverse(tmpc.begin(), tmpc.end());
reverse(tmps.begin(), tmps.end());
if(tmps < tmpc){
it = tmp;
}
}
ret += choose[0];
ms.erase(it);
if(choose.size() > 1){
choose = choose.substr(1);
ms.insert(choose);
}
}
cout << ret << endl;
return 0;
}