# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924973 | 2024-02-10T08:59:37 Z | vjudge1 | Type Printer (IOI08_printer) | C++17 | 52 ms | 20172 KB |
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define pii pair<int,int> const int mod = 1e9 + 7; const int mxN = 6e5 + 5; using namespace std; int trie[mxN][26]; int nodeCnt; char cnt[mxN]; int p[mxN]; string chk; int ed; void insert(int u = 0){ for(int i = 0;i <chk.size();i++){ if(!trie[u][chk[i] - 'a']) trie[u][chk[i] - 'a'] = ++nodeCnt; u = trie[u][chk[i] - 'a']; cnt[u] = chk[i]; } } void calcD(int u = 0,int dep = 0){ ed = u; // cout<<u<<' '; for(int i = 0;i < 26;i++){ if(trie[u][i]) { p[trie[u][i]] = u; calcD(trie[u][i],dep + 1); } } } set<int>path; vector<char>ans; void query(int u = 0){ queue<int> q; int lst = -1; for(int i = 0;i < 26;i++){ if(trie[u][i]){ if(path.find(trie[u][i]) != path.end()) lst = trie[u][i]; else q.push(trie[u][i]); } } if(lst == -1 && q.empty()){ ans.push_back('P'); return; } if(lst != -1) q.push(lst); while(q.size()){ ans.push_back(cnt[q.front()]); query(q.front()); q.pop(); } ans.push_back('-'); } signed main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); int n; cin >>n; for(int i = 0;i < n;i++){ cin >>chk; insert(); } calcD(); while(ed){ path.insert(ed); ed = p[ed]; } query(); // cout<<"TEST\n"; while(ans.back() == '-') ans.pop_back(); cout<<ans.size()<<'\n'; for(auto x : ans){ cout<<x<<'\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | printed invalid word |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 1112 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 3164 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 9680 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 52 ms | 20172 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 42 ms | 16080 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |