#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
int lets[1000000][26] = {}, inds[1000000] = {}, par[1000000], dp[500000] = {}, winds[500000], sz = 1, ind, ans = 0;
vector<string> strs;
string s;
void add(int c, int i){
if (i == s.length()){
inds[c] = ind+1; winds[ind] = c;
return;
}
int l = int(s[s.length()-i-1])-97;
if (lets[c][l] == 0){
lets[c][l] = sz; par[sz] = c, sz++;
}
add(lets[c][l], i+1);
}
bool comp(string a, string b){
if (a.length() == b.length()){
return a < b;
}
return a.length() < b.length();
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
for (int i = 0; i < n; i++){
string s; cin >> s;
strs.push_back(s);
}
sort(strs.begin(), strs.end(), comp);
for (int i = 0; i < n; i++){
s = strs[i]; ind = i;
add(0, 0);
}
dp[0] = 1;
for (int i = 1; i < n; i++){
int pi = par[winds[i]], fr = -1;
dp[i] = 1;
if (inds[pi] > 0){
fr = inds[pi]-1;
}
for (int j = 0; lets[pi][j] != winds[i]; j++){
if (inds[lets[pi][j]] > 0){
fr = inds[lets[pi][j]]-1;
}
}
if (fr > -1){
dp[i] += dp[fr];
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
Compilation message
rima.cpp: In function 'void add(int, int)':
rima.cpp:19:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if (i == s.length()){
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
618 ms |
89936 KB |
Output isn't correct |
5 |
Correct |
35 ms |
6520 KB |
Output is correct |
6 |
Incorrect |
34 ms |
34024 KB |
Output isn't correct |
7 |
Incorrect |
32 ms |
33776 KB |
Output isn't correct |
8 |
Incorrect |
30 ms |
33464 KB |
Output isn't correct |
9 |
Incorrect |
101 ms |
41032 KB |
Output isn't correct |
10 |
Incorrect |
29 ms |
33620 KB |
Output isn't correct |