#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
ios::sync_with_stdio(0);
cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
map<int,vector<string>> mp;
for (int i=0;i<n;i++)
{
string s;
cin>>s;
mp[s.size()].push_back(s);
}
vector<string> v;
for (auto i:mp)
for (auto j:i.second)
v.push_back(j);
reverse(v.begin(),v.end());
unordered_map<string,int> ans;
unordered_set<string> se;
ans.reserve(500369);
se.reserve(500369);
for (auto s:v)
se.insert(s);
while (!v.empty())
{
string s=v.back();
v.pop_back();
int mx=0,m=s.size();
string s1=s.substr(1,m-1);
if (ans.find(s1)!=ans.end())
mx=ans[s1];
s1='0'+s1;
for (int c='a';c<='z';c++)
{
s1[0]=c;
if (se.find(s1)!=se.end())
mx++;
}
ans[s]=mx;
}
int res=0;
for (auto i:ans)
res=max(res,i.second);
cout<<res<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8536 KB |
Output is correct |
2 |
Correct |
5 ms |
8428 KB |
Output is correct |
3 |
Correct |
3 ms |
8540 KB |
Output is correct |
4 |
Execution timed out |
1089 ms |
92248 KB |
Time limit exceeded |
5 |
Correct |
35 ms |
17792 KB |
Output is correct |
6 |
Incorrect |
12 ms |
11720 KB |
Output isn't correct |
7 |
Incorrect |
11 ms |
11236 KB |
Output isn't correct |
8 |
Incorrect |
9 ms |
10644 KB |
Output isn't correct |
9 |
Incorrect |
57 ms |
21896 KB |
Output isn't correct |
10 |
Incorrect |
10 ms |
10808 KB |
Output isn't correct |