Submission #1000106

# Submission time Handle Problem Language Result Execution time Memory
1000106 2024-06-16T16:43:21 Z vjudge1 Type Printer (IOI08_printer) C++17
10 / 100
338 ms 109136 KB
#include "bits/stdc++.h"

using namespace std;

#define int long long 

const int sz = 2e5 + 5;
const int inf = 1e18;

int trie[32 * sz][26];
int depth[32 * sz];
int leaf[32 * sz];
int nxt = 0, cnt = 0;
char ch[sz];
vector<int> adj[sz];
vector<char> res;
int n;

struct Trie
{
    void add(string s) 
    {
        int root = 0;
        for(char c : s) 
        {
            int child = c - 'a';
            if (!trie[root][child]) 
            {
                trie[root][child] = ++nxt;
                adj[root].push_back(trie[root][child]);
                ch[trie[root][child]] = c;
            }
            root = trie[root][child];
            depth[root] = max(depth[root], (int)s.size() - (&c - &s.front()));
        }
        leaf[root] = true;
    }
    void dfs(int node) 
    {
        if (node) res.push_back(ch[node]);
        if (leaf[node]) res.push_back('P'), cnt++;
        for(int to : adj[node]) dfs(to);
        if (cnt != n) res.push_back('-');
    }
};

void solve() 
{
    cin >> n;
    Trie tree;
    for(int i = 1; i <= n; i++) 
    {
        string s;
        cin >> s;
        tree.add(s);
    }
    for(int i = 0; i <= nxt; i++) sort(adj[i].begin(), adj[i].end(), [&](int a, int b)
    {
        return depth[a] < depth[b];
    });
    tree.dfs(0);
    cout << res.size() << endl;
    for(char c : res) cout << c << endl;
}

signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Incorrect 9 ms 7708 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 8284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 12888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 145 ms 22476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 338 ms 46288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 278 ms 37240 KB Output is correct
2 Runtime error 74 ms 109136 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -