답안 #520665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520665 2022-01-30T16:36:36 Z HaYoungJoon Rima (COCI17_rima) C++14
14 / 140
274 ms 160452 KB
#include <bits/stdc++.h>

using namespace std;

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

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]++;
}

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);
    }
    if (maxnhanh) {
        int total = 0;
        for (int v: adj[u]) total += (dp[v] > 0);
        total += maxnhanh - 1;
        res = max(dp[u],total);

    }
}

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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 86376 KB Output isn't correct
2 Incorrect 48 ms 86464 KB Output isn't correct
3 Incorrect 41 ms 86416 KB Output isn't correct
4 Incorrect 274 ms 160452 KB Output isn't correct
5 Correct 64 ms 89848 KB Output is correct
6 Incorrect 89 ms 150652 KB Output isn't correct
7 Incorrect 89 ms 150504 KB Output isn't correct
8 Incorrect 90 ms 150400 KB Output isn't correct
9 Incorrect 109 ms 154668 KB Output isn't correct
10 Incorrect 86 ms 150436 KB Output isn't correct