# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107465 | tictaccat | Type Printer (IOI08_printer) | C++14 | 226 ms | 76392 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAX = 25000 + 10;
int N;
vector<string> words;
string longest;
vector<vector<int>> trie(20*MAX,vector<int>(26));
vector<int> hasString(20*MAX);
int c = 0; //current max node in tree
ostringstream oss;
int ops;
void insert (const string &s) {
int u = 0;
for (int i = 0; i < s.size(); i++) {
if (trie[u][s[i]-'a']) u = trie[u][s[i]-'a'];
else u = trie[u][s[i]-'a'] = ++c;
}
hasString[u] = true;
}
void dfs(int u, int adv) {
if (hasString[u]) {
ops++;
oss << "P\n";
}
if (adv == longest.size()) {
cout << ops << "\n" << oss.str();
exit(0);
}
for (int c = 0; c < 26; c++) {
if (c == longest[adv]-'a') continue;
if (trie[u][c]) {
ops++;
oss << (char)('a'+c) << "\n";
dfs(trie[u][c],adv);
}
}
if (trie[u][longest[adv]-'a']) {
ops++;
oss << longest[adv] << "\n";
dfs(trie[u][longest[adv]-'a'],adv+1);
}
ops++;
oss << "-\n";
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
for (int i = 0; i < N; i++) {
string w; cin >> w;
words.push_back(w);
insert(w);
}
longest = *max_element(words.begin(),words.end(),[](string a, string b) {return a.size() < b.size();});
dfs(0,0);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |