#include <bits/stdc++.h>
#define MAXN 500010
#define pb push_back
#define inf 0x3f3f3f3f
using namespace std;
int n, dp[MAXN];
vector < string > vet;
inline bool cmp(string a, string b)
{
if(a.size() > b.size()) return true;
else if(a.size() < b.size()) return false;
return a < b;
}
inline int func(int i)
{
if(i == n-1) return 1;
if(dp[i] != -1) return dp[i];
string eu = vet[i];
eu.pop_back();
int r = 1;
if(vet[i+1].size() == eu.size())
{
if(vet[i+1] == eu) r = func(i+1) + 1;
}
else if(vet[i+1].size() - 1 == eu.size())
{
string k = vet[i+1];
k.pop_back();
if(k == eu) r = func(i+1) + 1;
}
return dp[i] = r;
}
int main()
{
cin >> n;
memset(dp, -1, sizeof dp);
for(int i = 0 ; i < n ; i++)
{
string s;
cin >> s;
reverse(s.begin(), s.end());
vet.pb(s);
}
sort(vet.begin(), vet.end(), cmp);
int resp = 0;
for(int i = 0 ; i < n ; i++)
{
resp = max(resp, func(i));
// cout << i << ' ' << resp << endl;
}
cout << resp << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2304 KB |
Output is correct |
2 |
Correct |
4 ms |
2304 KB |
Output is correct |
3 |
Incorrect |
4 ms |
2304 KB |
Output isn't correct |
4 |
Incorrect |
548 ms |
18896 KB |
Output isn't correct |
5 |
Correct |
97 ms |
5988 KB |
Output is correct |
6 |
Incorrect |
28 ms |
3316 KB |
Output isn't correct |
7 |
Incorrect |
25 ms |
3180 KB |
Output isn't correct |
8 |
Incorrect |
20 ms |
3188 KB |
Output isn't correct |
9 |
Incorrect |
156 ms |
6348 KB |
Output isn't correct |
10 |
Incorrect |
25 ms |
3228 KB |
Output isn't correct |