# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303710 | 2020-09-20T14:54:53 Z | FlashGamezzz | Type Printer (IOI08_printer) | C++17 | 1000 ms | 111624 KB |
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <string> #include <utility> #include <vector> #include <queue> using namespace std; vector< vector<long> > lets; vector<bool> endb; vector<int> length; vector<char> ans; void add(long c, int i, string s){ if (i == s.length()){ endb[c] = true; length[c] = max(0, length[c]); return; } int l = int(s[i])-97; if (lets[c][l] == 0){ vector<long> t; for (int j = 0; j < 26; j++) t.push_back(0); lets.push_back(t); endb.push_back(false); length.push_back(-100); lets[c][l] = lets.size()-1; } add(lets[c][l], i+1, s); length[c] = max(length[lets[c][l]]+1, length[c]); } void solve(long c){ if (endb[c]){ ans.push_back('P'); } vector< pair<int, int> > ls; for (int i = 0; i < 26; i++){ if (lets[c][i] != 0){ ls.push_back(make_pair(length[lets[c][i]], i)); } } sort(ls.begin(), ls.end()); for (pair<int, int> a : ls){ ans.push_back(char(a.second+97)); solve(lets[c][a.second]); ans.push_back('-'); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<long> t; for (int j = 0; j < 26; j++) t.push_back(0); lets.push_back(t); endb.push_back(false); length.push_back(-100); 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 | 1 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 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 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 | Correct | 4 ms | 512 KB | Output is correct |
2 | Correct | 19 ms | 1280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 2048 KB | Output is correct |
2 | Correct | 46 ms | 2612 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 6736 KB | Output is correct |
2 | Correct | 284 ms | 14248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 339 ms | 16936 KB | Output is correct |
2 | Correct | 98 ms | 3892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 833 ms | 41772 KB | Output is correct |
2 | Execution timed out | 1095 ms | 94136 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 676 ms | 32548 KB | Output is correct |
2 | Execution timed out | 1105 ms | 111624 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |