結果

問題 No.916 Encounter On A Tree
ユーザー ks2mks2m
提出日時 2019-10-25 23:09:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 3,492 ms
コンパイル使用メモリ 73,920 KB
実行使用メモリ 55,820 KB
最終ジャッジ日時 2023-10-11 08:15:07
合計ジャッジ時間 8,573 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,188 KB
testcase_01 AC 43 ms
49,104 KB
testcase_02 AC 44 ms
49,140 KB
testcase_03 AC 65 ms
55,812 KB
testcase_04 AC 45 ms
49,164 KB
testcase_05 AC 63 ms
55,348 KB
testcase_06 AC 43 ms
49,308 KB
testcase_07 AC 66 ms
55,344 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 44 ms
49,308 KB
testcase_11 AC 44 ms
49,268 KB
testcase_12 AC 44 ms
49,092 KB
testcase_13 AC 63 ms
55,820 KB
testcase_14 AC 43 ms
49,180 KB
testcase_15 AC 63 ms
55,260 KB
testcase_16 AC 43 ms
49,416 KB
testcase_17 AC 63 ms
55,132 KB
testcase_18 AC 44 ms
49,180 KB
testcase_19 AC 64 ms
55,132 KB
testcase_20 AC 44 ms
49,192 KB
testcase_21 AC 64 ms
55,264 KB
testcase_22 AC 44 ms
49,256 KB
testcase_23 WA -
testcase_24 AC 43 ms
49,148 KB
testcase_25 AC 64 ms
55,204 KB
testcase_26 AC 44 ms
49,804 KB
testcase_27 AC 55 ms
52,128 KB
testcase_28 AC 43 ms
49,532 KB
testcase_29 WA -
testcase_30 AC 44 ms
49,180 KB
testcase_31 AC 44 ms
49,148 KB
testcase_32 AC 43 ms
49,160 KB
testcase_33 AC 44 ms
49,316 KB
testcase_34 AC 51 ms
49,964 KB
testcase_35 AC 46 ms
49,308 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 50 ms
49,908 KB
testcase_39 AC 43 ms
49,232 KB
testcase_40 WA -
testcase_41 AC 43 ms
49,188 KB
testcase_42 AC 44 ms
49,196 KB
testcase_43 AC 44 ms
49,312 KB
testcase_44 AC 43 ms
49,224 KB
testcase_45 AC 46 ms
49,508 KB
testcase_46 AC 43 ms
49,020 KB
testcase_47 AC 43 ms
49,316 KB
testcase_48 AC 43 ms
49,504 KB
testcase_49 AC 44 ms
49,488 KB
testcase_50 AC 44 ms
49,068 KB
testcase_51 WA -
testcase_52 AC 43 ms
49,084 KB
testcase_53 AC 44 ms
49,104 KB
testcase_54 AC 44 ms
49,212 KB
testcase_55 AC 44 ms
49,136 KB
testcase_56 AC 44 ms
49,488 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 44 ms
49,128 KB
testcase_60 AC 45 ms
49,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

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 d = Integer.parseInt(sa[0]);
		int l = Integer.parseInt(sa[1]);
		int r = Integer.parseInt(sa[2]);
		int k = Integer.parseInt(sa[3]);
		br.close();

		int dl = 1;
		for (int i = 1; i <= d; i++) {
			if ((1 << i) > l) {
				dl = i;
				break;
			}
		}
		int dr = 1;
		for (int i = 1; i <= d; i++) {
			if ((1 << i) > r) {
				dr = i;
				break;
			}
		}

		if (dr - dl <= k && k <= (dl + dr - 2) && (dr - dl) % 2 == k % 2) {
			int mod = 1000000007;
			int end = 1 << (d - 1);
			long[] p = new long[end + 1];
			p[0] = 1;
			for (int i = 1; i < p.length; i++) {
				p[i] = p[i - 1] * i % mod;
			}
			int k2 = k - (dr - dl);
			k2 /= 2;
			long ans = 1;
			for (int i = 0; i < d; i++) {
				if (dl > 1 && i + 1 == dr) {
					if (dl == dr) {
						ans *= 1 << i;
						ans %= mod;
						ans *= 1 << (k2 - 1);
						ans %= mod;
						ans *= p[(1 << i) - 2];
					} else {
						if (k2 == 0) {
							ans *= 1 << (i - 1);
						} else {
							ans *= 1 << k2;
						}
						ans %= mod;
						ans *= p[(1 << i) - 1];
					}
				} else {
					ans *= p[1 << i];
				}
				ans %= mod;
			}
			System.out.println(ans);
		} else {
			System.out.println(0);
		}
	}
}
0