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 all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const ll mod = 1e9+7;
const ll base = 101;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
vector<int>qnt;
vector<string>v;
ll hsh[2000001], revHsh[2000001];
void computeHash(int idx){
int n = qnt[idx];
hsh[0] = ll(v[idx][0]-'A'+1ll);
for(int i=1;i<n;++i){
hsh[i] = hsh[i-1]*base+ll(v[idx][i]-'A'+1ll);
hsh[i] %= mod;
}
revHsh[0] = ll(v[idx][n-1]-'A'+1ll);
ll act = 1ll;
for(int i=n-2;i>=0;--i){
act = (act*base)%mod;
revHsh[n-1-i] = revHsh[n-2-i]+act*ll(v[idx][i]-'A'+1ll);
revHsh[n-1-i] %= mod;
}
}
unordered_map<int,int>dp;
int main(){_
int n;cin>>n;
v.resize(n), qnt.resize(n);
for(int i=0;i<n;++i){
cin>>v[i];
qnt[i] = sz(v[i]);
}
int best = 0;
for(int i=0;i<n;++i){
int idx = i;
computeHash(idx);
int m = qnt[idx], res = 0;
for(int j=0;j<m;++j)if(hsh[j]==revHsh[j])ckmax(res,dp[int(hsh[j])]);
++res;
if(hsh[m-1]==revHsh[m-1])ckmax(dp[int(hsh[m-1])], res);
ckmax(best, res);
}
cout<<best<<endl;
}
# | 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... |