Submission #635362

# Submission time Handle Problem Language Result Execution time Memory
635362 2022-08-26T06:48:30 Z NeroZein Type Printer (IOI08_printer) C++17
10 / 100
46 ms 36188 KB
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=a; i<=(b); i++)

using namespace std;
int n;
long long ans;
string mx;

struct node{
    node* ch[26];
    int cnt; 
    node(){
        for(int i=0;i<26;i++)
            ch[i] = NULL;
        cnt = 0;
    }
};

node* root = new node();
void add(string s){
    node* cur = root; 
    for(int i=0;i<s.size();i++){
        int id = s[i]-'a';
        if (cur->ch[id] == NULL)
            cur->ch[id] = new node(),ans+=2;
        cur = cur->ch[id];
        cur->cnt++;
    }
}

void dfs(node* go,int lv=-1){
    bool leaf = 0;int left = -1;
    if(go != root)leaf = 1;
    for(int i=0;i<26;i++){
        if(go->ch[i] == NULL)continue;
        leaf = 0;
        if(mx[lv+1]==(i+'a')){left=i;continue;}
        cout<<(char(i+'a'))<<'\n';
        dfs(go->ch[i],lv+1);
        cout<<('-')<<'\n';
    }
    if (left!=-1){
        cout<<(char('a'+left))<<'\n';
        dfs(go->ch[left],lv+1);
    }
    if (leaf)
        cout<<('P')<<'\n';
}

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin>>n;
    FOR(i,1,n){
        string s; 
        cin>>s; 
        add(s);
        if((int)mx.size() < (int)s.size())
            mx = s; 
    }
    cout<<ans-(int)mx.size()+n<<'\n';
    dfs(root);
}

Compilation message

printer.cpp: In function 'void add(std::string)':
printer.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 324 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1748 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 5832 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 14536 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 36188 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 28236 KB printed invalid word
2 Halted 0 ms 0 KB -