結果

問題 No.765 ukuku 2
ユーザー kriiikriii
提出日時 2018-12-13 02:42:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 455 ms / 3,000 ms
コード長 2,116 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 44,516 KB
実行使用メモリ 128,504 KB
最終ジャッジ日時 2023-10-25 09:01:18
合計ジャッジ時間 9,232 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,364 KB
testcase_01 AC 3 ms
9,364 KB
testcase_02 AC 3 ms
9,364 KB
testcase_03 AC 3 ms
9,364 KB
testcase_04 AC 3 ms
9,364 KB
testcase_05 AC 3 ms
9,364 KB
testcase_06 AC 3 ms
9,364 KB
testcase_07 AC 3 ms
9,364 KB
testcase_08 AC 3 ms
9,364 KB
testcase_09 AC 3 ms
9,368 KB
testcase_10 AC 3 ms
9,364 KB
testcase_11 AC 3 ms
9,364 KB
testcase_12 AC 3 ms
9,364 KB
testcase_13 AC 3 ms
9,364 KB
testcase_14 AC 3 ms
9,364 KB
testcase_15 AC 3 ms
9,364 KB
testcase_16 AC 3 ms
9,364 KB
testcase_17 AC 4 ms
9,368 KB
testcase_18 AC 3 ms
9,368 KB
testcase_19 AC 3 ms
9,368 KB
testcase_20 AC 3 ms
9,368 KB
testcase_21 AC 3 ms
9,368 KB
testcase_22 AC 3 ms
9,368 KB
testcase_23 AC 3 ms
9,368 KB
testcase_24 AC 3 ms
9,368 KB
testcase_25 AC 3 ms
9,368 KB
testcase_26 AC 3 ms
9,380 KB
testcase_27 AC 3 ms
9,380 KB
testcase_28 AC 3 ms
9,380 KB
testcase_29 AC 3 ms
9,380 KB
testcase_30 AC 303 ms
102,996 KB
testcase_31 AC 292 ms
102,296 KB
testcase_32 AC 236 ms
86,044 KB
testcase_33 AC 426 ms
128,504 KB
testcase_34 AC 405 ms
128,504 KB
testcase_35 AC 402 ms
128,504 KB
testcase_36 AC 402 ms
128,504 KB
testcase_37 AC 423 ms
128,504 KB
testcase_38 AC 455 ms
128,504 KB
testcase_39 AC 429 ms
128,504 KB
testcase_40 AC 304 ms
106,556 KB
testcase_41 AC 339 ms
113,444 KB
testcase_42 AC 367 ms
119,352 KB
testcase_43 AC 315 ms
108,608 KB
testcase_44 AC 318 ms
110,660 KB
testcase_45 AC 366 ms
121,696 KB
testcase_46 AC 314 ms
108,608 KB
testcase_47 AC 369 ms
126,624 KB
testcase_48 AC 355 ms
124,140 KB
testcase_49 AC 362 ms
124,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
using namespace std;

int mod[2] = {1000000007,1000000009};
long long bas[2][20];

char S[200200]; int L;
long long A[2][200200][20], B[2][200200][20];

int f(int i, int j)
{
    int r = 0;
    for (int l=19;l>=0;l--){
        if (i < 1 || j > L) break;
        
        bool good = true;
        for (int k=0;k<2;k++){
            if (A[k][i][l] == -1 || B[k][j][l] == -1 || A[k][i][l] != B[k][j][l]){
                good = false;
                break;
            }
        }
        
        if (good){
            i -= (1 << l);
            j += (1 << l);
            r += (1 << l);
        }
    }
    return r;
}

int main()
{
    scanf ("%s",S+1);
    while (S[L+1]) L++;
    
    for (int k=0;k<2;k++){
        for (int l=0;l<20;l++) A[k][0][l] = B[k][L+1][l] = -1;
        bas[k][0] = (long long)S % mod[k]; bas[k][0] |= 512;
        for (int l=1;l<20;l++) bas[k][l] = bas[k][l-1] * bas[k][l-1] % mod[k];
    }
    
    for (int k=0;k<2;k++) for (int i=1;i<=L;i++){
        A[k][i][0] = S[i];
        for (int l=1;l<20;l++){
            int s = 1 << (l-1);
            if (A[k][i][l-1] == -1 || i - s < 0 || A[k][i-s][l-1] == -1)
                A[k][i][l] = -1;
            else
                A[k][i][l] = (A[k][i-s][l-1] * bas[k][l-1] + A[k][i][l-1]) % mod[k];
        }
    }
    
    for (int k=0;k<2;k++) for (int i=L;i>=1;i--){
        B[k][i][0] = S[i];
        for (int l=1;l<20;l++){
            int s = 1 << (l-1);
            if (B[k][i][l-1] == -1 || i + s > L || B[k][i+s][l-1] == -1)
                B[k][i][l] = -1;
            else
                B[k][i][l] = (B[k][i+s][l-1] * bas[k][l-1] + B[k][i][l-1]) % mod[k];
        }
    }
    
    int ans = 0;
    for (int i=1;i<=L;i++){
        int l = f(i,i);
        int u = max(f(i-l-1,i+l),f(i-l,i+l+1)) + l;
        if (u * 2 - 1 == L) u--;
        ans = max(ans, u*2-1);
    }
    for (int i=1;i<L;i++){
        int l = f(i,i+1);
        int u = max(f(i-l-1,i+1+l),f(i-l,i+1+l+1)) + l;
        if (u * 2 == L) u--;
        ans = max(ans, u*2);
    }
    printf ("%d\n",ans);
    
    return 0;
}
0