Submission #690986

# Submission time Handle Problem Language Result Execution time Memory
690986 2023-01-30T20:08:02 Z ansgar Type Printer (IOI08_printer) C++17
0 / 100
78 ms 21144 KB
#include <bits/stdc++.h>
using namespace std;

#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vb vector<bool>
#define vc vector<char>
#define vvc vector<vc>
#define vvb vector<vb>z
#define si set<int>
#define mii map<int,int>

const int MOD=1e9+7;
const int N=2e5+1;
struct Nodo{
    map<char,Nodo*>childs;
    bool end=false;
    int depth=1;
};
void add(Nodo* Trie,string& word,int index=0){
    if((int)word.size()==index){
        Trie->end=true;
        return;
    }
    char character=word[index];
    if(Trie->childs.find(character)==Trie->childs.end()){
        Trie->childs[character]=new Nodo;
    }
    add(Trie->childs[character],word,index+1);
    Trie->depth=max(Trie->depth,Trie->childs[character]->depth+1);
}
int ned=0;
void solve(Nodo* Trie){
    char last='P';
    if(ned and Trie->end)cout<<"P\n",ned--;
    int ma=0;
    for(char e='a';e<='z';e++){
        if(Trie->childs.find(e)!=Trie->childs.end()){
            if(Trie->childs[e]->depth>ma){
                ma=Trie->childs[e]->depth;
                last=e;
            }
        }
    }
    //cerr<<Trie->depth<<" "<<last<<endl;
    for(char e='a';e<='z';e++){
        if(e==last)continue;
        if(Trie->childs.find(e)!=Trie->childs.end()){
            //cerr<<char(e)<<endl;
            if(ned)cout<<e<<"\n";
            solve(Trie->childs[e]);
            if(ned)cout<<"-\n";
        }
    }
    if(last=='P')return;
    if(ned)cout<<last<<"\n";
    solve(Trie->childs[last]);
    if(ned)cout<<"-\n";
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    ned=n;
    Nodo* Root=new Nodo;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        add(Root,s);
    }
    solve(Root);
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1108 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 3476 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 8476 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 21144 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 16604 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -