# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96807 | tieunhi | Rima (COCI17_rima) | C++14 | 1216 ms | 263168 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 add(string s)
{
int p = 1;
FOR(i, 0, s.size()-1)
{
int c = s[i] - 'a';
if (t[p].child[c] == 0) t[p].child[c] = ++tt;
p = t[p].child[c];
}
t[p].cnt++;
}
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);
//freopen("INP.TXT", "r", stdin);
//freopen("OUT.TXT", "w", stdout);
cin >> n;
FOR(i, 1, n)
{
string s; cin >> s;
reverse(s.begin(), s.end());
add(s);
}
DFS(1);
cout <<*max_element(dp+1, dp+tt+1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |