# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
252711 |
2020-07-26T07:18:01 Z |
VEGAnn |
Savez (COCI15_savez) |
C++14 |
|
100 ms |
10104 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define PB push_back
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const int N = 2000100;
const int md = 998244353;
const int PW = 233;
gp_hash_table<int, int> mem;
string s;
int n, suf[N], po[N], ans;
int mult(int x, int y) { return (1ll * x * y) % md; }
int sub(int x, int y){
x -= y;
if (x < 0)
x += md;
return x;
}
int sum(int x, int y){
x += y;
if (x >= md)
x -= md;
return x;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n;
po[0] = 1;
for (int i = 1; i < N; i++)
po[i] = mult(po[i - 1], PW);
for (int i = 0; i < n; i++){
cin >> s;
int len = sz(s);
suf[len] = 0;
for (int i = len - 1; i >= 0; i--)
suf[i] = sum((s[i] - 'A') + 1, mult(PW, suf[i + 1]));
int res = 1;
for (int l = 1; l <= len; l++){
int pf = sub(suf[0], mult(suf[l], po[l]));
int sf = suf[len - l];
if (pf != sf) continue;
if (mem.find(pf) == mem.end()) continue;
res = max(res, 1 + mem[pf]);
}
ans = max(ans, res);
mem[suf[0]] = max(mem[suf[0]], res);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8192 KB |
Output is correct |
2 |
Correct |
15 ms |
8192 KB |
Output is correct |
3 |
Correct |
15 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8192 KB |
Output is correct |
2 |
Correct |
15 ms |
8192 KB |
Output is correct |
3 |
Correct |
18 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
9080 KB |
Output is correct |
2 |
Correct |
32 ms |
9216 KB |
Output is correct |
3 |
Correct |
37 ms |
9208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
8192 KB |
Output is correct |
2 |
Correct |
31 ms |
9216 KB |
Output is correct |
3 |
Correct |
32 ms |
9216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
9208 KB |
Output is correct |
2 |
Correct |
30 ms |
9240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
9208 KB |
Output is correct |
2 |
Correct |
32 ms |
9216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
9208 KB |
Output is correct |
2 |
Correct |
33 ms |
9208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
9208 KB |
Output is correct |
2 |
Correct |
34 ms |
9208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
9340 KB |
Output is correct |
2 |
Correct |
52 ms |
9336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
9592 KB |
Output is correct |
2 |
Correct |
58 ms |
9592 KB |
Output is correct |
3 |
Correct |
100 ms |
10104 KB |
Output is correct |