Submission #840283

# Submission time Handle Problem Language Result Execution time Memory
840283 2023-08-31T09:25:26 Z EntityPlantt Type Printer (IOI08_printer) C++17
40 / 100
86 ms 77576 KB
#include <iostream>
#include <algorithm>
using namespace std;
struct TrieNode {
    int mxdepth = 1;
    bool word = false;
    TrieNode *children[26] = {};
};
TrieNode tnderef[200000];
int n, tnderefcnt = 1;
string s, pr;
TrieNode *root = tnderef, *now;
void calcmxdepth(TrieNode *node) {
    for (int i = 0; i < 26; i++) {
        if (!node->children[i]) continue;
        calcmxdepth(node->children[i]);
        if (node->children[i]->mxdepth >= node->mxdepth) {
            node->mxdepth = node->children[i]->mxdepth + 1;
        }
    }
}
void print(TrieNode *node) {
    if (node->word) pr += 'P';
    int arr[26] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
    sort(arr, arr + 26, [&](int a, int b) {
        if (!node->children[a]) return false;
        if (!node->children[b]) return true;
        return node->children[a]->mxdepth < node->children[b]->mxdepth;
    });
    for (int i = 0; node->children[arr[i]]; i++) {
        pr += arr[i] + 'a';
        print(node->children[arr[i]]);
        pr += '-';
    }
}
int main() {
    ios::sync_with_stdio();
    cin.tie(0); cout.tie(0);
    cin >> n;
    while (n--) {
        cin >> s;
        now = root;
        for (char &x : s) {
            if (!now->children[x - 'a']) {
                now->children[x - 'a'] = tnderef + tnderefcnt++;
            }
            now = now->children[x - 'a'];
        }
        now->word = true;
    }
    calcmxdepth(root);
    print(root);
    while (pr.back() == '-') pr.pop_back();
    cout << pr.size() << '\n';
    for (char &ch : pr) cout << ch << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 35 ms 44120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 44 ms 45388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 49108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 57284 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 77576 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 67 ms 70092 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -