結果

問題 No.599 回文かい
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-11-24 23:05:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,299 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 74,512 KB
実行使用メモリ 56,288 KB
最終ジャッジ日時 2023-08-18 05:09:34
合計ジャッジ時間 10,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,564 KB
testcase_01 AC 120 ms
55,536 KB
testcase_02 AC 121 ms
55,548 KB
testcase_03 AC 122 ms
55,544 KB
testcase_04 AC 129 ms
55,780 KB
testcase_05 WA -
testcase_06 AC 128 ms
55,636 KB
testcase_07 AC 131 ms
55,772 KB
testcase_08 AC 130 ms
55,560 KB
testcase_09 WA -
testcase_10 AC 441 ms
56,192 KB
testcase_11 AC 325 ms
56,220 KB
testcase_12 AC 482 ms
56,268 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 120 ms
55,584 KB
testcase_19 WA -
testcase_20 WA -
evil_0.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    static final long MOD=1000000007;
    static final long P=1000000009;
    static final long[]Q={MOD,P};
    static long[]dp;
    static long[][]h,p;
    static final long b=31;
    static long c(int x,int y,int j){
        long t=h[j][y];
        t+=h[j][x]*(Q[j]-p[j][y-x])%Q[j];
        return t%Q[j];
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s=scan.next();
        int n=s.length();
        int[]a=new int[n];
        for(int i=0;i<n;++i)a[i]=s.charAt(i)-'a';
        h=new long[2][n+1];
        p=new long[2][n+1];
        for(int j=0;j<2;++j)
            for(int i=0;i<n;++i)
                h[j][i+1]=(b*h[j][i]+a[i])%Q[j];
        p[0][0]=p[1][0]=1;
        for(int j=0;j<2;++j)
            for(int i=0;i<n;++i)
                p[j][i+1]=p[j][i]*b%Q[j];
        dp=new long[n+1];
        dp[0]=1;
        for(int i=1;i<=n/2;++i){
            long t=0;
            for(int j=0;j<=i;++j){
                if(c(j,i,0)==c(n-i,n-j,0)&&c(j,i,1)==c(n-i,n-j,1))t=(t+dp[j])%MOD;
            }
            dp[i]=t;
        }
        long t=0;
        for(int i=0;i<=n/2;++i)
            t=(t+dp[i])%P;
        //System.err.println(Arrays.toString(dp));
        System.out.println(t);
    }
}
0