| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1279274 | swishy123 | Type Printer (IOI08_printer) | C++20 | 647 ms | 59216 KiB | 
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define x first
#define y second
const int inf = 2e9;
const int def = 1e5+1;
using namespace std;
struct node{
    int p[26];
    int max_len;
    bool end;
    node(){
        end = false;
        max_len = -1;
        for (int i = 0; i < 26; i++)
            p[i] = -1;
    }
};  
vector<node> nodes;
void add(int u, int i, string &s){
    if (i == s.size()){
        nodes[u].end = 1;
        nodes[u].max_len = max(nodes[u].max_len, (int)s.size());
        return;
    }
    int val = s[i] - 'a';
    if (nodes[u].p[val] == -1){
        nodes[u].p[val] = nodes.size();
        nodes.push_back(node());
    }
    add(nodes[u].p[val], i + 1, s);
    nodes[u].max_len = max(nodes[u].max_len, nodes[nodes[u].p[val]].max_len);
}
vector<char> res;
void go(int u){
    if (nodes[u].end){
        res.push_back('P');
    }
    vector<tuple<int, int, char>> order;
    for (int i = 0; i < 26; i++){
        int v = nodes[u].p[i];
        if (v != -1)
            order.push_back({nodes[v].max_len, v, (char)('a' + i)});
    }
    sort(order.begin(), order.end());
    for (int i = 0; i < order.size(); i++){
        auto [len, v, c] = order[i];
        if (v != -1){
            res.push_back(c);
            go(v);
            res.push_back('-');
        }
    }
}
void solve(){
    int n;
    cin >> n;
    nodes.push_back(node());
    vector<string> s(n);
    for (int i = 0; i < n; i++){
        cin >> s[i];
        add(0, 0, s[i]);
    }
    go(0);
    while (res.back() == '-')
        res.pop_back();
    cout << res.size() << endl;
    for (int i = 0; i < res.size(); i++){
        cout << res[i];
        if (i + 1 < res.size())
            cout << endl;
    }
}   
/*
-1 3 -1 1 0 -1
11 3 0 1 0 0
1 0 3 2
0 1 3 2 
*/
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (ifstream("input.txt").good()){
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout); 
    }
    int t;
    t = 1;
    
    while (t--){
        solve();
    }
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
