# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1028105 |
2024-07-19T13:43:21 Z |
earlyamazon |
Savez (COCI15_savez) |
C++14 |
|
111 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mn = 2e6+7;
const int mod1 = 1e9+7;
const int mod2 = 1e9+9;
const int p1 = 269;
const int p2 = 271;
int n,wyn;
map<pair<int, int>, int> dp;
pair<int,int> pot[mn];
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
pot[0] = {1,1};
for (int i = 1; i < mn; i++){
pot[i] = {pot[i-1].first*p1%mod1, pot[i-1].second*p2%mod2};
}
string s;
vector<pair<int,int>> hpref;
for (int i = 0; i < n; i++){
cin>>s;
hpref.push_back({0, 0});
for (int j = 1; j <= (int)s.size(); j++){
hpref.push_back({(hpref.back().first*p1+s[j-1])%mod1, (hpref.back().second*p2+s[j-1])%mod2});
}
int mx = 0;
for (int j = 1; j <= (int)s.size(); j++){
pair<int,int> h = hpref[j];
if (h == make_pair((hpref[s.size()].first-((hpref[s.size()-j].first*pot[j].first)%mod1)+mod1)%mod1, (hpref[s.size()].second-((hpref[s.size()-j].second*pot[j].second)%mod2)+mod2)%mod2)){
mx = max(mx, dp[h]);
}
}
mx++;
wyn = max(wyn, mx);
dp[hpref.back()] = mx;
// cout<<hpref.size()<<" "<<hpref.back().first<<" "<<hpref.back().second<<" "<<mx<<"\n";
}
cout<<wyn<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31580 KB |
Output is correct |
2 |
Incorrect |
27 ms |
31576 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
31744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
49072 KB |
Output is correct |
2 |
Correct |
111 ms |
49092 KB |
Output is correct |
3 |
Incorrect |
54 ms |
49080 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
34004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
48840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
48836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
48880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
65536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
65536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
65536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |