結果

問題 No.1493 隣接xor
ユーザー 小野寺健小野寺健
提出日時 2021-05-05 15:21:31
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,132 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 81,436 KB
実行使用メモリ 112,364 KB
最終ジャッジ日時 2023-10-11 10:02:59
合計ジャッジ時間 8,209 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
60,556 KB
testcase_01 AC 124 ms
56,000 KB
testcase_02 AC 126 ms
56,072 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
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 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;

public class No1498 {

	public static void main(String[] args) {
		final int M = 1000000007;
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> B = new ArrayList<Integer>();
		HashMap<Integer, List<Integer>> D = new HashMap<Integer, List<Integer>>();
		int P = 0;
		for (int i=0; i < N-1; i++) {
			P ^= scan.nextInt();
			B.add(P);
			if (D.containsKey(P)) {
				D.get(P).add(i);
			} else {
				List<Integer> l = new ArrayList<Integer>();
				l.add(i);
				D.put(P, l);
			}
		}
		scan.nextInt();
		scan.close();
		int[] dp = new int[N];
		dp[0] = 1;
		for (int i=0; i < N-1; i++) {
			for (List<Integer> v : D.values()) {
				int j = Collections.binarySearch(v, i);
				if (j < 0) {
					j = -j - 1;
				}
				if (j >= v.size()) {
					continue;
				}
				dp[v.get(j)+1] = (dp[v.get(j)+1] + dp[i]) % M;
			}
		}
		int cnt = 0;
		for (int i=0; i < N; i++) {
			cnt = (cnt + dp[i]) % M;
		}
		System.out.println(cnt);
	}

}
0