답안 #96810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96810 2019-02-12T08:33:20 Z tieunhi Rima (COCI17_rima) C++14
0 / 140
665 ms 263168 KB
#include <bits/stdc++.h>
#define FOR(i, u, v) for (int i = u; i <= v; i++)
#define FORD(i, v, u) for (int i = v; i >= u; i--)
#define ll long long
#define pii pair<int, int>
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define N 3000005
#define BASE 37
#define mod 1000000007
#define mid (r + l)/2

using namespace std;

int n, dp[N];

struct node
{
    int child[26], cnt;
    node()
    {
        FOR(i, 0, 25) child[i] = 0;
        cnt = 0;
    }
}t[N];
int tt = 1;

void DFS(int u)
{
    int cnt1 = 0, vmax = 0;
    FOR(c, 0, 25)
    {
        if (t[u].child[c] == 0) continue;

        int v = t[u].child[c];
        DFS(v);

        if (t[v].cnt == 0) continue;
        else if (t[v].cnt == 1)
        {
            cnt1++;
            vmax = max(vmax, dp[v]);
        }
        else dp[u] += (dp[v] + t[v].cnt);
    }
    dp[u] += (cnt1 + vmax);
}
int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    //freopen("INP.TXT", "r", stdin);
    //freopen("OUT.TXT", "w", stdout);
    cin >> n;
    FOR(i, 1, n)
    {
        string s; cin >> s;
        int p = 1;
    	FORD(i, s.size()-1, 0)
    	{
        	int c = s[i] - 'a';
        	if (t[p].child[c] == 0) t[p].child[c] = ++tt;
        	p = t[p].child[c];
    	}
    	t[p].cnt++;
    }
    DFS(1);
    cout <<*max_element(dp+1, dp+tt+1);
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 665 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 332 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 276 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 208 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 207 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 197 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 192 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 193 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 222 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 214 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)