# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444019 | 2021-07-13T01:57:54 Z | cpp219 | Type Printer (IOI08_printer) | C++14 | 206 ms | 99060 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 = max(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 = 6969; 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 (chosen < 26 && 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 "test" 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(); //return 0; 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 | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 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 | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 2 ms | 1100 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1740 KB | Output is correct |
2 | Correct | 4 ms | 2124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 5796 KB | Output is correct |
2 | Correct | 26 ms | 12356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 14492 KB | Output is correct |
2 | Correct | 10 ms | 3148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 80 ms | 36236 KB | Output is correct |
2 | Correct | 172 ms | 83220 KB | Output is correct |
3 | Correct | 94 ms | 42716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 28372 KB | Output is correct |
2 | Correct | 206 ms | 99060 KB | Output is correct |
3 | Correct | 106 ms | 48480 KB | Output is correct |
4 | Correct | 195 ms | 93556 KB | Output is correct |