結果

問題 No.599 回文かい
ユーザー snrnsidysnrnsidy
提出日時 2021-09-21 14:08:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,267 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 200,508 KB
実行使用メモリ 198,164 KB
最終ジャッジ日時 2023-09-16 23:21:59
合計ジャッジ時間 7,603 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 4 ms
9,984 KB
testcase_05 AC 4 ms
7,916 KB
testcase_06 AC 4 ms
10,052 KB
testcase_07 AC 4 ms
9,992 KB
testcase_08 AC 4 ms
10,312 KB
testcase_09 AC 3 ms
7,976 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 686 ms
187,532 KB
testcase_17 AC 784 ms
198,164 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
evil_0.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;

const int MOD = 10007;

inline int mod(long long n){
    if(n >= 0) return n % MOD;
    return ((-n/MOD+1)*MOD + n) % MOD;
}
 
short arr[10000][10000];
int dp[5005];
bool issame = true;
int L1,R1,L2,R2;
char S[200001];

int main()
{
    scanf("%s", S);
    int L = strlen(S);
    for(int mid=1;mid<=L;mid++)
    {
        int H = 0, power = 1;

        for(int i=0; i<=L-mid; i++){
            if(i == 0){
                for(int j=0; j<mid; j++){
                    H = mod(H + 1LL*S[mid-1-j]*power);
                    if(j < mid-1) power = mod(power*2);
                }
            }
            else H = mod(2*(H - 1LL*S[i-1]*power) + S[i+mid-1]);
            arr[i][i+mid-1] = H;
        }
    }

    dp[0] = 1;

    for(int i=0;i<=(L/2);i++)
    {
      for(int j=1;j<=L;j++)
      {
        L1 = i;
        R1 = i + j - 1;
        R2 = L-1-i;
        L2 = R2-j+1;
        if(L2<=R1) break;
        issame = true;
        if(arr[L1][R1]==arr[L2][R2])
        {
            dp[R1+1] += dp[i];
            dp[R1+1]%=1000000007;
        }
      }
    }

    long long int res = 0;

    for(int i=0;i<=(L/2);i++)
    {
      res += dp[i];
      res%=(1000000007);
    }

    cout << res << '\n';

    return 0;
}
0