Submission #1065018

# Submission time Handle Problem Language Result Execution time Memory
1065018 2024-08-18T21:21:42 Z YassirSalama Type Printer (IOI08_printer) C++17
0 / 100
490 ms 37644 KB
#include<bits/stdc++.h>
using namespace std;
struct Node{
    Node* c[26];
    int maxdepth=0;
    bool leaf=false;
    Node(){
        for(int i=0;i<26;i++) c[i]=nullptr;
    }
};
Node* root=new Node();
void insert(string s){
    Node* node=root;
    int n=s.length();
    for(int i=0;i<n;i++){
        if(node->c[s[i]-'a']==nullptr) node->c[s[i]-'a']  = new Node();
        node=node->c[s[i]-'a'];
        node->maxdepth=max(node->maxdepth,n);
        node->leaf=true;
    }
}
int k;
vector<char> op;
void dfs(Node* node){
    vector<pair<int,int>> v;
    for(int i=0;i<26;i++){
        if(node->c[i]!=nullptr){
            v.push_back({node->c[i]->maxdepth,i});
        }
    }
    if(v.empty()){
        k--;
        op.push_back('P');
        return;
    }
    if(node->leaf){
        k--;
        op.push_back('P');
    }
    sort(v.begin(),v.end());
    for(auto x:v){
        op.push_back(char('a'+x.second));
        dfs(node->c[x.second]);
        if(k!=0){
            op.push_back('-');
        }
    }
}
signed main(){
    int n;
    cin>>n;
    k=n;
    vector<string> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        insert(v[i]);
    }
    dfs(root);
    cout<<op.size()<<endl;
    for(auto x:op){
        cout<<x<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 2000 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 6192 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 200 ms 15056 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 490 ms 37644 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 444 ms 29648 KB printed invalid word
2 Halted 0 ms 0 KB -