# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061167 | 2024-08-16T06:57:04 Z | belgianbot | Type Printer (IOI08_printer) | C++17 | 59 ms | 31944 KB |
#include <bits/stdc++.h> #define int long long using namespace std; vector<char> ans, letters; vector<vector<pair<int,int>>> adj; void dfs(int curr) { sort(adj[curr].begin(), adj[curr].end()); //if (adj[curr].empty()) ans.push_back('P'); for (auto x : adj[curr]) { ans.push_back(letters[x.second]); dfs(x.second); if (letters[x.second] != 'P') ans.push_back('-'); } } signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<string> words(N); for (int i = 0; i < N; i++) cin >> words[i]; sort(words.begin(), words.end()); int cnt = 1; letters.resize(N * 21 + 1); adj.resize(N * 20 + 1); for (int i = 0; i < N; i++) { int pos = 0; for (int j = 0; j < words[i].length(); j++) { bool exist = false; for (int k = 0; k < adj[pos].size(); k++) { auto x = adj[pos][k]; if (letters[x.second] == words[i][j]) { int left = (int)words[i].length() - j - 1; if (left > adj[pos][k].first) adj[pos][k].first = left; pos = x.second; exist = true; break; } } if (!exist) { adj[pos].push_back({(int)words[i].length() - j - 1, cnt}); letters[cnt] = words[i][j]; pos = cnt; cnt++; } } adj[pos].push_back({0, cnt}); letters[cnt] = 'P'; cnt++; } dfs(0); int m = ans.size(); for (int i = m-1; ans[i] == '-'; i--) { ans.pop_back(); } m = ans.size(); cout << m << '\n'; for (int i = 0; i < m; i++) cout << ans[i] << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1116 KB | Output is correct |
2 | Correct | 2 ms | 1372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2908 KB | Output is correct |
2 | Correct | 11 ms | 5976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 7896 KB | Output is correct |
2 | Correct | 8 ms | 7772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 16452 KB | Output is correct |
2 | Correct | 53 ms | 26876 KB | Output is correct |
3 | Correct | 32 ms | 20940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 18896 KB | Output is correct |
2 | Correct | 59 ms | 31944 KB | Output is correct |
3 | Correct | 36 ms | 23640 KB | Output is correct |
4 | Correct | 55 ms | 31184 KB | Output is correct |