# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093856 | lambd47 | Type Printer (IOI08_printer) | C++14 | 45 ms | 54868 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;
const int MX=5e5+1;
int trie[MX][27];
char letra[MX];
bool ultimo[MX];
int tempo=0;
void add(string s, bool flag){
int idat=0;
for(auto c: s){
int nat=c-'a';
if(trie[idat][nat]!=-1){
idat=trie[idat][nat];
}
else{
trie[idat][nat]=++tempo;
idat=tempo;
letra[idat]=c;
}
if(flag)ultimo[idat]=1;
}
}
int n;
bool acabou=0;
int cnt=0;
void dfs(int node){
if(node!=0)cout<<letra[node]<<"\n";
int esp=-1;
bool folha=1;
for(int i=0;i<26;i++){
if(trie[node][i]==-1)continue;
folha=0;
if(ultimo[trie[node][i]]){
esp=trie[node][i];
continue;
}
dfs(trie[node][i]);
}
if(esp!=-1){
dfs(esp);
}
if(folha){cout<<"P\n";cnt++;}
if(cnt!=n && !ultimo[node])cout<<"-\n";
}
int main(){
cin>>n;
for(int i=0;i<MX;i++){
for(int j=0;j<27;j++)trie[i][j]=-1;
}
vector<string> vec(n);
int especial=0;
int maior=0;
for(int i=0;i<n;i++){cin>>vec[i];
if(maior<vec[i].size()){
maior=vec[i].size();
especial=i;
}
}
for(int i=0;i<n;i++){
if(especial==i){
add(vec[i],1);
}
else{
add(vec[i],0);
}
}
cout<<2*(tempo)-maior+n;
dfs(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... |