# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
318441 | 2020-11-01T21:56:08 Z | shrek12357 | Type Printer (IOI08_printer) | C++14 | 913 ms | 25948 KB |
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <climits> #include <cmath> #include <fstream> #include <queue> #include <stack> #include <bitset> using namespace std; #define ll long long //cin.tie(0);ios_base::sync_with_stdio(0); const int MAXN = 25000 * 20 + 3; int counter = 1; vector<int> adjList[MAXN]; map<int, int> cc; vector<char> ans; int depth[MAXN]; bool comp(int a, int b) { return depth[a] < depth[b]; } void init(string word, int src, int pos) { if (pos >= word.size()) { return; } int idx = -1; for (auto i : adjList[src]) { if (cc[i] == word[pos]) { idx = i; break; } } int nxt = -1; if (idx == -1) { adjList[src].push_back(counter); cc[counter] = word[pos]; nxt = counter; counter++; } else { nxt = idx; } init(word, nxt, pos + 1); depth[src] = max(depth[src], depth[nxt] + 1); } void dfs(int src) { if (adjList[src].size() == 0) { ans.push_back('P'); } sort(adjList[src].begin(), adjList[src].end(), comp); for (auto i : adjList[src]) { ans.push_back(cc[i]); dfs(i); } if(src != 0) ans.push_back('-'); } int main() { int n; cin >> n; vector<string> words; for (int i = 0; i < n; i++) { string s; cin >> s; init(s, 0, 0); } dfs(0); while (ans[ans.size() - 1] == '-') { ans.pop_back(); } cout << ans.size() << endl; for (auto i : ans) { cout << i << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12012 KB | Output is correct |
2 | Correct | 8 ms | 12012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 12140 KB | Output is correct |
2 | Correct | 9 ms | 12012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 12140 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12032 KB | Output is correct |
2 | Incorrect | 8 ms | 12012 KB | didn't print every word |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 12140 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 43 ms | 12652 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 138 ms | 14308 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 355 ms | 17636 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 913 ms | 25948 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 787 ms | 22752 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |