# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534025 | __Variatto | Type Printer (IOI08_printer) | C++17 | 177 ms | 115288 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 pb push_back
#define fi first
#define se second
#define ll long long
const int A=30;
const int MAX=25e3+10;
struct st{
st* a[A];
int kon;
};
int n;
string s[MAX];
void stworz(st *v, char c){
if(v->a[c-'a']!=nullptr)
return;
st *nowy=new st;
for(int i=0; i<A; i++)
nowy->a[i]=nullptr;
nowy->kon=0;
v->a[c-'a']=nowy;
}
void dodaj(st* r, string s){
st *x=r;
for(int i=0; i<s.size(); i++){
stworz(x, s[i]);
x=x->a[s[i]-'a'];
}
x->kon++;
}
string ost;
vector<char>wyn;
void dfs(st* v, int j){
for(int i=1; i<=v->kon; i++)
wyn.pb('P');
for(int i=0; i<A; i++){
if(i==ost[j]-'a')
continue;
if(v->a[i]!=nullptr){
wyn.pb(char(i+'a'));
dfs(v->a[i], j+1);
}
}
//return;
if(j<ost.size() && v->a[ost[j]-'a']!=nullptr){
wyn.pb(ost[j]);
dfs(v->a[ost[j]-'a'], j+1);
}
wyn.pb('-');
}
int main(){
/* ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
*/ cin>>n;
st *r=new st;
for(int i=0; i<A; i++)
r->a[i]=nullptr;
r->kon=0;
pair<int,int> maxi={0,0};
for(int i=1; i<=n; i++){
cin>>s[i];
dodaj(r, s[i]);
maxi=max(maxi, {int(s[i].size()), i});
}
ost=s[maxi.se];
dfs(r, 0);
while(wyn.size() && wyn.back()=='-')
wyn.pop_back();
cout<<wyn.size()<<"\n";
for(auto x: wyn)
cout<<x<<"\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... |