# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
632897 |
2022-08-21T06:08:02 Z |
racsosabe |
Savez (COCI15_savez) |
C++14 |
|
294 ms |
31712 KB |
#include<bits/stdc++.h>
using namespace::std;
const int B[] = {311, 257};
const int MOD = 1e9 + 7;
const int N = 2000000 + 5;
int mul(int a, int b){
return (1ll * a * b) % MOD;
}
int pow_mod(int a, int b){
int r = 1;
while(b){
if(b & 1) r = mul(r, a);
a = mul(a, a);
b >>= 1;
}
return r;
}
int n;
char s[N];
int pot[2][N];
int poti[2][N];
int prefix[2][N];
map<pair<int, int>, int> best;
void init(){
for(int id = 0; id < 2; id++){
pot[id][0] = 1;
for(int i = 1; i < N; i++) pot[id][i] = mul(pot[id][i - 1], B[id]);
poti[id][N - 1] = pow_mod(pot[id][N - 1], MOD - 2);
for(int i = N - 2; i >= 0; i--) poti[id][i] = mul(poti[id][i + 1], B[id]);
}
}
bool check(int l, int len){
for(int id = 0; id < 2; id++){
int L = prefix[id][l];
int R = mul((prefix[id][len] + MOD - prefix[id][len - l]), poti[id][len - l]);
if(L != R) return false;
}
return true;
}
int main(){
init();
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%s", s + 1);
int len = strlen(s + 1);
for(int id = 0; id < 2; id++)
for(int j = 1; j <= len; j++) prefix[id][j] = (prefix[id][j - 1] + mul(pot[id][j], s[j])) % MOD;
for(int l = 1; l <= len; l++){
if(check(l, len)){
int cur = 1 + (best.count(make_pair(prefix[0][l], prefix[1][l])) ? best[make_pair(prefix[0][l], prefix[1][l])] : 0);
best[make_pair(prefix[0][l], prefix[1][l])] = cur;
}
}
}
int ans = 0;
for(auto e : best){
if(ans < e.second) ans = e.second;
}
printf("%d\n", ans);
return 0;
}
Compilation message
savez.cpp: In function 'int main()':
savez.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
savez.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%s", s + 1);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
31564 KB |
Output is correct |
2 |
Incorrect |
52 ms |
31564 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
31600 KB |
Output is correct |
2 |
Correct |
52 ms |
31612 KB |
Output is correct |
3 |
Incorrect |
55 ms |
31564 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
294 ms |
31692 KB |
Output is correct |
2 |
Incorrect |
274 ms |
31672 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
31596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
107 ms |
31604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
94 ms |
31624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
31572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
90 ms |
31712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
31616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
31608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |