結果

問題 No.911 ラッキーソート
ユーザー ks2mks2m
提出日時 2019-10-18 23:46:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 349 ms / 2,000 ms
コード長 1,699 bytes
コンパイル時間 3,435 ms
コンパイル使用メモリ 74,024 KB
実行使用メモリ 79,104 KB
最終ジャッジ日時 2023-09-08 02:54:28
合計ジャッジ時間 15,253 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,344 KB
testcase_01 AC 43 ms
49,664 KB
testcase_02 AC 42 ms
49,328 KB
testcase_03 AC 44 ms
49,408 KB
testcase_04 AC 44 ms
49,408 KB
testcase_05 AC 45 ms
49,268 KB
testcase_06 AC 43 ms
49,348 KB
testcase_07 AC 44 ms
49,268 KB
testcase_08 AC 45 ms
49,268 KB
testcase_09 AC 45 ms
49,476 KB
testcase_10 AC 42 ms
49,748 KB
testcase_11 AC 44 ms
49,300 KB
testcase_12 AC 43 ms
49,324 KB
testcase_13 AC 328 ms
76,024 KB
testcase_14 AC 333 ms
76,648 KB
testcase_15 AC 322 ms
76,556 KB
testcase_16 AC 344 ms
75,672 KB
testcase_17 AC 343 ms
75,816 KB
testcase_18 AC 349 ms
75,952 KB
testcase_19 AC 325 ms
78,820 KB
testcase_20 AC 321 ms
76,384 KB
testcase_21 AC 327 ms
76,808 KB
testcase_22 AC 327 ms
75,668 KB
testcase_23 AC 338 ms
74,844 KB
testcase_24 AC 308 ms
69,308 KB
testcase_25 AC 295 ms
65,596 KB
testcase_26 AC 240 ms
60,104 KB
testcase_27 AC 199 ms
56,000 KB
testcase_28 AC 159 ms
55,176 KB
testcase_29 AC 107 ms
51,892 KB
testcase_30 AC 58 ms
50,360 KB
testcase_31 AC 46 ms
49,636 KB
testcase_32 AC 44 ms
49,180 KB
testcase_33 AC 44 ms
49,232 KB
testcase_34 AC 43 ms
49,152 KB
testcase_35 AC 46 ms
49,312 KB
testcase_36 AC 45 ms
49,528 KB
testcase_37 AC 45 ms
49,168 KB
testcase_38 AC 347 ms
76,084 KB
testcase_39 AC 322 ms
76,048 KB
testcase_40 AC 105 ms
52,420 KB
testcase_41 AC 328 ms
78,896 KB
testcase_42 AC 319 ms
67,544 KB
testcase_43 AC 328 ms
78,592 KB
testcase_44 AC 319 ms
77,232 KB
testcase_45 AC 316 ms
79,104 KB
testcase_46 AC 314 ms
79,004 KB
testcase_47 AC 329 ms
76,420 KB
testcase_48 AC 330 ms
75,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		long l = Long.parseLong(sa[1]) - 1;
		long r = Long.parseLong(sa[2]);
		sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		int[] dp = new int[62];
		Arrays.fill(dp, 2);
		for (int i = 1; i < n; i++) {
			for (int j = 61; j >= 0; j--) {
				long x = a[i - 1] >> j & 1;
				long y = a[i] >> j & 1;
				if (x > y) {
					if (dp[j] == 0) {
						System.out.println(0);
						return;
					}
					dp[j] = 1;
					break;
				}
				if (x < y) {
					if (dp[j] == 1) {
						System.out.println(0);
						return;
					}
					dp[j] = 0;
					break;
				}
			}
		}

		long[][] bdp1 = bdp(dp, r);
		long[][] bdp2 = bdp(dp, l);
		System.out.println(bdp1[0][0] + bdp1[0][1] - bdp2[0][0] - bdp2[0][1]);
	}

	static long[][] bdp(int[] dp, long r) {
		long[][] bdp = new long[62][2];
		if (r < 0) {
			return bdp;
		}
		bdp[61][0] = 1;
		for (int j = 60; j >= 0; j--) {
			bdp[j][1] = bdp[j + 1][1];
			if (dp[j] == 0) {
				if ((r >> j & 1) == 0) {
					bdp[j][0] = bdp[j + 1][0];
				} else {
					bdp[j][1] += bdp[j + 1][0];
				}
			} else if (dp[j] == 1) {
				if ((r >> j & 1) == 1) {
					bdp[j][0] = bdp[j + 1][0];
				}
			} else {
				bdp[j][1] += bdp[j + 1][1];
				bdp[j][0] = bdp[j + 1][0];
				if ((r >> j & 1) == 1) {
					bdp[j][1] += bdp[j + 1][0];
				}
			}
		}
		return bdp;
	}
}
0