結果
問題 |
No.205 マージして辞書順最小
|
ユーザー |
|
提出日時 | 2018-10-23 21:04:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 745 ms |
コンパイル使用メモリ | 76,288 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-19 04:45:25 |
合計ジャッジ時間 | 1,510 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 WA * 7 |
ソースコード
#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; choose = *it; } } ret += choose[0]; ms.erase(it); if(choose.size() > 1){ choose = choose.substr(1); ms.insert(choose); } } cout << ret << endl; return 0; }