# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63240 | Tenuun | Type Printer (IOI08_printer) | C++17 | 198 ms | 108448 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>
#define pb push_back
using namespace std;
string m;
struct node{
char c;
int val=0, mx=0;
node *l[26];
node(){
for(int i=0; i<26; i++) {
l[i]=NULL;
}
}
};
vector<char>res;
node *root=new node;
void insert(string s){
node *now=root;
int v;
for(int i=0; i<s.length(); i++){
v=s[i]-'a';
if(now->l[v]==NULL){
now->l[v]=new node;
now->l[v]->c=s[i];
now->l[v]->val++;
}
else{
now->l[v]->val++;
}
now->mx++;
now=now->l[v];
}
}
void swp(){
node *now=root;
int ind=0;
while(ind<m.length()){
for(int i=0; i<26; i++){
if(i==m[ind]-'a'){
swap(now->l[25], now->l[i]);
now=now->l[25];
break;
}
}
ind++;
}
}
void print(node *now){
int cnt=0;
for(int i=0; i<26; i++){
if(now->l[i]==NULL) continue;
cnt++;
res.pb(now->l[i]->c);
//cout << now->l[i]->mx << " " << now->l[i]->val << endl;
for(int j=now->l[i]->mx; j<now->l[i]->val; j++) res.pb('P');
print(now->l[i]);
res.pb('-');
}
if(cnt==0){
//res.pb('P');
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, t=0;
cin >> n;
string s;
for(int i=0; i<n; i++){
cin >> s;
if(s.length()>t){
m=s;
t=s.length();
}
insert(s);
}
swp();
print(root);
while(res[res.size()-1]=='-'){
res.pop_back();
}
cout << res.size() << endl;
for(int i=0; i<res.size(); i++) if(res[i]!='#')cout << res[i] << '\n';
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... |