結果

問題 No.916 Encounter On A Tree
ユーザー chocoruskchocorusk
提出日時 2019-10-25 22:04:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 2,125 bytes
コンパイル時間 2,729 ms
コンパイル使用メモリ 110,720 KB
実行使用メモリ 24,072 KB
最終ジャッジ日時 2023-10-11 04:22:06
合計ジャッジ時間 5,279 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,544 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 18 ms
23,808 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 17 ms
23,792 KB
testcase_06 AC 18 ms
23,932 KB
testcase_07 AC 18 ms
23,788 KB
testcase_08 AC 4 ms
6,408 KB
testcase_09 AC 7 ms
11,628 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
5,480 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 18 ms
24,020 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 18 ms
23,784 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 18 ms
23,788 KB
testcase_18 AC 2 ms
5,396 KB
testcase_19 AC 18 ms
24,072 KB
testcase_20 AC 18 ms
23,848 KB
testcase_21 AC 18 ms
23,800 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 18 ms
23,792 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 18 ms
23,912 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 11 ms
15,724 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 18 ms
23,848 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 7 ms
11,576 KB
testcase_35 AC 4 ms
6,468 KB
testcase_36 AC 18 ms
24,024 KB
testcase_37 AC 18 ms
23,876 KB
testcase_38 AC 7 ms
11,512 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 18 ms
23,852 KB
testcase_41 AC 2 ms
5,704 KB
testcase_42 AC 2 ms
5,388 KB
testcase_43 AC 2 ms
5,364 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 4 ms
6,476 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 2 ms
5,444 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 2 ms
5,456 KB
testcase_50 AC 2 ms
5,364 KB
testcase_51 AC 2 ms
5,428 KB
testcase_52 AC 2 ms
5,472 KB
testcase_53 AC 2 ms
5,536 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 2 ms
5,444 KB
testcase_56 AC 2 ms
5,616 KB
testcase_57 AC 2 ms
5,568 KB
testcase_58 AC 2 ms
5,452 KB
testcase_59 AC 3 ms
5,604 KB
testcase_60 AC 3 ms
5,628 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    }
    dl--; dr--;
    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--){
        if(dl!=dr) c[i]=(1ll<<(dl-i+dr-i))%MOD;
        else{
            ll x=(1<<(dl-i));
            c[i]=x*(x-1)%MOD;
        }
        (c[i]*=(1ll<<i))%=MOD;
        for(int j=i+1; j<=min(dl, dr); j++){
            c[i]+=MOD-c[j];
            c[i]%=MOD;
        }
      //cout<<c[i]<<" "<<i<<endl;
    }
    ll ans=c[dp];
    fac(1<<d);
    if(dl==dr){
        for(int i=0; i<d; i++){
            if(i==dl){
                (ans*=f[(1<<i)-2])%=MOD;
            }else{
                (ans*=f[(1<<i)])%=MOD;
            }
        }
    }else{
        for(int i=0; i<d; i++){
            if(i==dl || i==dr){
                (ans*=f[(1<<i)-1])%=MOD;
            }else{
                (ans*=f[(1<<i)])%=MOD;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
0