#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const int inf = 1e9 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int n;
string s[maxn];
int dp[maxn];
const ll mod = 1e9 + 9;
ll add(ll a, ll b){
return (a + b) % mod;
}
ll sub(ll a, ll b){
return (a - b + mod) % mod;
}
ll mul(ll a, ll b){
return (a * b) % mod;
}
ll power(ll a, ll b){
if(!b)return 1;
ll pola = power(a, b / 2);
pola = mul(pola, pola);
if(b % 2)pola = mul(pola, a);
return pola;
}
ll inv(ll a){
return power(a, mod - 2);
}
const int p = 67;
ll pw[maxn];
ll invz[maxn];
ll hsh[maxn];
ll get(int l, int r){
if(l == r)return 1;
if(l > r)return 0;
return mul(sub(hsh[r], hsh[l - 1]), invz[l - 1]);
}
map<ll,int> kol;
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n;
ff(i,1,n)cin >> s[i];
pw[0] = 1;
ff(i,1,maxn - 1)pw[i] = mul(pw[i - 1], p);
invz[0] = 1;
ff(i,1,maxn - 1)invz[i] = mul(invz[i - 1], inv(p));
ff(i,1,n){
// ja bi trebao da hasujem i u nekoj mapi da cuvaj za vrednost hasha max dp do njega
int len = sz(s[i]);
s[i] = ' ' + s[i];
ff(j,1,len)hsh[j] = add(hsh[j - 1], mul(pw[j - 1], (s[i][j] - 'A' + 1)));
dp[i] = 1;
ff(j,1,len){
ll a = hsh[j];
ll b = get(len - j + 1, len);
if(a == b)dp[i] = max(dp[i], kol[a] + 1);
}
kol[hsh[len]] = max(kol[hsh[len]], dp[i]);
}
int rez = 0;
ff(i,1,n)rez = max(rez, dp[i]);
cout << rez << endl;
return 0;
}
/**
5
A
B
AA
BBB
AAA
// probati bojenje sahovski ili slicno
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
5100 KB |
Output is correct |
2 |
Correct |
31 ms |
5100 KB |
Output is correct |
3 |
Correct |
31 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
5100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
7404 KB |
Output is correct |
2 |
Correct |
116 ms |
7276 KB |
Output is correct |
3 |
Correct |
118 ms |
7276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
5228 KB |
Output is correct |
2 |
Correct |
62 ms |
7148 KB |
Output is correct |
3 |
Correct |
86 ms |
7404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
7148 KB |
Output is correct |
2 |
Correct |
52 ms |
7276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
7404 KB |
Output is correct |
2 |
Correct |
52 ms |
7404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7916 KB |
Output is correct |
2 |
Correct |
55 ms |
7916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
7916 KB |
Output is correct |
2 |
Correct |
58 ms |
7916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
7404 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
7352 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |