# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
980628 | enkhochir | Type Printer (IOI08_printer) | C++14 | 98 ms | 100884 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 long long
int n;
string s[25005];
int trie[500005][27];
int longest=0;
int cnt=1;
string ans="";
bool islong[500005], isend[500005];
void dfs(int node){
if(isend[node]){
ans+='P';
// return;
}
int tmp=-1;
for(int i=0; i<26; i++){
if(trie[node][i]>0){
if(islong[trie[node][i]]){
tmp=i;
}
else{
char tmpchar='a'+i;
ans+=tmpchar;
dfs(trie[node][i]);
ans+='-';
}
}
}
if(tmp!=-1){
char tmpchar='a'+tmp;
ans+=tmpchar;
dfs(trie[node][tmp]);
ans+='-';
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(NULL);
cin>>n;
for(int i=0; i<n; i++){
cin>>s[i];
int sz=s[i].size();
longest=max(longest,sz);
}
for(int i=0; i<n; i++){
bool flag=0;
if(s[i].size()==longest){
longest=-1;
flag=1;
}
int cur=0;
for(int j=0; j<s[i].size(); j++){
if(trie[cur][s[i][j]-'a']==0){
trie[cur][s[i][j]-'a']=cnt;
cnt++;
}
// islong[cur]=flag;
islong[trie[cur][s[i][j]-'a']]|=flag;
cur=trie[cur][s[i][j]-'a'];
}
isend[cur]=1;
}
dfs(0);
while(ans.back()=='-'){
ans.pop_back();
}
cout<<ans.size()<<'\n';
for(int i=0; i<ans.size(); i++){
cout<<ans[i]<<'\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... |