# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737947 | guagua0407 | Type Printer (IOI08_printer) | C++17 | 102 ms | 56664 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.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=2.5e4*20+5;
int trie[mxn][26];
int cnt[mxn];
char c[mxn];
int cur=1;
vector<char> ans;
string mx="";
void dfs(int v,int d=0,bool tf=true){
if(v!=0) ans.push_back(c[v]);
if(cnt[v]) ans.push_back('P');
for(int i=0;i<26;i++){
if(trie[v][i]!=-1){
if(tf and (mx[d]-'a')==i) continue;
dfs(trie[v][i],d+1,false);
}
}
if(tf and d<(int)mx.length()){
dfs(trie[v][mx[d]-'a'],d+1,true);
}
if(v!=0) ans.push_back('-');
}
void insert(string str){
int v=0,i=0;
while(i<str.length()){
if(trie[v][str[i]-'a']==-1){
trie[v][str[i]-'a']=cur;
v=cur;
c[cur]=str[i];
cur++;
}
else{
v=trie[v][str[i]-'a'];
}
i++;
}
cnt[v]++;
}
int main() {_
for(int i=0;i<mxn;i++){
for(int j=0;j<26;j++){
trie[i][j]=-1;
}
}
int n;
cin>>n;
for(int i=0;i<n;i++){
string str;
cin>>str;
insert(str);
if(str.length()>mx.length()){
mx=str;
}
}
dfs(0);
while(ans.back()=='-') ans.pop_back();
cout<<(int)ans.size()<<'\n';
for(auto v:ans){
cout<<v<<'\n';
}
return 0;
}
//maybe its multiset not set
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... |