結果

問題 No.765 ukuku 2
ユーザー pekempeypekempey
提出日時 2018-12-13 02:06:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,958 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 34,832 KB
実行使用メモリ 8,388 KB
最終ジャッジ日時 2023-10-25 09:00:07
合計ジャッジ時間 3,681 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,312 KB
testcase_01 AC 2 ms
5,312 KB
testcase_02 AC 2 ms
5,312 KB
testcase_03 AC 2 ms
5,312 KB
testcase_04 AC 2 ms
5,312 KB
testcase_05 AC 2 ms
5,312 KB
testcase_06 AC 2 ms
5,312 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,312 KB
testcase_10 AC 2 ms
5,312 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,312 KB
testcase_13 AC 2 ms
5,312 KB
testcase_14 AC 2 ms
5,312 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,312 KB
testcase_19 AC 2 ms
5,312 KB
testcase_20 AC 2 ms
5,312 KB
testcase_21 AC 2 ms
5,312 KB
testcase_22 AC 2 ms
5,312 KB
testcase_23 WA -
testcase_24 AC 2 ms
5,312 KB
testcase_25 AC 2 ms
5,312 KB
testcase_26 AC 2 ms
5,312 KB
testcase_27 AC 2 ms
5,312 KB
testcase_28 AC 2 ms
5,312 KB
testcase_29 AC 3 ms
5,312 KB
testcase_30 AC 93 ms
8,248 KB
testcase_31 AC 92 ms
8,240 KB
testcase_32 AC 79 ms
8,192 KB
testcase_33 AC 46 ms
8,328 KB
testcase_34 AC 47 ms
8,328 KB
testcase_35 AC 124 ms
8,328 KB
testcase_36 WA -
testcase_37 AC 130 ms
8,328 KB
testcase_38 AC 144 ms
8,328 KB
testcase_39 AC 150 ms
8,328 KB
testcase_40 AC 94 ms
8,252 KB
testcase_41 AC 105 ms
8,276 KB
testcase_42 AC 111 ms
8,296 KB
testcase_43 AC 103 ms
8,264 KB
testcase_44 AC 101 ms
8,264 KB
testcase_45 AC 119 ms
8,304 KB
testcase_46 AC 100 ms
8,256 KB
testcase_47 AC 114 ms
8,312 KB
testcase_48 AC 112 ms
8,304 KB
testcase_49 AC 115 ms
8,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define M 1000000007

long long B;
int n;
char s[200001];
char t[200001];
long long H[200001];
long long G[200001];
long long P[200001];

int min(int x, int y) {
    return x < y ? x : y;
}

int max(int x, int y) {
    return x > y ? x : y;
}

long long mod(long long x) {
    x %= M;
    if (x < 0) x += M;
    return x;
}

long long f(int l, int n) {
    return mod(H[l + n] - H[l] * P[n]);
}

long long g(int l, int n) {
    return mod(G[l + n] - G[l] * P[n]);
}

int lcp(int a, int b, int n) {
    int l = 0;
    int r = n + 1;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (f(a, mid) == g(b, mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    return l;
}

int solve(int a, int b, int n) {
    int l = 0;
    int r = n + 1;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (f(a, mid) == g(b, mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    if (l == n) return l;
    a += l;
    b += l;
    n -= l;
    int vl = lcp(a, b + 1, n - 1);
    int vr = lcp(a + 1, b, n - 1);
    return l + max(vl, vr);
}

int main() {
    scanf("%s", s);
    n = strlen(s);
    for (int i = 0; i < n; i++) {
        t[n - 1 - i] = s[i];
    }
    srand(time(NULL));
    B = rand() % M;
    P[0] = 1;
    for (int i = 1; i <= n; i++) {
        P[i] = B * P[i - 1] % M;
    }
    for (int i = 0; i < n; i++) {
        H[i + 1] = (H[i] * B + s[i]) % M;
        G[i + 1] = (G[i] * B + t[i]) % M;
    }
    int ans = 0;
    // odd length
    for (int i = 0; i < n; i++) {
        int x = 2 * solve(i + 1, n - i, min(i, n - (i + 1)));
        x = min(x, n - 2);
        ans = max(ans, 1 + x);
    }
    // even length
    for (int i = 1; i < n; i++) {
        int x  = 2 * solve(i, n - i, min(i, n - i));
        x = min(x, n - 1);
        ans = max(ans, x);
    }
    printf("%d\n", ans);
}

0