結果

問題 No.599 回文かい
ユーザー snrnsidysnrnsidy
提出日時 2021-09-21 14:10:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 819 ms / 4,000 ms
コード長 1,792 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 203,848 KB
実行使用メモリ 138,728 KB
最終ジャッジ日時 2023-09-16 23:24:27
合計ジャッジ時間 8,126 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 4 ms
9,884 KB
testcase_05 AC 3 ms
7,884 KB
testcase_06 AC 4 ms
9,952 KB
testcase_07 AC 4 ms
9,928 KB
testcase_08 AC 4 ms
9,940 KB
testcase_09 AC 3 ms
8,060 KB
testcase_10 AC 449 ms
86,716 KB
testcase_11 AC 236 ms
79,392 KB
testcase_12 AC 495 ms
99,964 KB
testcase_13 AC 261 ms
81,796 KB
testcase_14 AC 656 ms
122,132 KB
testcase_15 AC 783 ms
132,716 KB
testcase_16 AC 738 ms
127,956 KB
testcase_17 AC 819 ms
138,728 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
evil_0.txt AC 556 ms
111,044 KB
権限があれば一括ダウンロードができます

ソースコード

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];
set <int> s;
int main()
{
    scanf("%s", S);
    int L = strlen(S);
    for(int i=0;i<L;i++)
    {
        s.insert(S[i]);
    }
    
    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])
        {
            if(s.size()==1)
            {
              dp[R1+1] += dp[i];
              dp[R1+1]%=1000000007;             
            }
            else
            {
              for(int k=0;k<j;k++)
              {
                if(S[L1+k]!=S[L2+k])
                {
                  issame = false;
                  break;
                }
              }
              if(issame)
              {
                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