結果

問題 No.916 Encounter On A Tree
ユーザー face4
提出日時 2019-10-26 11:49:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,002 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 65,408 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 04:43:11
合計ジャッジ時間 2,116 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

typedef long long ll;
const int mod = 1000000007;

int f(int x){
    int ret = 0;
    while(x)    ret++, x>>=1;
    return ret;
}

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int d, l, r, k;
    cin >> d >> l >> r >> k;
    int depl = f(l), depr = f(r);
    if(abs(depl-depr) > k || abs(depl-depr)%2 != k%2 || depl-1+depr-1 < k){
        cout << 0 << endl;
        return 0;
    }
    int deplca = min(depl,depr)-(k-abs(depl-depr))/2;
    ll ans = (1ll<<(depr-deplca)) * (1<<(depl-deplca)) %mod * modpow((depl==deplca||depr==deplca)?1:2,mod-2) % mod;
    ans *= 1<<(deplca-1);
    ans %= mod;
    for(int i = 1; i <= d; i++){
        int tmp = 1<<(i-1);
        tmp -= (i==depl) + (i==depr);
        while(tmp)  ans = ans*tmp--%mod;
    }
    cout << ans << endl;
    return 0;
}
0