# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107465 | 2019-04-24T16:02:04 Z | tictaccat | Type Printer (IOI08_printer) | C++14 | 226 ms | 76392 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 89 ms | 68856 KB | Output is correct |
2 | Correct | 98 ms | 68984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 101 ms | 68912 KB | Output is correct |
2 | Correct | 96 ms | 68856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 97 ms | 68920 KB | Output is correct |
2 | Correct | 90 ms | 68984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 97 ms | 68856 KB | Output is correct |
2 | Correct | 93 ms | 68892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 102 ms | 68860 KB | Output is correct |
2 | Correct | 122 ms | 68956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 110 ms | 69064 KB | Output is correct |
2 | Correct | 113 ms | 69016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 116 ms | 69284 KB | Output is correct |
2 | Correct | 113 ms | 69876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 118 ms | 70152 KB | Output is correct |
2 | Correct | 89 ms | 69744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 127 ms | 71684 KB | Output is correct |
2 | Correct | 172 ms | 75236 KB | Output is correct |
3 | Correct | 148 ms | 73160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 71524 KB | Output is correct |
2 | Correct | 226 ms | 76392 KB | Output is correct |
3 | Correct | 157 ms | 73752 KB | Output is correct |
4 | Correct | 180 ms | 76072 KB | Output is correct |