# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
269734 | mayhoubsaleh | Savez (COCI15_savez) | C++14 | 134 ms | 33644 KiB |
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 ll long long
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll maxn=1e5+100;
const ll inf=1e9+10;
const ll mod=1e9+7;
const ll base=27;
ll n;vector<string>s;
unordered_map<ll,ll>dp;
ll ans;
int main()
{
IOS
cin>>n;
s.resize(n);
for(ll i=0;i<n;i++)cin>>s[i];
for(ll i=0;i<n;i++){
ll curans=1;
ll pre=0,suf=0,b=1;
for(ll l=0,r=s[i].size()-1;l<s[i].size();l++,r--){
pre=pre*base%mod;
pre=(pre+(s[i][l]-'A'+1))%mod;
suf=(suf+(s[i][r]-'A'+1)*b%mod)%mod;
b=b*base%mod;
if(pre==suf){
curans=max(curans,dp[pre]+1);
}
}
dp[pre]=max(dp[pre],curans);
ans=max(ans,curans);
}
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
# | 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... |