| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 965351 | noyancanturk | Type Printer (IOI08_printer) | C++17 | 129 ms | 99784 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.
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define pb push_back
const int lim=1e6+100;
const int mod=1e9+7;
using pii=pair<int,int>;
vector<char>ans;
struct trie{
struct node{
int c[26],depth;
bool have;
};
node nds[lim];
int nextunused=2;
void insert(const string&s){
int cur=1;
int i=0;
while(i<s.size()){
if(nds[cur].c[s[i]-'a']==0){
nds[cur].c[s[i]-'a']=nextunused++;
}
cur=nds[cur].c[s[i++]-'a'];
}
nds[cur].have=1;
}
struct iterator{
trie*par;
int cur;
iterator(trie*par,int b):par(par),cur(b){}
node* operator()(){
return par->nds+cur;
}
void operator+=(char cc){
cur=par->nds[cur].c[cc-'a'];
}
bool operator==(const iterator&it){
return par==it.par&&cur==it.cur;
}
};
const iterator begin() {
return iterator(this,1);
};
const iterator end(){
return iterator(this,0);
}
int depdfs(node*p){
if(!p)return 0;
p->depth=1;
for(int i=0;i<26;i++){
if(p->c[i])p->depth=max(p->depth,1+depdfs(nds+p->c[i]));
}
return p->depth;
}
void dfs(node*p,bool nope){
if(!p)return;
if(p->have)ans.pb('P');
int maxchild=0,maxind=-1;
if(!nope)for(int i=0;i<26;i++){
if(nds[maxchild].depth<nds[p->c[i]].depth){
maxchild=p->c[i];
maxind=i;
}
}
for(int i=0;i<26;i++){
if(p->c[i]!=maxchild&&p->c[i]){
ans.pb(i+'a');
dfs(nds+p->c[i],1);
ans.pb('-');
}
}
if(maxchild){
ans.pb(maxind+'a');
dfs(nds+maxchild,0);
}
}
}tr;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen(".in","r",stdin); freopen(".out","w",stdout);
#endif
int n;
cin>>n;
for(int i=0;i<n;i++){
string s;
cin>>s;
tr.insert(s);
}
tr.depdfs(tr.nds+1);
tr.dfs(tr.nds+1,0);
cout<<ans.size()<<"\n";
for(char c:ans){
cout<<c<<"\n";
}
}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... | ||||
