結果

問題 No.916 Encounter On A Tree
ユーザー auaua
提出日時 2019-10-25 23:18:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,130 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 160,396 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 08:44:32
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 WA * 1
other AC * 35 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll depth(ll a){
    ll cnt=0;
    while(a){
        cnt++;
        a/=2;
    }
    return cnt;
}
ll e(ll d){
    ll res=1;
    ll s=d;
    while(s>0){
        s--;
        res*=2;
        res%=inf;
    }
    return res;
}
int main(){
    ll d,l,r,k;cin>>d>>l>>r>>k;
    ll ans=1;
    if((depth(l)+depth(r)-k)%2||depth(l)+depth(r)-k<=0){
        cout<<0<<endl;
        return 0;
    }
    ll anc=(depth(l)+depth(r)-k)/2;
    ans*=e(depth(r)-anc-1);
    ans%=inf;
    if(depth(l)>anc)ans*=e(depth(l)-anc-1);
    ans%=inf;
    ans*=2;
    ans%=inf;
    ll f=0;
    rep(i,d){
        k=e(i);
        if(depth(l)!=anc&&i==depth(l)-1)k--;
        if(i==depth(r)-1)k--;
        while(k>1){
            ans*=k;
            ans%=inf;
            k--;
        }
    }
    cout<<ans<<endl;
}
0