Submission #1003405

# Submission time Handle Problem Language Result Execution time Memory
1003405 2024-06-20T09:52:25 Z fryingduc Type Printer (IOI08_printer) C++17
10 / 100
38 ms 36180 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 25005;
int n;
string del;

struct trie {
    int total_nodes;
    struct node {
        node *child[26];
        bool exist;
        node() { 
            exist = 0;
            for(int i = 0; i < 26; ++i) {
                child[i] = nullptr;
            }
        }        
    } *root;
    trie() {
        total_nodes = 0;
        root = new node();
    }
    void add(string &s) {
        node *p = root;
        for(int i = 0; i < (int)s.size(); ++i) {
            int c = s[i] - 'a';
            if(p->child[c] == nullptr) {
                p->child[c] = new node();
                ++total_nodes;
            }
            p = p->child[c];
        }
        p->exist = 1;
    }
    void dfs(int depth, node *p) {
        for(int i = 0; i < 26; ++i) {
            if(p->child[i] == nullptr || i == del[depth] - 'a') continue;
            cout << char(i + 'a') << '\n';
            dfs(depth + 1, p->child[i]);
            cout << '-' << '\n';
        }
        if(depth < (int)del.size() and p->child[del[depth] - 'a'] != nullptr) {
            cout << del[depth] << '\n';
            dfs(depth + 1, p->child[del[depth] - 'a']);
//            cout << '-' << '\n';
        }
        if(p->exist) {
            cout << 'P' << '\n';
            return;
        } 
    }
    void dfs() {
        dfs(0, root);
    }
} t;
void solve() {
    cin >> n;
    string s;
    for(int i = 1; i <= n; ++i) {
        cin >> s;
        t.add(s);   
        if((int)s.size() > (int)del.size()) {
            del = s;
        }
    }
    cout << t.total_nodes * 2 + n - (int)del.size() << '\n';    
    t.dfs();
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 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 0 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 452 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 2 ms 1884 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5980 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 14424 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 36180 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 28252 KB printed invalid word
2 Halted 0 ms 0 KB -