# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
182413 | XmtosX | Rima (COCI17_rima) | C++17 | 1088 ms | 159476 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[500004];
vector <int> v[500004];
unordered_map<string, int> r;
bool vis[500004],fin[500004];
int dfs (int x)
{
vis[x]=true;
fin[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=1;i<=n;i++)
{
cin >>s[i];
reverse(s[i].begin(),s[i].end());
r[s[i]]=i;
}
for (int i=1;i<=n;i++)
{
for (int j='a';j<='z';j++)
{
s[i]+=j;
if (r[s[i]])
{
v[i].push_back(r[s[i]]);
v[r[s[i]]].push_back(i);
}
s[i].pop_back();
}
char c= s[i].back();
s[i].pop_back();
for (int j='a';j<='z';j++)
{
s[i]+=j;
if (r[s[i]])
{
v[i].push_back(r[s[i]]);
}
s[i].pop_back();
}
s[i]+=c;
}
for (int i=1;i<=n;i++)
{
if (!fin[i])
ans=max(ans,dfs(i)+1);
}
cout <<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |