# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499087 | 2021-12-27T08:17:01 Z | Nartifact | Type Printer (IOI08_printer) | C++14 | 141 ms | 99628 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,b) for (int i=0;i<b;++i) #define forinc(i,a,b) for(int i=a;i<=b;++i) #define fordec(i,a,b) for(int i=a;i>=b;--i) #define pb push_back #define eb emplace_back #define pii pair <int,int> #define piii pair <int, pii> #define fi first #define se second #define two(x) (1ll << x) #define getbit(i, x) (x >> i & 1ll) #define onbit(i, x) (x|(1ll << i)) #define offbit(i, x) (x & ~(1ll << i)) #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() const int N = 25025; int n; string sta; vector <char> ans; struct node { node* child[26]; bool eos, ok; node () { forinc(i,0,25) child[i] = nullptr; eos = ok = 0; } }; struct Trie { node* root; Trie () {root = new node();} void add (const string& s, const bool& type) { node* tmp = root; for (char c : s) { int pos = c - 'a'; if(!tmp->child[pos]) tmp->child[pos] = new node(); tmp = tmp->child[pos]; tmp->ok = type; } tmp->eos = 1; tmp->ok = type; } void solve (node* tmp) { if(tmp->eos) ans.eb('P'); int check = -1; forinc(i,0,25) if(tmp->child[i]) { node* nxt = tmp->child[i]; if(nxt->ok) check = i; else { ans.eb(i + 'a'); solve(nxt); ans.eb('-'); } } if(check != -1){ ans.eb(check + 'a'); solve(tmp->child[check]); } } } trie; void read () { cin >> n; string s; forinc(i,1,n) { cin >> s; trie.add(s, 0); if(s.size() > sta.size()) sta = s; } trie.add(sta, 1); trie.solve(trie.root); cout << ans.size() << '\n'; for (char i : ans) cout << i << '\n'; } main () { #define task "" cin.tie(0) -> sync_with_stdio(0); if(fopen (task ".inp", "r")) { freopen (task ".inp", "r", stdin); freopen (task ".out", "w", stdout); } read(); return 0; }
Compilation message
# | 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 | 0 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Correct | 1 ms | 1100 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1740 KB | Output is correct |
2 | Correct | 3 ms | 2252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5936 KB | Output is correct |
2 | Correct | 17 ms | 12568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 14804 KB | Output is correct |
2 | Correct | 6 ms | 3388 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 36596 KB | Output is correct |
2 | Correct | 101 ms | 83668 KB | Output is correct |
3 | Correct | 58 ms | 43312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 28636 KB | Output is correct |
2 | Correct | 141 ms | 99628 KB | Output is correct |
3 | Correct | 72 ms | 49112 KB | Output is correct |
4 | Correct | 100 ms | 94004 KB | Output is correct |