제출 #549965

#제출 시각아이디문제언어결과실행 시간메모리
549965Duy_ePalindromes (APIO14_palindrome)C++14
23 / 100
1087 ms8996 KiB
/*
**  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;
}    
/**  /\_/\
*   (= ._.)
*   / >🍵 \>🍮
**/

컴파일 시 표준 에러 (stderr) 메시지

palindrome.cpp:67:9: warning: "/*" within comment [-Wcomment]
   67 | /**  /\_/\
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...