結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
agatan
|
| 提出日時 | 2015-05-08 23:10:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,207 bytes |
| コンパイル時間 | 481 ms |
| コンパイル使用メモリ | 66,756 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 20:05:40 |
| 合計ジャッジ時間 | 1,282 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#define REP(i, n) for(int i=0;i<(n);i++)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<string> s;
REP(i, N) {
string tmp;
cin >> tmp;
s.push_back(tmp);
}
string t;
int minidx = 0;
while (!all_of(begin(s), end(s), [](string &tmp) { return tmp.empty(); })) {
char minc = CHAR_MAX;
for (int i = 0; i < s.size(); ++i) {
if (s[i].empty()) continue;
if (s[i][0] < minc) {
minidx = i;
minc = s[i][0];
} else if (s[i][0] == minc) {
int j = 0;
while (j < s[i].size() && j < s[minidx].size() && s[i][j] == s[minidx][j]) ++j;
if (j >= s[minidx].size()) {
minidx = i;
} else if (j < s[i].size()) {
if (s[i][j] < s[minidx][j])
minidx = i;
}
}
}
t += minc;
s[minidx] = s[minidx].substr(1, s[minidx].size() - 1);
}
cout << t << endl;
return 0;
}
agatan