結果

問題 No.916 Encounter On A Tree
ユーザー tko919tko919
提出日時 2019-10-26 18:29:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 3,126 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 169,220 KB
実行使用メモリ 19,604 KB
最終ジャッジ日時 2023-10-12 16:33:22
合計ジャッジ時間 7,704 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
19,292 KB
testcase_01 AC 53 ms
19,296 KB
testcase_02 AC 53 ms
19,448 KB
testcase_03 AC 53 ms
19,460 KB
testcase_04 AC 53 ms
19,404 KB
testcase_05 AC 53 ms
19,316 KB
testcase_06 AC 54 ms
19,456 KB
testcase_07 AC 53 ms
19,408 KB
testcase_08 AC 53 ms
19,516 KB
testcase_09 AC 54 ms
19,412 KB
testcase_10 AC 53 ms
19,412 KB
testcase_11 AC 53 ms
19,464 KB
testcase_12 AC 53 ms
19,364 KB
testcase_13 AC 53 ms
19,448 KB
testcase_14 AC 53 ms
19,452 KB
testcase_15 AC 53 ms
19,512 KB
testcase_16 AC 53 ms
19,300 KB
testcase_17 AC 53 ms
19,340 KB
testcase_18 AC 52 ms
19,292 KB
testcase_19 AC 53 ms
19,300 KB
testcase_20 AC 52 ms
19,416 KB
testcase_21 AC 52 ms
19,524 KB
testcase_22 AC 52 ms
19,452 KB
testcase_23 AC 52 ms
19,516 KB
testcase_24 AC 52 ms
19,312 KB
testcase_25 AC 52 ms
19,296 KB
testcase_26 AC 52 ms
19,456 KB
testcase_27 AC 52 ms
19,404 KB
testcase_28 AC 53 ms
19,516 KB
testcase_29 AC 53 ms
19,520 KB
testcase_30 AC 53 ms
19,416 KB
testcase_31 AC 52 ms
19,508 KB
testcase_32 AC 53 ms
19,456 KB
testcase_33 AC 53 ms
19,420 KB
testcase_34 AC 54 ms
19,412 KB
testcase_35 AC 53 ms
19,596 KB
testcase_36 AC 52 ms
19,532 KB
testcase_37 AC 53 ms
19,528 KB
testcase_38 AC 52 ms
19,448 KB
testcase_39 AC 54 ms
19,304 KB
testcase_40 AC 53 ms
19,596 KB
testcase_41 AC 54 ms
19,464 KB
testcase_42 AC 53 ms
19,604 KB
testcase_43 AC 53 ms
19,300 KB
testcase_44 AC 53 ms
19,472 KB
testcase_45 AC 52 ms
19,364 KB
testcase_46 AC 53 ms
19,448 KB
testcase_47 AC 53 ms
19,416 KB
testcase_48 AC 53 ms
19,316 KB
testcase_49 AC 53 ms
19,296 KB
testcase_50 AC 53 ms
19,412 KB
testcase_51 AC 53 ms
19,520 KB
testcase_52 AC 53 ms
19,312 KB
testcase_53 AC 53 ms
19,356 KB
testcase_54 AC 53 ms
19,516 KB
testcase_55 AC 53 ms
19,452 KB
testcase_56 AC 52 ms
19,412 KB
testcase_57 AC 53 ms
19,296 KB
testcase_58 AC 53 ms
19,296 KB
testcase_59 AC 54 ms
19,336 KB
testcase_60 AC 53 ms
19,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end

ll mod=1e9+7;
struct Mint {
    ll val;
    Mint inv() const{
        ll tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x):val(x>=0?x%mod:x%mod+mod){}
    int mtoi(){return this->val; }
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this *= x.inv();}
    bool operator==(const Mint& x) const{return val == x.val;}
    bool operator!=(const Mint& x) const{return val != x.val;}
    bool operator<(const Mint& x) const{return val < x.val;}
    bool operator<=(const Mint& x) const{return val <= x.val;}
    bool operator>(const Mint& x) const{return val > x.val;}
    bool operator>=(const Mint& x) const{return val >= x.val;}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*Mint(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*Mint(i);
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

factorial fact(1050000);
Mint precalc[25];

int main(){
    int d,l,r,k; scanf("%d%d%d%d",&d,&l,&r,&k);
    int dl=0,dr=0;
    while(l>=1<<dl)dl++;
    while(r>=1<<dr)dr++;
    int lca=-1;
    if((dl+dr-k)>1&&((dl+dr-k)%2==0))lca=(dl+dr-k)/2;
    if(lca==-1||dl<lca||dr<lca){
        printf("0\n"); return 0;
    }
    Mint ans=1;
    rep(i,1,d+1){
        int sum=1<<(i-1);
        if(i==dl)sum--;
        if(i==dr)sum--;
        ans*=fact.fact(sum);
    }
    precalc[0]=1;
    rep(i,1,21)precalc[i]=Mint(2).pow(i-1);
    ans*=precalc[lca]*precalc[dl-lca]*precalc[dr-lca]*2;
    printf("%d\n",ans.mtoi());
    return 0;
}
0