#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int n;
#define MAX 3000005
#define All(x...) (x).begin(), (x).end()
int dp[MAX];
struct Node{
Node* child[26];
int last, ID;
Node(){
REP(i, 26) child[i] = nullptr;
last = 0, ID = 0;
}
};
int numNode = 0;
Node *root = new Node();
void Add(string &s){
Node *p = root;
for (char c : s){
int nxt = (c - 'a');
if (p -> child[nxt] == nullptr){
p -> child[nxt] = new Node();
p -> child[nxt] -> ID = ++numNode;
}
p = p -> child[nxt];
}
p -> last++;
}
int ans = 0;
void dfs(Node *p){
REP(c, 26) if(p -> child[c] != nullptr){
dfs(p -> child[c]);
}
if (p -> last){
dp[p -> ID] = (p -> last);
REP(c, 26) if(p -> child[c] != nullptr){
dp[p -> ID] += dp[p -> child[c] -> ID];
}
maximize(ans, dp[p -> ID]);
}
}
void process(void){
cin >> n;
vector<string> s(n);
for (string&i : s) cin >> i;
for (string&i : s) reverse(All(i)), Add(i);
dfs(root);
cout << ans;
}
signed main(){
#define name "Whisper"
cin.tie(nullptr) -> sync_with_stdio(false);
// freopen(name".inp", "r", stdin);
// freopen(name".out", "w", stdout);
process();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
251 ms |
168952 KB |
Output isn't correct |
5 |
Correct |
13 ms |
7000 KB |
Output is correct |
6 |
Incorrect |
55 ms |
89068 KB |
Output isn't correct |
7 |
Incorrect |
57 ms |
88432 KB |
Output isn't correct |
8 |
Incorrect |
56 ms |
88100 KB |
Output isn't correct |
9 |
Incorrect |
72 ms |
97260 KB |
Output isn't correct |
10 |
Incorrect |
53 ms |
88288 KB |
Output isn't correct |