# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201737 | mdn2002 | Savez (COCI15_savez) | C++14 | 1091 ms | 23580 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>
using namespace std;
const int mod=1e9+7;
vector<string>s;
map<string,vector<int> >mp;
map<string,int>dp,on;
int n;
int f(int x)
{
if(on[s[x]]!=0)return dp[s[x]];
int ans=0;
for(int i=0;i<mp[s[x]].size();i++)
{
int to=mp[s[x]][i];
if(x>=to)continue;
ans=max(ans,f(to)+1);
}
on[s[x]]++;
return dp[s[x]]=ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("empty.in","r",stdin);
//freopen("empty.out","w",stdout);
cin>>n;
for(int k=0;k<n;k++)
{
string st,pr,sf;
cin>>st;
for(int i=0,j=st.size()-1;i<st.size();i++,j--)
{
pr.push_back(st[i]);
sf.push_back(st[j]);
if(pr==sf)mp[pr].push_back(k);
}
s.push_back(st);
}
int ans=0;
for(int i=0;i<n;i++)ans=max(ans,f(i)+1);
cout<<ans;
}
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... |