Submission #549965

# Submission time Handle Problem Language Result Execution time Memory
549965 2022-04-17T01:53:46 Z Duy_e Palindromes (APIO14_palindrome) C++14
23 / 100
1000 ms 8996 KB
/*
**  TASK: 
**  LINK: 
*/

#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long INF = 1e18;
const long long N = 2e5 + 5;
const long long base = 311;
const long long MOD = 1e9 + 321;

string s;
ll h[N], ph[N], pw[N], n;

ll get(int l, int r) {
    return (h[r] - h[l - 1] * pw[r - l + 1] % MOD + MOD * MOD) % MOD;
}

ll getpre(int l, int r) {
    return (ph[l] - ph[r + 1] * pw[r - l + 1] % MOD + MOD * MOD) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // #ifndef hihi
    //     freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    // #endif
    
    cin >> s;
    s = '#' + s;

    n = s.size() - 1;

    pw[0] = 1;
    for (int i = 1; i <= n; i ++) {
        pw[i] = pw[i - 1] * base % MOD;
        h[i] = (h[i - 1] * base + s[i]) % MOD;
    }

    for (int i = n; i >= 1; i --)
        ph[i] = (ph[i + 1] * base + s[i]) % MOD;

    map <int, ll> dp;
    
    ll ans = 0;
    for (int i = 1; i <= n; i ++)
        for (int j = i; j <= n; j ++) {
            ll x = get(i, j);
            if (x == getpre(i, j)) {
                // cout << i << ' ' << j << '\n';
                dp[x] += j - i + 1;
                ans = max(ans, dp[x]);
            }
        }

    cout << ans;

    return 0;
}    
/**  /\_/\
*   (= ._.)
*   / >🍵 \>🍮
**/

Compilation message

palindrome.cpp:67:9: warning: "/*" within comment [-Wcomment]
   67 | /**  /\_/\
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 340 KB Output is correct
2 Correct 11 ms 332 KB Output is correct
3 Correct 40 ms 408 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 39 ms 328 KB Output is correct
6 Correct 37 ms 424 KB Output is correct
7 Correct 6 ms 340 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 4 ms 368 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 8996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 7988 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -