# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546312 | krit3379 | Type Printer (IOI08_printer) | C++17 | 149 ms | 94396 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 N 25
struct node{
int nxt[26],dep[26];
bool is_end;
}t[1000000];
struct A{
int nxt,dep;
char c;
bool operator<(const A& o)const{
return dep<o.dep;
}
};
int sz;
char s[N];
vector<char> ans;
void add(int n){
int i,now=0;
for(i=1;i<=n;i++){
int idx=s[i]-'a';
if(!t[now].nxt[idx])t[now].nxt[idx]=++sz;
t[now].dep[idx]=max(t[now].dep[idx],n);
now=t[now].nxt[idx];
}
t[now].is_end=true;
}
void dfs(int now){
if(t[now].is_end)ans.push_back('P');
vector<A> temp;
for(int i=0;i<26;i++){
if(t[now].nxt[i]){
temp.push_back({t[now].nxt[i],t[now].dep[i],'a'+i});
}
}
sort(temp.begin(),temp.end());
for(auto [nxt,dep,c]:temp){
ans.push_back(c);
dfs(nxt);
ans.push_back('-');
}
}
int main(){
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf(" %s",s+1);
add(strlen(s+1));
}
dfs(0);
while(ans.back()=='-')ans.pop_back();
printf("%d\n",ans.size());
for(auto x:ans)printf("%c\n",x);
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... |