結果
| 問題 |
No.916 Encounter On A Tree
|
| ユーザー |
QCFium
|
| 提出日時 | 2019-11-01 16:05:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,042 bytes |
| コンパイル時間 | 1,743 ms |
| コンパイル使用メモリ | 166,804 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 22:44:17 |
| 合計ジャッジ時間 | 3,773 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 56 |
ソースコード
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
#define MOD 1000000007
int solve() {
int d = ri();
int l = ri(), r = ri(), k = ri();
int l_depth = 0;
for (int cur = 2; cur <= l; cur <<= 1) l_depth++;
int r_depth = 0;
for (int cur = 2; cur <= r; cur <<= 1) r_depth++;
if (l_depth > r_depth) std::swap(l_depth, r_depth);
if (l_depth + r_depth < k) return 0;
if ((l_depth + r_depth - k) & 1) return 0;
if (k < r_depth - l_depth) return 0;
int lca_depth = (l_depth + r_depth - k) >> 1;
int res = 1;
for (int i = 0; i < d; i++) {
int num = 1 << i;
if (l_depth == i) num--;
if (r_depth == i) num--;
for (int j = 1; j <= num; j++) res = (int64_t) res * j % MOD;
}
for (int i = 0; i < lca_depth; i++) res = res * 2 % MOD;
l_depth -= lca_depth;
r_depth -= lca_depth;
if (!l_depth) for (int i = 0; i < r_depth; i++) res = res * 2 % MOD;
else {
for (int i = 0; i < l_depth + r_depth - 1; i++) res = res * 2 % MOD;
}
return res;
}
int main() {
std::cout << solve() << std::endl;
return 0;
}
QCFium