結果

問題 No.916 Encounter On A Tree
ユーザー chocoruskchocorusk
提出日時 2019-10-25 21:55:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,967 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 109,192 KB
実行使用メモリ 24,132 KB
最終ジャッジ日時 2023-10-01 01:34:34
合計ジャッジ時間 3,540 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,580 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 18 ms
23,860 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
5,592 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 18 ms
23,824 KB
testcase_14 WA -
testcase_15 AC 18 ms
23,996 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 18 ms
23,744 KB
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 WA -
testcase_26 AC 1 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1 ms
4,380 KB
testcase_40 WA -
testcase_41 AC 2 ms
5,592 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,376 KB
testcase_45 WA -
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
5,516 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
5,516 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 2 ms
5,444 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[5000001], invf[5000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
int main()
{
	int d, l, r, k;
    cin>>d>>l>>r>>k;
    int dl=0, dr=0;
    int l1=l, r1=r;
    while(l1){
        dl++;
        l1>>=1;
    }
    while(r1){
        dr++;
        r1>>=1;
    }
    if((dl+dr)%2!=k%2 || dl+dr<k){
        cout<<0<<endl;
        return 0;
    }
    int dp=(dl+dr-k)/2;
    ll c[22]={};
    for(int i=min(dl, dr); i>=dp; i--){
        c[i]=(1ll<<(dl-i+dr-i))%MOD;
        for(int j=i+1; j<=min(dl, dr); j++){
            c[i]+=MOD-c[j];
            c[i]%=MOD;
        }
    }
    ll ans=c[dp];
    fac(1<<d);
    if(dl==dr){
        for(int i=1; i<=d; i++){
            if(i==dl){
                (ans*=f[(1<<(i-1))-2])%=MOD;
            }else{
                (ans*=f[(1<<(i-1))])%=MOD;
            }
        }
    }else{
        for(int i=1; i<=d; i++){
            if(i==dl || i==dr){
                (ans*=f[(1<<(i-1))-1])%=MOD;
            }else{
                (ans*=f[(1<<(i-1))])%=MOD;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
0