# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1000318 | 2024-06-17T08:36:10 Z | AtabayRajabli | Type Printer (IOI08_printer) | C++17 | 1000 ms | 150076 KB |
#include <bits/stdc++.h> // author : a1abay using namespace std; #define int ll #define all(v) v.begin(), v.end() typedef long long ll; typedef long double ld; const int inf = 1e9 + 7; const int inff = (int)1e18 + 7; const int sz = 25e3 + 5; int n, k, x = 0; int t[sz * 26][26], mx[sz * 26], d[sz * 26]; bool w[sz * 26]; vector<array<int, 3>> g[sz * 26]; string s; set<int> st; void add(int ind, int cur) { while(ind < s.size()) { if(t[cur][s[ind] - 'a']) cur = t[cur][s[ind] - 'a']; else cur = t[cur][s[ind] - 'a'] = ++x; ind++; } w[cur] = 1; } void dfs(int v) { bool lf = 1; for(int i = 0; i < 26; i++) { if(!t[v][i]) continue; lf = 0; int c = t[v][i]; d[c] = d[v] + 1; dfs(c); mx[v] = max(mx[v], mx[c]); } for(int i = 0; i < 26; i++) { if(!t[v][i]) continue; int c = t[v][i]; g[v].push_back({mx[c], c, i}); } sort(all(g[v])); if(lf) mx[v] = d[v]; } void calc(int v, char c) { if(st.size() == x) return; st.insert(v); cout << c << endl; if(w[v]) cout << "P" << endl; for(auto i : g[v]) { calc(i[1], char(i[2] + 'a')); } if(st.size() < x)cout << "-" << endl; } void solve() { cin >> n; for(int i = 0; i < n; i++) { cin >> s; add(0, 0); } dfs(0); cout << x * 2 - mx[0] + n << endl; for(auto i : g[0]) { calc(i[1], char(i[2] + 'a')); } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while(t--) { solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 19036 KB | Output is correct |
2 | Correct | 3 ms | 19036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 19032 KB | Output is correct |
2 | Correct | 3 ms | 19036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 19036 KB | Output is correct |
2 | Correct | 3 ms | 19036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 19036 KB | Output is correct |
2 | Correct | 3 ms | 19036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 19036 KB | Output is correct |
2 | Correct | 17 ms | 20020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 20828 KB | Output is correct |
2 | Correct | 26 ms | 21428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 25940 KB | Output is correct |
2 | Correct | 134 ms | 34264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 167 ms | 37100 KB | Output is correct |
2 | Correct | 62 ms | 22608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 414 ms | 66692 KB | Output is correct |
2 | Correct | 888 ms | 129888 KB | Output is correct |
3 | Correct | 477 ms | 74844 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 301 ms | 56660 KB | Output is correct |
2 | Execution timed out | 1062 ms | 150076 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |