結果

問題 No.916 Encounter On A Tree
ユーザー yakkiyakki
提出日時 2019-11-01 16:00:06
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,825 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 86,512 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2023-10-13 00:50:00
合計ジャッジ時間 6,901 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,088 KB
testcase_01 AC 7 ms
8,276 KB
testcase_02 AC 6 ms
8,088 KB
testcase_03 RE -
testcase_04 AC 7 ms
8,012 KB
testcase_05 RE -
testcase_06 AC 7 ms
8,016 KB
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 7 ms
8,144 KB
testcase_11 WA -
testcase_12 AC 7 ms
8,292 KB
testcase_13 RE -
testcase_14 AC 6 ms
8,036 KB
testcase_15 RE -
testcase_16 AC 7 ms
8,092 KB
testcase_17 RE -
testcase_18 AC 6 ms
8,692 KB
testcase_19 RE -
testcase_20 AC 7 ms
8,056 KB
testcase_21 RE -
testcase_22 AC 7 ms
8,012 KB
testcase_23 RE -
testcase_24 AC 7 ms
8,012 KB
testcase_25 RE -
testcase_26 AC 7 ms
8,040 KB
testcase_27 RE -
testcase_28 AC 7 ms
8,112 KB
testcase_29 RE -
testcase_30 AC 7 ms
8,060 KB
testcase_31 AC 6 ms
8,144 KB
testcase_32 AC 7 ms
8,240 KB
testcase_33 AC 6 ms
8,092 KB
testcase_34 AC 6 ms
8,464 KB
testcase_35 AC 6 ms
8,360 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 6 ms
8,372 KB
testcase_39 AC 6 ms
8,032 KB
testcase_40 RE -
testcase_41 WA -
testcase_42 AC 7 ms
8,116 KB
testcase_43 AC 7 ms
8,120 KB
testcase_44 AC 7 ms
8,008 KB
testcase_45 AC 6 ms
8,372 KB
testcase_46 AC 6 ms
8,036 KB
testcase_47 WA -
testcase_48 AC 6 ms
8,032 KB
testcase_49 WA -
testcase_50 AC 6 ms
8,368 KB
testcase_51 WA -
testcase_52 AC 6 ms
8,372 KB
testcase_53 WA -
testcase_54 AC 6 ms
8,052 KB
testcase_55 AC 7 ms
8,356 KB
testcase_56 AC 7 ms
8,372 KB
testcase_57 AC 6 ms
8,472 KB
testcase_58 WA -
testcase_59 AC 6 ms
8,364 KB
testcase_60 AC 7 ms
8,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

#define MAX 200000
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    repr(i,2,MAX){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}


int main(){
    COMinit();
    int d,l,r,k; cin >> d >> l >> r >> k;
    int l_2 = 0;
    int r_2 = 0;
    rep(i,2){
        int s;
        if(i == 0) s = l;
        else s = r;
        while(s > 1){
            s /= 2;
            if(i == 0) l_2++;
            else r_2++;
        }
    }
    bool ok = false;
    for(int i = abs(l_2-r_2); i <= l_2+r_2; i+=2){
        if(i == k) ok = true;
    }
    if(!ok){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    rep(i,d){
        if(i != l_2 && i != r_2){
            ans *= fac[(int)pow(2,i)];
            ans %= MOD;
        }
    }
    int t = (k-abs(l_2-r_2))/2;
    int m = pow(2,t-1);
    ans *= (ll)pow(2,max(l_2,r_2))*m;
    ans %= MOD;
    if(l_2 == r_2){
        ans *= fac[(int)pow(2,r_2)-2];
        ans %= MOD;
    }
    else{
        ans *= fac[(int)pow(2,l_2)-1];
        ans %= MOD;
        ans *= fac[(int)pow(2,r_2)-1];
        ans %= MOD;
    }
    cout << ans << endl;
}
0