結果

問題 No.916 Encounter On A Tree
ユーザー kotamanegikotamanegi
提出日時 2019-10-25 22:42:01
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,912 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 111,432 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 13:20:05
合計ジャッジ時間 4,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
long long depth(long long now) {
	long long ans = 0;
	while (now != 0) {
		now /= 2;
		ans++;
	}
	return ans;
}
long long inv(long long now) {
	long long b = MAX_MOD - 2;
	long long ans = 1;
	while (b != 0) {
		if (b % 2) {
			ans *= now;
			ans %= MAX_MOD;
		}
		now *= now;
		now %= MAX_MOD;
		b /= 2;
	}
	return ans;
}
int main() {
	long long d, l, r, k;
	cin >> d >> l >> r >> k;
	k -= depth(r) - depth(l);
	int target = k / 2;
	if (k % 2 == 1 || depth(l) - target < 1||k < 0||(depth(l) == depth(r)&&k == 0)) {
		cout << 0 << endl;
		return 0;
	}
	long long ans = 1;
	for (long long i = 2; i <= d; ++i) {
		for (long long q = 1; q <= (1LL << (i - 1)); ++q) {
			ans *= q;
			ans %= MAX_MOD;
		}
	}
	if (depth(l) != depth(r)) {
		long long hoge = depth(l) - max(target - 1, 0) - 1;
		ans *= inv((1LL << hoge) % MAX_MOD);
	}
	else {
		long long hoge = (1LL << (depth(l) - 1)) - 1;
		ans *= inv(hoge);
		ans %= MAX_MOD;
		ans *= (1LL << (target - 1));
	}
	cout << ans%MAX_MOD << endl;
}
0