# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954818 | PieArmy | Type Printer (IOI08_printer) | C++17 | 54 ms | 68180 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |