# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100844 |
2019-03-14T21:04:28 Z |
dalgerok |
Savez (COCI15_savez) |
C++17 |
|
100 ms |
63396 KB |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 505, M = 2e6 + 5, MOD1 = 1e9 + 1337, MOD2 = 999888777;
int n, p1[M], p2[M], ans, h1[M], h2[M];
map < pair < int, int >, int > dp;
string s[N];
inline pair < int, int > get(int l, int r){
return make_pair(
(h1[r] - h1[l - 1] + MOD1) % MOD1 * p1[M - r] % MOD1,
(h2[r] - h2[l - 1] + MOD2) % MOD2 * p2[M - r] % MOD2
);
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
p1[0] = p2[0] = 1;
for(int i = 1; i < M; i++){
p1[i] = p1[i - 1] * 59 % MOD1;
p2[i] = p2[i - 1] * 45 % MOD2;
}
cin >> n;
for(int i = 1; i <= n; i++){
cin >> s[i];
int sz = (int)s[i].size();
for(int j = 1; j <= sz; j++){
h1[j] = (h1[j - 1] + s[i][j - 1] * p1[j]) % MOD1;
h2[j] = (h2[j - 1] + s[i][j - 1] * p2[j]) % MOD2;
}
int mx = 0;
for(int j = 1; j <= sz; j++){
auto it1 = get(1, j),
it2 = get(sz - j + 1, sz);
if(it1 == it2 && dp.find(it1) != dp.end()){
mx = max(mx, dp[it1]);
}
}
dp[get(1, sz)] = mx + 1;
ans = max(ans, mx + 1);
}
cout << ans;
}
Compilation message
savez.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
31620 KB |
Output is correct |
2 |
Correct |
34 ms |
31608 KB |
Output is correct |
3 |
Correct |
33 ms |
31744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
31736 KB |
Output is correct |
2 |
Correct |
35 ms |
31608 KB |
Output is correct |
3 |
Correct |
36 ms |
31736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
32760 KB |
Output is correct |
2 |
Correct |
63 ms |
32760 KB |
Output is correct |
3 |
Correct |
100 ms |
32764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
31796 KB |
Output is correct |
2 |
Correct |
64 ms |
32888 KB |
Output is correct |
3 |
Correct |
85 ms |
32888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
75 ms |
63396 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
80 ms |
63244 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
73 ms |
63164 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
77 ms |
63324 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
79 ms |
63256 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
73 ms |
63284 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |