# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954818 | 2024-03-28T15:45:06 Z | PieArmy | Type Printer (IOI08_printer) | C++17 | 54 ms | 68180 KB |
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} struct Node{ int *a=new int[26]; bool word=false; int deep=-1,depth=0; }; vector<char>ans; Node trie[500000]; int node_cnt=1; void ekle(string word){ int cur=0; for(char c:word){ if(word.size()>trie[cur].depth){ trie[cur].depth=word.size(); trie[cur].deep=c-'a'; } if(!trie[cur].a[c-'a']){ trie[cur].a[c-'a']=node_cnt++; } cur=trie[cur].a[c-'a']; } trie[cur].word=true; } void code(){ int n;cin>>n; for(int i=0;i<n;i++){ string s;cin>>s; ekle(s); } function<void(int)>f=[&](int pos)->void{ if(trie[pos].word){ ans.pb('P'); } for(int i=0;i<26;i++){ if(trie[pos].deep==i)continue; if(trie[pos].a[i]==0)continue; ans.pb(char('a'+i)); f(trie[pos].a[i]); } if(trie[pos].deep!=-1){ ans.pb(char('a'+trie[pos].deep)); f(trie[pos].a[trie[pos].deep]); } ans.pb('-'); }; f(0); n=ans.size(); while(ans[n-1]=='-')n--; cout<<n<<endl; for(int i=0;i<n;i++) cout<<ans[i]<<endl; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 28 ms | 66900 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 66900 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 66900 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 31 ms | 66896 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 66908 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 66896 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 32 ms | 67164 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 38 ms | 67532 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 54 ms | 68180 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 48 ms | 68040 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |