結果

問題 No.464 PPAP
ユーザー uwiuwi
提出日時 2016-12-10 02:48:45
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,071 bytes
コンパイル時間 3,948 ms
コンパイル使用メモリ 79,084 KB
実行使用メモリ 47,792 KB
最終ジャッジ日時 2024-05-06 14:07:51
合計ジャッジ時間 9,621 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
46,816 KB
testcase_01 AC 125 ms
41,112 KB
testcase_02 AC 128 ms
40,976 KB
testcase_03 AC 127 ms
41,092 KB
testcase_04 AC 156 ms
41,512 KB
testcase_05 AC 129 ms
41,044 KB
testcase_06 AC 129 ms
41,072 KB
testcase_07 AC 397 ms
41,512 KB
testcase_08 AC 197 ms
41,220 KB
testcase_09 AC 132 ms
41,568 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 #

package adv2016;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class N464N {
	static Scanner in;
	static PrintWriter out;
	
	static String INPUT = "";

	static void solve() {
		char[] s = in.next().toCharArray();
		if(!(s.length >= 4))throw new AssertionError();
		if(!(s.length <= 5000))throw new AssertionError();
		for(char c : s){
			if(!(c >= 'a' && c <= 'z'))throw new AssertionError();
		}
		
		long B = 1000000009;
		int n = s.length;
		long[] hs = new long[n+1];
		for(int i = 0;i < n;i++){
			hs[i+1] = hs[i] * B + s[i];
		}
		long[] rhs = new long[n+1];
		for(int i = 0;i < n;i++){
			rhs[n-i-1] = rhs[n-i] * B + s[n-1-i];
		}
		long[] pows = new long[n+1];
		pows[0] = 1;
		for(int i = 1;i <= n;i++)pows[i] = pows[i-1] * B;
		
		long ct = 0;
		for(int i = 1;i < n;i++){
			if(hs[i] == rhs[0] - rhs[i]*pows[i]){
				for(int j = i+1;j < n;j++){
					if(hs[j] - hs[i] * pows[j-i] == rhs[i] - rhs[j] * pows[j-i]){
						for(int k = j+1;k < n;k++){
							if(hs[n] - hs[k] * pows[n-k] == rhs[k] - rhs[n] * pows[n-k]){
								ct++;
							}
						}
					}
				}
			}
		}
		out.println(ct);
	}
	
	public static int[] palindrome(char[] str)
	{
		int n = str.length;
		int[] r = new int[2*n];
		int k = 0;
		for(int i = 0, j = 0;i < 2*n;i += k, j = Math.max(j-k, 0)){
			// normally
			while(i-j >= 0 && i+j+1 < 2*n && str[(i-j)/2] == str[(i+j+1)/2])j++;
			r[i] = j;
			
			// skip based on the theorem
			for(k = 1;i-k >= 0 && r[i]-k >= 0 && r[i-k] != r[i]-k;k++){
				r[i+k] = Math.min(r[i-k], r[i]-k);
			}
		}
		return r;
	}


	public static void main(String[] args) throws Exception {
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

	static int ni() {
		return Integer.parseInt(in.next());
	}

	static long nl() {
		return Long.parseLong(in.next());
	}

	static double nd() {
		return Double.parseDouble(in.next());
	}

	static void tr(Object... o) {
		if (INPUT.length() != 0)
			System.out.println(Arrays.deepToString(o));
	}
}
0