結果
問題 | No.916 Encounter On A Tree |
ユーザー |
![]() |
提出日時 | 2019-10-25 22:04:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,360 bytes |
コンパイル時間 | 693 ms |
コンパイル使用メモリ | 57,196 KB |
実行使用メモリ | 34,780 KB |
最終ジャッジ日時 | 2024-09-13 03:52:21 |
合計ジャッジ時間 | 4,216 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 3 |
other | AC * 34 WA * 22 |
ソースコード
#include <iostream>#define llint long long#define mod 1000000007using namespace std;llint d, l, r, k;const int FACT_MAX = 2000005;llint fact[FACT_MAX], fact_inv[FACT_MAX];llint modpow(llint a, llint n){if(n == 0) return 1;if(n % 2){return ((a%mod) * (modpow(a, n-1)%mod)) % mod;}else{return modpow((a*a)%mod, n/2) % mod;}}void make_fact(){llint val = 1;fact[0] = 1;for(int i = 1; i < FACT_MAX; i++){val *= i;val %= mod;fact[i] = val;}fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);for(int i = FACT_MAX-2; i >= 0; i--){fact_inv[i] = fact_inv[i+1] * (i+1) % mod;}}llint get(llint x){llint ret = 0;for(;x;x/=2) ret++;return ret;}int main(void){ios::sync_with_stdio(0);cin.tie(0);cin >> d >> l >> r >> k;make_fact();llint ans = 1;for(int i = 1; i <= d; i++) ans *= fact[1<<(i-1)], ans %= mod;//cout << ans << endl;llint dl = get(l), dr = get(r);if((dl+dr-k) % 2){cout << 0 << endl;return 0;}llint da = (dl+dr-k) / 2, f = dr - da;if(da > min(dl, dr) || da < 1){cout << 0 << endl;return 0;}//cout << dl << " " << dr << " " << da << endl;if(dl != dr) ans *= 1<<f, ans %= mod, ans *= modpow(1<<(dr-1), mod-2), ans %= mod;else ans *= 1<<f, ans %= mod, ans *= modpow((1<<(dr-1))-1, mod-2), ans %= mod;cout << ans << endl;return 0;}