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