結果
問題 |
No.464 PPAP
|
ユーザー |
![]() |
提出日時 | 2020-01-24 08:47:17 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,472 bytes |
コンパイル時間 | 2,646 ms |
コンパイル使用メモリ | 79,032 KB |
実行使用メモリ | 244,224 KB |
最終ジャッジ日時 | 2024-09-13 20:14:39 |
合計ジャッジ時間 | 8,679 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 TLE * 1 -- * 15 |
ソースコード
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); } }