結果

問題 No.916 Encounter On A Tree
ユーザー tekihei2317tekihei2317
提出日時 2019-10-29 21:32:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 167,252 KB
実行使用メモリ 7,304 KB
最終ジャッジ日時 2023-10-12 23:32:00
合計ジャッジ時間 3,938 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 7 ms
7,208 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 6 ms
7,092 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 7 ms
7,164 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
7,136 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 6 ms
7,244 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 7 ms
7,092 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 7 ms
7,304 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 6 ms
7,296 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 7 ms
7,092 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 7 ms
7,228 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 5 ms
5,200 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 6 ms
7,220 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 6 ms
7,140 KB
testcase_37 AC 7 ms
7,100 KB
testcase_38 AC 3 ms
4,352 KB
testcase_39 AC 1 ms
4,352 KB
testcase_40 AC 6 ms
7,216 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 1 ms
4,352 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 1 ms
4,352 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 1 ms
4,352 KB
testcase_59 AC 2 ms
4,352 KB
testcase_60 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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> 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*(1<<lca)%mod;
        ans=ans*(1<<(r-lca))%mod;
    }else{
        ans=ans*(1<<lca)%mod;
        ans=ans*(1<<(l-lca))%mod;
        ans=ans*(1<<(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;
}
0