結果

問題 No.916 Encounter On A Tree
ユーザー ningenMeningenMe
提出日時 2019-03-20 16:45:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,612 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 63,668 KB
実行使用メモリ 19,632 KB
最終ジャッジ日時 2023-10-19 04:29:15
合計ジャッジ時間 2,600 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
19,632 KB
testcase_01 AC 9 ms
19,632 KB
testcase_02 AC 10 ms
19,632 KB
testcase_03 WA -
testcase_04 AC 10 ms
19,632 KB
testcase_05 WA -
testcase_06 AC 9 ms
19,632 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 9 ms
19,632 KB
testcase_11 WA -
testcase_12 AC 9 ms
19,632 KB
testcase_13 WA -
testcase_14 AC 9 ms
19,632 KB
testcase_15 WA -
testcase_16 AC 9 ms
19,632 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 9 ms
19,632 KB
testcase_21 WA -
testcase_22 AC 9 ms
19,632 KB
testcase_23 WA -
testcase_24 AC 9 ms
19,632 KB
testcase_25 WA -
testcase_26 AC 9 ms
19,632 KB
testcase_27 WA -
testcase_28 AC 10 ms
19,632 KB
testcase_29 WA -
testcase_30 AC 9 ms
19,632 KB
testcase_31 AC 9 ms
19,632 KB
testcase_32 AC 9 ms
19,632 KB
testcase_33 AC 9 ms
19,632 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 9 ms
19,632 KB
testcase_40 WA -
testcase_41 AC 10 ms
19,632 KB
testcase_42 AC 9 ms
19,632 KB
testcase_43 AC 9 ms
19,632 KB
testcase_44 AC 9 ms
19,632 KB
testcase_45 WA -
testcase_46 AC 10 ms
19,632 KB
testcase_47 WA -
testcase_48 AC 10 ms
19,632 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 9 ms
19,632 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

int main() {
	int d, l, r, k, MAX_d = 20;
	cin >> d >> l >> r >> k;
	vector<ll> pow2(MAX_d + 1, 1), sum(MAX_d + 1, 0), fac((1<<(MAX_d + 1)) + 1,1);
	//2冪を前計算
	for (int i = 2; i < MAX_d + 1; ++i) pow2[i] = pow2[i - 1] * 2;
	//2冪の和を前計算
	for (int i = 1; i < MAX_d + 1; ++i) sum[i] = sum[i - 1] + pow2[i];
	//階乗を前計算
	for (ll i = 1; i < (1 << MAX_d) + 1; ++i) fac[i] = (fac[i] * i) % MOD;
	//l,rを深さに変換
	l = lower_bound(sum.begin(), sum.end(), l) - sum.begin();
	r = lower_bound(sum.begin(), sum.end(), r) - sum.begin();

	int lca = -1;

	//lcaが存在するならそのlcaの深さを計算
	if ((l + r - k) > 1 && (l + r - k) % 2 == 0) lca = (l + r - k) / 2;

	//lcaが条件を満たしていない場合コーナー
	if(lca == -1 || lca > l || lca > r){
		cout << 0 << endl;
		return 0;
	}

	ll ans = 1;
	//上の段からl,r以外の頂点の順列の数え上げ
	for (int i = 1; i <= d; ++i) {
		ll cnt = pow2[i];
		if (i == l) cnt--;
		if (i == r) cnt--;
		(ans *= fac[cnt]) %= MOD;
	}
	
	//lcaとなるような頂点の位置についての数え上げ
	(ans *= pow2[lca]) %= MOD;
	//lcaを決め打ちした時のlの位置についての数え上げ
	(ans *= pow2[l - lca]) %= MOD;
	//lcaを決め打ちした時のrの位置についての数え上げ
	(ans *= pow2[r - lca]) %= MOD;
	//lcaについて、子は左右について2通りのパターンがあるため
	(ans *= 2) %= MOD;

	cout << ans << endl;
	return 0;
}

0