CE求助
查看原帖
CE求助
339311
mori_楼主2023/8/31 13:40

看不懂啊这啥报错。

//
//  Created by mori on 2023/08/31 下午1:19 星期四
//
//  P3805 【模板】manacher 算法 on Luogu 
//  Coded with CLion
//  

#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;
typedef vector <int> vci;
typedef long long ll;
typedef __int128 lll;

struct MODER {
    ll p, m;

    explicit MODER (ll tmp) : p(tmp), m((ll) (((lll) 1 << 63) / tmp)) {}

    ll operator() (ll x) const {
        ll q = ((lll) x * m) >> 63;
        x -= p * q;
        if (x >= p) x -= p;
        return x;
    }
};

#define rep(i, x, y) for (int i = (x); i <= (y); ++i)
#define per(i, x, y) for (int i = (x); i >= (y); --i)
#define cat const auto &

template <typename T>
void ckmin (T &_0, T _1) { if (_1 < _0) _0 = _1; }

template <typename T>
void ckmax (T &_0, T _1) { if (_1 > _0) _0 = _1; }

int read () {
    int res = 0;
    bool f = false;
    char temp = getchar();
    for (; !isdigit(temp); temp = getchar()) f = temp == '-';
    for (; isdigit(temp); temp = getchar()) res = res * 10 + temp - '0';
    if (f) return -res;
    return res;
}

char gc () {
    char temp = getchar();
    while (temp == '\n' || temp == '\r' || temp == ' ') temp = getchar();
    return temp;
}

constexpr int maxn = 2e8 + 4e5;
char s[maxn] = {'A', 'M'};
int ans, len = 1, p[maxn];

signed main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (cin >> s[++len]) s[++len] = 'M';
    int r = 0, mid = 0;
    rep (i, 1, len) {
        p[i] = 1;
        if (r > i) p[i] = min(p[(mid << 1) - i], r - i + 1);
        while (s[i - p[i]] == s[i + p[i]]) ++p[i];
        if (i + p[i] - 1 > r) r = i + p[i] - 1, mid = i;
        ckmax(ans, p[i]);
    }
    printf("%d\n", ans - 1);
    return 0;
}
2023/8/31 13:40
加载中...