Submission #226456

# Submission time Handle Problem Language Result Execution time Memory
226456 2020-04-23T20:33:48 Z hackermub Type Printer (IOI08_printer) C++17
20 / 100
130 ms 46700 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=1;
}

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');
        now->cnt--;
    }
    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);
    while(ans.back()!='P') ans.pop_back();
    cout<<ans.size();
    for(auto c:ans) cout<<"\n"<<c;
    //endscreen();
    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 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 22 ms 7552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 18808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 46700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 36468 KB Output isn't correct
2 Halted 0 ms 0 KB -