#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;
const int N = int(2e6) + 10;
const ll base = int(1e9) + 7;
ll n, power[N], pf[N], ans;
map <ll, ll> dp;
ll sum(ll x, ll y) { return (x + y) % base; }
ll mul(ll x, ll y) { return (x * y) % base; }
ll dec(ll x, ll y) { x -= y; while (x < 0) x += base; return x; }
int main() {
fast_io;
cin >> n;
power[0] = 1;
for (int i = 1; i <= int(2e6); ++i)
power[i] = mul(power[i - 1], 29ll);
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
int m = int(s.size());
for (int j = 0; j < m; ++j)
pf[j] = sum((j - 1 < 0 ? 0 : pf[j - 1]), mul((s[j] - 'A' + 1), power[j]));
for (int j = 1; j <= m; ++j) {
ll pref = mul(pf[j - 1], power[m - j]);
ll suff = dec(pf[m - 1], (m - 1 - j < 0 ? 0 : pf[m - 1 - j]));
//cerr << s << " " << pref << " " << suff << " " << pf[j - 1] << "\n";
if (pref != suff || dp.find(pf[j - 1]) == dp.end())
continue;
++dp[pf[j - 1]];
ans = max(ans, dp[pf[j - 1]]);
}
dp[pf[m - 1]] = max(dp[pf[m - 1]], 1ll);
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
16000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
15992 KB |
Output is correct |
2 |
Correct |
18 ms |
15992 KB |
Output is correct |
3 |
Incorrect |
20 ms |
16052 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
17144 KB |
Output is correct |
2 |
Incorrect |
42 ms |
17016 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
16128 KB |
Output is correct |
2 |
Correct |
49 ms |
17016 KB |
Output is correct |
3 |
Incorrect |
60 ms |
17008 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
17016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
17016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
17016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
17016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
17180 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
17400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |