Submission #520662

# Submission time Handle Problem Language Result Execution time Memory
520662 2022-01-30T16:29:17 Z HaYoungJoon Rima (COCI17_rima) C++14
56 / 140
694 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

const int maxsize = 3*1e5;
int trie[300001][26], timer = 0;
int dp[300001], n, res = 0;
string a[500001];
vector<int> adj[300001];

void addString(string s) {
    int cur = 0;
    for (char c: s) {
        int val = c - 'a';
        if (!trie[cur][val]) {
            adj[cur].emplace_back(++timer);
            trie[cur][val] = timer;
        }
        cur = trie[cur][val];
    }
    dp[cur] = 1;
}

void DFS(int u) {
    int maxnhanh = 0;
    for (int v: adj[u]) {
        DFS(v);
        maxnhanh = max(maxnhanh,dp[v]);
    }
    res = max(dp[u],res);
    if (dp[u] && maxnhanh) {
        for (int v: adj[u]) dp[u] += (dp[v] > 0);
        dp[u] += maxnhanh - 1;
        res = max(dp[u],res);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        reverse(a[i].begin(),a[i].end());
    }
    for (int i = 1; i <= n; i++) addString(a[i]);
    DFS(0);
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 22988 KB Output is correct
2 Correct 12 ms 23020 KB Output is correct
3 Correct 11 ms 22988 KB Output is correct
4 Runtime error 694 ms 262148 KB Execution killed with signal 9
5 Correct 35 ms 27204 KB Output is correct
6 Runtime error 92 ms 129696 KB Execution killed with signal 11
7 Runtime error 94 ms 129404 KB Execution killed with signal 11
8 Runtime error 107 ms 129300 KB Execution killed with signal 11
9 Runtime error 111 ms 134876 KB Execution killed with signal 11
10 Runtime error 93 ms 129300 KB Execution killed with signal 11