結果

問題 No.916 Encounter On A Tree
ユーザー rpy3cpprpy3cpp
提出日時 2019-11-17 01:33:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,779 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 167,688 KB
実行使用メモリ 11,832 KB
最終ジャッジ日時 2023-10-25 10:45:21
合計ジャッジ時間 3,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

constexpr long long mod = 1e9+7;
long long fac[1 << 20];

void fill_fac(){
    fac[0] = 1;
    for (int i = 1; i < (1 << 20); ++i){
        fac[i] = fac[i - 1] * i % mod;
    }
}

int find_depth(int x){
    int d = 1;
    while (x > (1 << (d - 1))){
        x -= 1 << (d - 1);
        ++d;
    }
    return d;
}

int solve_core(int d, int dr, int dl, int k){
    int s = (k - (dr - dl)) / 2;
    long long ans = 0;
    if (s == 0){
        if (dl == dr) return 0;
        ans = (1 << (dr - dl)) % mod;
        ans = ans * fac[(1 << (dr - 1)) - 1] % mod;
        for (int i = 1; i <= d; ++i){
            if (i == dr) continue;
            ans = ans * fac[1 << (i - 1)] % mod;
        }
        return ans;
    }else if (dl == dr){
        ans = 1 << (dl - 1);
        ans = ans * (1 << (s - 1)) % mod;
        ans = ans * fac[(1 << (dl - 1)) - 2] % mod;
        for (int i = 1; i <= d; ++i){
            if (i == dl) continue;
            ans = ans * fac[1 << (i - 1)] % mod;
        }
        return ans;
    }else{
        ans = 1 << (s - 1);
        ans = ans * fac[(1 << (dl - 1)) - 1] % mod;
        for (int i = 1; i <= d; ++i){
            if (i == dl) continue;
            ans = ans * fac[1 << (i - 1)] % mod;
        }
        return ans;
    }
}

int solve(int d, int l, int r, int k){
    int dl = find_depth(l);
    int dr = find_depth(r);
    if (dr - dl > k){
        return 0;
    }else if (dl + dr < k){
        return 0;
    }else if ((k - (dr - dl)) % 2){
        return 0;
    }else if ((k - (dr - dl)) / 2 > dl - 1){
        return 0;
    }
    return solve_core(d, dl, dr, k);
}

int main(){
    fill_fac();
    int d, l, r, k;
    cin >> d >> l >> r >> k;
    cout << solve(d, l, r, k) << endl;
    return 0;
}
0