# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
182409 | XmtosX | Rima (COCI17_rima) | C++17 | 5 ms | 504 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;
int n,ans;
string s[20];
vector <int> v[20];
bool vis[20];
bool check (string s1,string s2)
{
int x=max(s1.size(),s2.size())-1;
return s1.substr(0,x)==s2.substr(0,x);
}
int dfs (int x)
{
vis[x]=true;
int maxx=0;
for (int i=0;i<v[x].size();i++)
{
if (!vis[v[x][i]])
maxx=max(maxx,dfs(v[x][i])+1);
}
vis[x]=false;
return maxx;
}
int main()
{
cin >>n;
for (int i=0;i<n;i++)
{
cin >>s[i];
reverse(s[i].begin(),s[i].end());
}
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
if (check(s[i],s[j]))
{
v[i].push_back(j);
v[j].push_back(i);
}
}
}
for (int i=0;i<n;i++)
ans=max(ans,dfs(i)+1);
cout <<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |