結果

問題 No.464 PPAP
ユーザー htensaihtensai
提出日時 2020-01-24 08:47:17
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,472 bytes
コンパイル時間 2,737 ms
コンパイル使用メモリ 74,812 KB
実行使用メモリ 240,040 KB
最終ジャッジ日時 2023-10-11 21:21:55
合計ジャッジ時間 8,437 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
60,216 KB
testcase_01 AC 125 ms
55,724 KB
testcase_02 AC 121 ms
55,428 KB
testcase_03 AC 120 ms
56,156 KB
testcase_04 AC 138 ms
55,936 KB
testcase_05 AC 126 ms
55,684 KB
testcase_06 AC 117 ms
55,612 KB
testcase_07 AC 503 ms
88,856 KB
testcase_08 AC 350 ms
72,972 KB
testcase_09 AC 127 ms
55,884 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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 n = arr.length;
        TreeSet<Integer>[] counts = new TreeSet[n];
        for (int i = 0; i < n; i++) {
            counts[i] = new TreeSet<Integer>();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; i - j >= 0 && i + j < n; j++) {
                if (arr[i - j] == arr[i + j]) {
                    counts[i - j].add(j * 2 + 1);
                } else {
                    break;
                }
            }
            for (int j = 0; i - j >= 0 && i + j + 1 < n; j++) {
                if (arr[i - j] == arr[i + j + 1]) {
                    counts[i - j].add((j + 1) * 2);
                } else {
                    break;
                }
            }
        }
        int[] lasts = new int[n];
        lasts[n - 1] = 1;
        for (int i = n - 2; i >= 0; i--) {
            lasts[i] = lasts[i + 1];
            if (counts[i].last() == n - i) {
                lasts[i]++;
            }
        }
        long total = 0;
        for (int x : counts[0]) {
            if (x >= n) {
                continue;
            }
            for (int y : counts[x]) {
                if (x + y + 1 < n) {
                    total += lasts[x + y + 1];
                }
            }
        }
        System.out.println(total);
        
    }
}
0