# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954819 | 2024-03-28T15:49:48 Z | PieArmy | Type Printer (IOI08_printer) | C++17 | 112 ms | 70080 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; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); 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; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 66852 KB | Output is correct |
2 | Correct | 28 ms | 66932 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 66824 KB | Output is correct |
2 | Correct | 28 ms | 66780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 66908 KB | Output is correct |
2 | Correct | 28 ms | 66908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 66904 KB | Output is correct |
2 | Correct | 30 ms | 66896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 66896 KB | Output is correct |
2 | Correct | 29 ms | 66956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 66908 KB | Output is correct |
2 | Correct | 29 ms | 66908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 67152 KB | Output is correct |
2 | Correct | 36 ms | 67484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 67276 KB | Output is correct |
2 | Correct | 34 ms | 67412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 68092 KB | Output is correct |
2 | Correct | 83 ms | 69576 KB | Output is correct |
3 | Correct | 59 ms | 68520 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 67784 KB | Output is correct |
2 | Correct | 112 ms | 70080 KB | Output is correct |
3 | Correct | 63 ms | 68812 KB | Output is correct |
4 | Correct | 80 ms | 70056 KB | Output is correct |