結果

問題 No.916 Encounter On A Tree
ユーザー FF256grhy
提出日時 2019-10-26 01:13:24
言語 C++14
(gcc 8.3.0)
結果
AC  
実行時間 5 ms
コード長 1,359 Byte
コンパイル時間 1,366 ms
使用メモリ 1,512 KB
最終ジャッジ日時 2019-10-26 01:13:28

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
corner1 AC 4 ms
1,512 KB
corner2 AC 3 ms
1,508 KB
corner3 AC 3 ms
1,508 KB
corner4 AC 3 ms
1,508 KB
corner5 AC 3 ms
1,512 KB
corner6 AC 3 ms
1,508 KB
corner7 AC 3 ms
1,508 KB
corner8 AC 4 ms
1,512 KB
corner9 AC 3 ms
1,512 KB
corner10 AC 3 ms
1,508 KB
corner11 AC 3 ms
1,512 KB
corner12 AC 3 ms
1,508 KB
corner13 AC 3 ms
1,508 KB
corner14 AC 4 ms
1,508 KB
corner15 AC 3 ms
1,512 KB
corner16 AC 4 ms
1,508 KB
corner17 AC 5 ms
1,512 KB
corner18 AC 3 ms
1,508 KB
corner19 AC 3 ms
1,508 KB
corner20 AC 3 ms
1,508 KB
corner21 AC 3 ms
1,508 KB
large1 AC 3 ms
1,508 KB
large2 AC 3 ms
1,508 KB
large3 AC 4 ms
1,512 KB
large4 AC 4 ms
1,512 KB
large5 AC 3 ms
1,512 KB
large6 AC 4 ms
1,508 KB
large7 AC 3 ms
1,508 KB
large8 AC 3 ms
1,508 KB
large9 AC 3 ms
1,512 KB
large10 AC 4 ms
1,512 KB
large11 AC 3 ms
1,508 KB
large12 AC 3 ms
1,508 KB
large13 AC 3 ms
1,512 KB
large14 AC 3 ms
1,512 KB
large15 AC 3 ms
1,512 KB
large16 AC 3 ms
1,508 KB
large17 AC 3 ms
1,508 KB
large18 AC 3 ms
1,508 KB
large19 AC 3 ms
1,512 KB
large20 AC 3 ms
1,508 KB
sample1 AC 3 ms
1,512 KB
sample2 AC 3 ms
1,508 KB
sample3 AC 3 ms
1,508 KB
sample4 AC 4 ms
1,508 KB
sample5 AC 3 ms
1,512 KB
small1 AC 3 ms
1,512 KB
small2 AC 3 ms
1,512 KB
small3 AC 3 ms
1,508 KB
small4 AC 3 ms
1,508 KB
small5 AC 3 ms
1,508 KB
small6 AC 3 ms
1,508 KB
small7 AC 4 ms
1,504 KB
small8 AC 3 ms
1,508 KB
small9 AC 3 ms
1,512 KB
small10 AC 3 ms
1,508 KB
small11 AC 3 ms
1,508 KB
small12 AC 3 ms
1,508 KB
small13 AC 3 ms
1,512 KB
small14 AC 3 ms
1,508 KB
small15 AC 3 ms
1,512 KB
テストケース一括ダウンロード

ソースコード

diff #
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define ef else if

const int MOD = 1'000'000'007;
LL p[] = { 1, 2, 48, 1935360, 187767522, 588272078, 968309376, 754829929, 796867150, 94305900, 797182173, 825553566, 800802892, 622822155, 398493013, 843531154, 634777479, 233483695, 319671727, 608676892 };
LL x[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288 };
LL y[] = { 1, 500000004, 250000002, 125000001, 562500004, 281250002, 140625001, 570312504, 285156252, 142578126, 71289063, 535644535, 767822271, 883911139, 941955573, 970977790, 485488895, 742744451, 871372229, 935686118 };
LL z[] = { 0, 1, 333333336, 142857144, 466666670, 129032259, 15873016, 480314964, 556862749, 344422703, 94819160, 974596978, 492551896, 527652305, 840932680, 403149513, 243411919, 219232326, 372991080, 254269133 };

int main() {
	int d, l, r, k;
	scanf("%d%d%d%d", & d, & l, & r, & k);
	l = 32 - __builtin_clz(l) - 1;
	r = 32 - __builtin_clz(r) - 1;
	
	LL ans = 0;
	if(r - l <= k && k <= l + r && (l + r + k) % 2 == 0) {
		ans = p[d - 1];
		int m = (l + r - k) / 2;
		if(l == r) { (ans *= x[r - m - 1] * z[r] % MOD) %= MOD; }
		ef(l == m) { (ans *= x[r - m - 0] * y[r] % MOD) %= MOD; }
		else       { (ans *= x[r - m - 1] * y[r] % MOD) %= MOD; }
	}
	printf("%lld\n", ans);
	
	return 0;
}
0