結果
| 問題 | 
                            No.916 Encounter On A Tree
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tekihei2317
                         | 
                    
| 提出日時 | 2019-10-29 21:22:59 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 7 ms / 2,000 ms | 
| コード長 | 1,237 bytes | 
| コンパイル時間 | 1,548 ms | 
| コンパイル使用メモリ | 169,096 KB | 
| 実行使用メモリ | 7,424 KB | 
| 最終ジャッジ日時 | 2024-09-14 21:36:48 | 
| 合計ジャッジ時間 | 3,252 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 56 | 
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
const int mod=1e9+7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d,l,r,k; cin>>d>>l>>r>>k;
    if(l>r) swap(l,r);
    l=32-__builtin_clz(l)-1;
    r=32-__builtin_clz(r)-1;
    int lca=-1;
    if(l+r-k>=0 and (l+r-k)%2==0) lca=(l+r-k)/2;
    if(lca==-1 or lca>l or lca>r){
        cout<<0<<endl;
        return 0;
    }
    // cout<<l<<' '<<r<<' '<<lca<<endl;
    vector<int> pow2(d);
    pow2[0]=1;
    for(int i=1;i<d;i++) pow2[i]=pow2[i-1]*2%mod;
    vector<int> fact((1<<(d-1))+1);
    fact[0]=1;
    for(int i=1;i<=1<<(d-1);i++) fact[i]=fact[i-1]*i%mod;
    int ans=1;
    if(lca==l){
        ans=ans*pow2[lca]%mod;
        ans=ans*pow2[r-lca];
    }else{
        ans=ans*pow2[lca]%mod;
        ans=ans*pow2[l-lca]%mod;
        ans=ans*pow2[r-lca-1]%mod;
    }
    // cout<<ans<<endl;
    for(int i=0;i<d;i++){
        int cnt=1<<i;
        if(i==l) cnt--;
        if(i==r) cnt--;
        ans=ans*fact[cnt]%mod;
    }
    cout<<ans<<endl;
    return 0;
}
            
            
            
        
            
tekihei2317