結果
問題 | No.916 Encounter On A Tree |
ユーザー |
![]() |
提出日時 | 2020-03-31 18:04:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 1,042 bytes |
コンパイル時間 | 1,761 ms |
コンパイル使用メモリ | 166,796 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-24 22:01:57 |
合計ジャッジ時間 | 3,214 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; }