結果

問題 No.916 Encounter On A Tree
ユーザー face4
提出日時 2019-10-26 11:41:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 757 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 64,684 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-14 04:35:23
合計ジャッジ時間 2,917 ms
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 44 WA * 12
権限があれば一括ダウンロードができます

ソースコード

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;
}

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)) / (depl==depr?2:1) % 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