# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
96813 |
2019-02-12T08:43:23 Z |
tieunhi |
Rima (COCI17_rima) |
C++14 |
|
444 ms |
134776 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], res;
struct Trie
{
Trie *child[26];
int cnt, dp;
Trie()
{
FOR(i, 0, 25) child[i] = NULL;
cnt = 0, dp = 0;
}
}t;
void DFS(Trie *u)
{
int cnt1 = 0, vmax = 0, val = 0;
FOR(c, 0, 25)
{
if (u->child[c] == NULL) continue;
Trie *v = u->child[c];
DFS(v);
if (v->cnt == 0) val = max(val, v->dp);
else if (v->cnt == 1)
{
cnt1++;
vmax = max(vmax, v->dp);
}
else u->dp += (v->dp + v->cnt);
}
u->dp += (cnt1 + vmax);
u->dp = max(u->dp, val);
res = max(res, u->dp);
}
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;
Trie *p = &t;
FORD(i, s.size()-1, 0)
{
int c = s[i] - 'a';
if (p->child[c] == NULL) p->child[c] = new Trie();
p = p->child[c];
}
p->cnt++;
}
DFS(&t);
cout <<res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Incorrect |
444 ms |
134776 KB |
Output isn't correct |
5 |
Incorrect |
35 ms |
1016 KB |
Output isn't correct |
6 |
Incorrect |
99 ms |
90208 KB |
Output isn't correct |
7 |
Incorrect |
108 ms |
90084 KB |
Output isn't correct |
8 |
Incorrect |
102 ms |
89884 KB |
Output isn't correct |
9 |
Incorrect |
135 ms |
93160 KB |
Output isn't correct |
10 |
Incorrect |
103 ms |
90072 KB |
Output isn't correct |