結果
| 問題 |
No.916 Encounter On A Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-25 22:24:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,135 bytes |
| コンパイル時間 | 1,609 ms |
| コンパイル使用メモリ | 167,420 KB |
| 実行使用メモリ | 11,724 KB |
| 最終ジャッジ日時 | 2024-09-13 04:30:15 |
| 合計ジャッジ時間 | 3,272 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 37 WA * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
ll modpow(ll x, ll n, ll mod = MOD) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll depth(ll x) {
ll hoge = 1;
ll ans = 0;
while (x >= hoge) {
ans++;
hoge <<= 1;
}
return ans;
}
ll f[1 << 20];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll d, l, r, K;
cin >> d >> l >> r >> K;
ll ld = depth(l);
ll rd = depth(r);
ll hoge = rd - ld;
ll maxk = hoge + (ld >= 2) * 2 + max((1LL << (ld - 1)) - 2, 0LL);
if (K < hoge || K > maxk || (K - hoge) % 2 == 1) {
cout << 0 << "\n";
return 0;
}
ll foo = (K - hoge) / 2;
foo = (foo >= 2 ? 2 : 1);
ll ans = foo * (1LL << (rd - 1)) % MOD;
f[0] = 1;
for (int i = 1; i < (1 << d); i++) {
f[i] = f[i - 1] * i % MOD;
}
for (int i = 1; i <= d; i++) {
(ans *= f[(1 << (i - 1)) - (i == ld) - (i == rd)]) %= MOD;
}
cout << ans << "\n";
return 0;
}