# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303090 | 2020-09-19T21:47:12 Z | FlashGamezzz | Type Printer (IOI08_printer) | C++17 | 1000 ms | 111852 KB |
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <string> #include <utility> #include <vector> #include <queue> using namespace std; struct trie{ long lets[26] = {}; bool end = false; int len; }; trie root = trie(); vector<trie> tries; vector<char> ans; void add(int c, int i, string s){ int l = int(s[i])-97; if (tries[c].lets[l] == 0){ tries.push_back(trie()); tries[c].lets[l] = tries.size()-1; } if (i == s.length()-1){ tries[tries[c].lets[l]].end = true; tries[tries[c].lets[l]].len = 0; return; } add(tries[c].lets[l], i+1, s); tries[c].len = max(tries[tries[c].lets[l]].len+1, tries[c].len); } void solve(int c){ if (tries[c].end){ ans.push_back('P'); } vector< pair<int, int> > ls; for (int i = 0; i < 26; i++){ if (tries[c].lets[i] != 0){ ls.push_back(make_pair(tries[tries[c].lets[i]].len, i)); } } sort(ls.begin(), ls.end()); for (pair<int, int> a : ls){ ans.push_back(char(a.second+97)); solve(tries[c].lets[a.second]); ans.push_back('-'); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; tries.push_back(root); for (int i = 0; i < n; i++){ string s; cin >> s; add(0, 0, s); } solve(0); long count = ans.size(); while (ans[count-1] == '-'){ count--; } cout << count << endl; for (int i = 0; i < count; i++){ cout << ans[i] << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 640 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 2200 KB | Output is correct |
2 | Incorrect | 43 ms | 3892 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 124 ms | 7408 KB | Output is correct |
2 | Correct | 264 ms | 14444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 313 ms | 14536 KB | Output is correct |
2 | Correct | 94 ms | 4020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 798 ms | 56136 KB | Output is correct |
2 | Execution timed out | 1087 ms | 111852 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 642 ms | 28392 KB | Output is correct |
2 | Execution timed out | 1098 ms | 111724 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |