Submission #1003408

# Submission time Handle Problem Language Result Execution time Memory
1003408 2024-06-20T09:55:10 Z fryingduc Type Printer (IOI08_printer) C++17
10 / 100
34 ms 36284 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) {
        if(p->exist) {
            cout << 'P' << '\n';
        } 
        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';
        }
    }
    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 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# 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 1 ms 344 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 456 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1892 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 13 ms 14428 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 36284 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 28356 KB printed invalid word
2 Halted 0 ms 0 KB -