# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444015 | 2021-07-13T01:33:35 Z | cpp219 | Type Printer (IOI08_printer) | C++14 | 202 ms | 99560 KB |
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 1e5 + 9; const ll Log2 = 20; const ll inf = 1e9 + 7; deque<char> ans; string s; ll n; struct Trie{ Trie *child[26]; ll End,mx; Trie (){ for (ll i = 0;i < 26;i++) child[i] = NULL; End = 0; mx = 0; } void Add(ll pos,string &s){ if (pos == s.size()){ End++; mx = 1; return; } ll now = s[pos] - 'a'; if (!child[now]) child[now] = new Trie; child[now] -> Add(pos + 1,s); mx = max(mx,child[now] -> mx + 1); } void DFS(){ while(End--) ans.push_back('P'); ll cur = 0,chosen = 0; for (ll i = 0;i < 26;i++) if (child[i] && cur < child[i] -> mx) cur = child[i] -> mx, chosen = i; for (ll i = 0;i < 26;i++){ if (child[i] && i != chosen) ans.push_back(i + 'a'),child[i] -> DFS(); } if (child[chosen]) ans.push_back(chosen + 'a'),child[chosen] -> DFS(); ans.push_back('-'); } }; Trie Tree; int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n; for (ll i = 1;i <= n;i++){ cin>>s; Tree.Add(0,s); } Tree.DFS(); while(ans.back() == '-') ans.pop_back(); cout<<ans.size()<<"\n"; for (auto i : ans) cout<<i<<"\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 332 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 332 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1740 KB | Output is correct |
2 | Incorrect | 5 ms | 2252 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 5836 KB | Output is correct |
2 | Correct | 27 ms | 12336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 14640 KB | Output is correct |
2 | Correct | 10 ms | 3276 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 36432 KB | Output is correct |
2 | Correct | 167 ms | 83652 KB | Output is correct |
3 | Correct | 90 ms | 43048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 73 ms | 28484 KB | Output is correct |
2 | Correct | 202 ms | 99560 KB | Output is correct |
3 | Correct | 103 ms | 48836 KB | Output is correct |
4 | Correct | 180 ms | 93944 KB | Output is correct |