Submission #957381

# Submission time Handle Problem Language Result Execution time Memory
957381 2024-04-03T15:20:59 Z bmh123456789asdf Type Printer (IOI08_printer) C++14
20 / 100
15 ms 16984 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 25010;
int child[N][26], dp[N], depth[N], id[N], par[N], stop[N];
vector<pair<int,char>> adj[N];
vector<char> ans;
int cnt = 0, n, Node;
string s[N];


void insertword(string word,int num)
{
    int node = 0, cur = 0;
    for(auto k : word)
    {
        if(child[node][k - 'a'] == 0)
        {
            child[node][k - 'a'] = ++cnt;
            adj[node].push_back({cnt, k});
            par[cnt] = node;
        }
        node = child[node][k - 'a'];
    }
    stop[node]++;
    while(node != 0) depth[par[node]] = max(depth[par[node]], depth[node] + 1), node = par[node];
}

bool mmb(pair<int,char> a,pair<int,char> b)
{
    return depth[a.first] < depth[b.first];
}

void DFS(int u)
{
    for(auto v : adj[u])
    {
        while(Node != u) Node = par[Node], ans.push_back('-');
        Node = child[Node][v.second - 'a'];
        ans.push_back(v.second);
        DFS(v.first);
    }
    if(stop[u])ans.push_back('P');
}

int32_t main()
{
//    freopen("test.inp", "r" ,stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    for(int i = 1; i <= n; i++)
    {
        cin >> s[i];
        insertword(s[i], i);
    }
    vector<pair<int,char>> v;
    for(int i = 0; i <= cnt; i++)
        sort(adj[i].begin(), adj[i].end(), mmb);
    DFS(0);
    cout << ans.size() <<'\n';
    for(auto k : ans) cout << k<<'\n';
}

Compilation message

printer.cpp: In function 'void insertword(std::string, long long int)':
printer.cpp:14:19: warning: unused variable 'cur' [-Wunused-variable]
   14 |     int node = 0, cur = 0;
      |                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 1 ms 2648 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2652 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4188 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 8536 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 16984 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 16984 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 16732 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -