Submission #100847

# Submission time Handle Problem Language Result Execution time Memory
100847 2019-03-14T21:07:04 Z dalgerok Savez (COCI15_savez) C++17
120 / 120
134 ms 17144 KB
#include<bits/stdc++.h>
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;

inline pair < int, int > get(int l, int r){
    return make_pair(
        1LL * (h1[r] - h1[l - 1] + MOD1) % MOD1 * p1[M - r] % MOD1,
        1LL * (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] = 1LL * p1[i - 1] * 59 % MOD1;
        p2[i] = 1LL * p2[i - 1] * 45 % MOD2;
    }
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> s;
        int sz = (int)s.size();
        for(int j = 1; j <= sz; j++){
            h1[j] = (h1[j - 1] + 1LL * s[j - 1] * p1[j]) % MOD1;
            h2[j] = (h2[j - 1] + 1LL * s[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:19:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 24 ms 16000 KB Output is correct
2 Correct 24 ms 15992 KB Output is correct
3 Correct 25 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 15992 KB Output is correct
2 Correct 24 ms 15992 KB Output is correct
3 Correct 26 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 15992 KB Output is correct
2 Correct 54 ms 16060 KB Output is correct
3 Correct 87 ms 16092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 15992 KB Output is correct
2 Correct 53 ms 16120 KB Output is correct
3 Correct 65 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 16000 KB Output is correct
2 Correct 52 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 16040 KB Output is correct
2 Correct 72 ms 17060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 16104 KB Output is correct
2 Correct 63 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 16120 KB Output is correct
2 Correct 52 ms 17144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 16000 KB Output is correct
2 Correct 69 ms 17144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 16000 KB Output is correct
2 Correct 79 ms 16120 KB Output is correct
3 Correct 134 ms 16120 KB Output is correct