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>
using namespace std;
const int N = 505, M = 2e6 + 5, MOD1 = 1e9 + 1337, MOD2 = 999888777;
int n, p1[M], p2[M], ans, h1[M], h2[M];
map < pair < int, int >, int > dp;
string s;
inline pair < int, int > get(int l, int r){
return make_pair(
1LL * (h1[r] - h1[l - 1] + MOD1) % MOD1 * p1[M - r] % MOD1,
1LL * (h2[r] - h2[l - 1] + MOD2) % MOD2 * p2[M - r] % MOD2
);
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
p1[0] = p2[0] = 1;
for(int i = 1; i < M; i++){
p1[i] = 1LL * p1[i - 1] * 59 % MOD1;
p2[i] = 1LL * p2[i - 1] * 45 % MOD2;
}
cin >> n;
for(int i = 1; i <= n; i++){
cin >> s;
int sz = (int)s.size();
for(int j = 1; j <= sz; j++){
h1[j] = (h1[j - 1] + 1LL * s[j - 1] * p1[j]) % MOD1;
h2[j] = (h2[j - 1] + 1LL * s[j - 1] * p2[j]) % MOD2;
}
int mx = 0;
for(int j = 1; j <= sz; j++){
auto it1 = get(1, j),
it2 = get(sz - j + 1, sz);
if(it1 == it2 && dp.find(it1) != dp.end()){
mx = max(mx, dp[it1]);
}
}
dp[get(1, sz)] = mx + 1;
ans = max(ans, mx + 1);
}
cout << ans;
}
Compilation message (stderr)
savez.cpp:19:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |