Submission #318478

# Submission time Handle Problem Language Result Execution time Memory
318478 2020-11-02T05:05:28 Z qpwoeirut Palindromes (APIO14_palindrome) C++17
23 / 100
1000 ms 1124 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

string s;
const int CT = 3;
const ll BASE = 29;
const ll MOD[CT] = {(ll)1e9 + 7, (ll)1e9 + 9, (ll)1e9 + 13};


ll binpow(ll x, ll p, const ll mod) {
    x %= mod;
    p %= mod;
    ll res = 1;
    while (p > 0) {
        if (p & 1) {
            res = (res * x) % mod;
        }
        x = (x * x) % mod;
        p >>= 1;
    }
    return res;
}

struct Hash {
    ll val[CT];
    int len;

    Hash() {
        for (int i=0; i<CT; ++i) {
            val[i] = 0;
        }
        len = 0;
    }
    Hash(char c) {
        for (int i=0; i<CT; ++i) {
            val[i] = c - 'a' + 1;
        }
        len = 1;
    }

    void add_left(char c) {
        for (int i=0; i<CT; ++i) { 
            val[i] = (val[i] * BASE) % MOD[i];
            val[i] += c - 'a' + 1;
        }
        ++len;
    }
    void add_right(char c) {
        for (int i=0; i<CT; ++i) {
            val[i] = (val[i] + c * binpow(BASE, len, MOD[i])) % MOD[i];
        }
        ++len;
    }

    inline const bool operator<(const Hash& other) const {
        if (len != other.len) {
            return len < other.len;
        }
        for (int i=0; i<CT; ++i) {
            if (val[i] != other.val[i]) {
                return val[i] < other.val[i];
            }
        }
        return false;
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> s;
    const int N = s.size();

    map<Hash, ll> ct;
    for (int i=0; i<N; ++i) {
        Hash hash(s[i]);
        ++ct[hash];
        int L = i-1, R = i+1;
        while (L >= 0 && R < N && s[L] == s[R]) {
            hash.add_left(s[L]);
            hash.add_right(s[R]);
            
            ++ct[hash];
            --L; ++R;
        }

        hash = Hash();
        L = i, R = i+1;
        while (L >= 0 && R < N && s[L] == s[R]) {
            hash.add_left(s[L]);
            hash.add_right(s[R]);
            
            ++ct[hash];
            --L; ++R;
        }
    }

    ll ans = 0;
    for (auto it=ct.begin(); it!=ct.end(); ++it) {
        ans = max(ans, it->first.len * it->second);
    }

    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 396 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 364 KB Output is correct
2 Correct 42 ms 364 KB Output is correct
3 Correct 200 ms 492 KB Output is correct
4 Correct 8 ms 364 KB Output is correct
5 Correct 197 ms 364 KB Output is correct
6 Correct 197 ms 484 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 98 ms 452 KB Output is correct
9 Correct 4 ms 360 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1051 ms 900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 1124 KB Time limit exceeded
2 Halted 0 ms 0 KB -