Submission #226433

# Submission time Handle Problem Language Result Execution time Memory
226433 2020-04-23T19:30:53 Z hackermub Type Printer (IOI08_printer) C++17
20 / 100
120 ms 46448 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
#define pii pair<int,int>
#define pqi priority_queue<int>
#define pb push_back()
#define INF 1000000000000000000
#define pi acos(-1)
#define deb(x) cout<<#x" = "<<x<<" "
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define all(x) x.begin(),x.end()
const int modu=1e9+7;
#define ull unsigned long long
 
int bigmod(int n,int p){
    if(p==0) return 1;
    int x=bigmod(n,p/2)%modu;
    x=(x*x)%modu;
    if(p%2) return (x*n)%modu;
    return x;
}
 
int modInverse(int a){
    return bigmod(a,modu-2)%modu;
}


int add(int a,int b){
    int ans=(a%modu + b%modu)%modu;
    while(ans<0) ans+=modu;
    return ans;
}

int mul(int a,int b){
    int ans=(a%modu * b%modu)%modu;
    while(ans<0) ans+=modu;
    return ans;
}

// starts here
const int MAXN=25001;
int n;
vector<char> ans;

class node{
public:
    int cnt=0,depth;
    char id;
    vector<node*> child;
    node(){
        child.resize(26,NULL);
    };
};

bool cmp(node* a,node* b){
    int ha=(a)? a->depth:0;
    int hb=(b)? b->depth:0;
    return ha<hb;
}

node* root;

void insert(string x){
    node *now=root;
    for(auto c:x){
        c-='a';
        if(!now->child[c]) now->child[c]=new node();
        now=now->child[c];
        now->id=c+'a';
    }
    now->cnt++;
}

void dfs1(node *now){
    now->depth=0;
    for(auto nd:now->child)if(nd){
        dfs1(nd);
        now->depth=max(now->depth,nd->depth+1);
    }
    //deb(now->id),deb(now->depth)<<endl;
    sort(all(now->child),cmp);
}

void dfs2(node *now){
    for(auto nd:now->child)if(nd){
        ans.push_back(nd->id);
        dfs2(nd);
    }
    while(now->cnt){
        ans.push_back('P');
        n--;
        now->cnt--;
    }
    if(n) ans.push_back('-');
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie();cout.tie();
    //If you hack my code , You are gay;
    cin>>n;
    root=new node();
    for(int i=0;i<n;i++){
        string x;
        cin>>x;
        insert(x);
    }
    dfs1(root);
    dfs2(root);
    cout<<ans.size();
    for(auto c:ans) cout<<"\n"<<c;
    //endscreen();
    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 7680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 18680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 46448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 36340 KB Output isn't correct
2 Halted 0 ms 0 KB -