結果

問題 No.464 PPAP
ユーザー tentententen
提出日時 2020-12-24 12:34:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 1,400 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 77,172 KB
実行使用メモリ 82,904 KB
最終ジャッジ日時 2023-10-21 15:37:48
合計ジャッジ時間 8,382 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,328 KB
testcase_01 AC 130 ms
57,308 KB
testcase_02 AC 131 ms
57,352 KB
testcase_03 AC 126 ms
55,236 KB
testcase_04 AC 129 ms
57,516 KB
testcase_05 AC 130 ms
57,336 KB
testcase_06 AC 132 ms
57,348 KB
testcase_07 AC 163 ms
57,480 KB
testcase_08 AC 153 ms
57,400 KB
testcase_09 AC 144 ms
57,328 KB
testcase_10 AC 391 ms
82,904 KB
testcase_11 AC 275 ms
71,244 KB
testcase_12 AC 344 ms
82,076 KB
testcase_13 AC 331 ms
82,284 KB
testcase_14 AC 371 ms
82,716 KB
testcase_15 AC 131 ms
57,544 KB
testcase_16 AC 129 ms
57,676 KB
testcase_17 AC 131 ms
57,388 KB
testcase_18 AC 130 ms
57,488 KB
testcase_19 AC 129 ms
57,496 KB
testcase_20 AC 133 ms
57,340 KB
testcase_21 AC 134 ms
57,572 KB
testcase_22 AC 132 ms
57,516 KB
testcase_23 AC 325 ms
82,224 KB
testcase_24 AC 339 ms
82,236 KB
testcase_25 AC 357 ms
80,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        boolean[][] isUse = new boolean[length][length];
        for (int i = 0; i < length - 1; i++) {
            isUse[i][i] = true;
            isUse[i][i + 1] = (arr[i] == arr[i + 1]);
        }
        isUse[length - 1][length - 1] = true;
        for (int i = 2; i < length; i++) {
            for (int j = 0; i + j < length; j++) {
                isUse[j][j + i] = (arr[j] == arr[j + i] && isUse[j + 1][j + i - 1]);
            }
        }
        int[] counts = new int[length];
        for (int i = 0; i < length - 3; i++) {
            if (!isUse[0][i]) {
                continue;
            }
            for (int j = i + 1; j < length - 2; j++) {
                if (isUse[i + 1][j]) {
                    counts[j]++;
                }
            }
        }
        long[] lasts = new long[length];
        lasts[length - 1] = 1;
        for (int i = length - 2; i >= 0; i--) {
            lasts[i] = lasts[i + 1];
            if (isUse[i][length - 1]) {
                lasts[i]++;
            }
        }
        long ans = 0;
        for (int i = 0; i + 2 < length; i++) {
            ans += counts[i] * lasts[i + 2];
        }
        System.out.println(ans);
    }
}
0