# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100842 |
2019-03-14T20:57:52 Z |
dalgerok |
Savez (COCI15_savez) |
C++17 |
|
172 ms |
65528 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], dp[N], a[N], ans;
vector < int > h1[N], h2[N];
bool used[N];
vector < int > g[N];
string s[N];
map < pair < int, int >, int > ss;
map < pair < int, int >, vector < int > > q;
inline pair < int, int > get(int i, int l, int r){
return make_pair(
(h1[i][r] - h1[i][l - 1] + MOD1) % MOD1 * p1[M - r] % MOD1,
(h2[i][r] - h2[i][l - 1] + MOD2) % MOD2 * p2[M - r] % MOD2
);
}
void dfs(int v){
used[v] = true;
for(int to : g[v]){
if(!used[to]){
dfs(to);
}
dp[v] = max(dp[v], dp[to]);
}
dp[v] += a[v];
ans = max(ans, dp[v]);
}
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();
h1[i].resize(sz + 2);
h2[i].resize(sz + 2);
for(int j = 1; j <= sz; j++){
h1[i][j] = (h1[i][j - 1] + 1LL * s[i][j - 1] * p1[j]) % MOD1;
h2[i][j] = (h2[i][j - 1] + 1LL * s[i][j - 1] * p2[j]) % MOD2;
}
int hh1 = h1[i][sz] * p1[M - sz] % MOD1,
hh2 = h2[i][sz] * p2[M - sz] % MOD2;
///cout << hh1 << " " << hh2 << "\n";
if(ss[make_pair(hh1, hh2)]){
a[ss[make_pair(hh1, hh2)]] += 1;
}
else{
ss[make_pair(hh1, hh2)] = i;
a[i] += 1;
q[make_pair(hh1, hh2)].push_back(i);
}
}
for(int i = 1; i <= n; i++){
int sz = (int)s[i].size();
for(int j = 1; j <= sz; j++){
auto it1 = get(i, 1, j),
it2 = get(i, sz - j + 1, sz);
if(it1 == it2){
///cout << i << " " << j << " " << it1.first << " " << it1.second << "\n";
for(auto it3 : q[it1]){
if(it3 != i){
g[it3].push_back(i);
}
}
}
}
}
for(int i = 1; i <= n; i++){
if(!used[i]){
dfs(i);
}
}
cout << ans;
}
Compilation message
savez.cpp:36:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
31736 KB |
Output is correct |
2 |
Incorrect |
35 ms |
31736 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
31864 KB |
Output is correct |
2 |
Correct |
33 ms |
31752 KB |
Output is correct |
3 |
Incorrect |
39 ms |
33144 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
49572 KB |
Output is correct |
2 |
Incorrect |
172 ms |
49812 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
33016 KB |
Output is correct |
2 |
Correct |
165 ms |
49500 KB |
Output is correct |
3 |
Incorrect |
165 ms |
50680 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
76 ms |
65528 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 |
72 ms |
64284 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 |
90 ms |
63864 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 |
74 ms |
63640 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 |
68 ms |
63352 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 |
74 ms |
63460 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |