結果

問題 No.916 Encounter On A Tree
ユーザー onigawara_kypronigawara_kypr
提出日時 2019-10-28 04:16:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 2,024 bytes
コンパイル時間 1,700 ms
コンパイル使用メモリ 102,824 KB
実行使用メモリ 11,456 KB
最終ジャッジ日時 2023-10-12 23:01:25
合計ジャッジ時間 3,141 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 11 ms
11,272 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 10 ms
11,260 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 11 ms
11,340 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 5 ms
5,136 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 11 ms
11,260 KB
testcase_14 AC 1 ms
4,356 KB
testcase_15 AC 11 ms
11,256 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 11 ms
11,268 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 11 ms
11,284 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 11 ms
11,260 KB
testcase_22 AC 1 ms
4,356 KB
testcase_23 AC 11 ms
11,284 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 11 ms
11,276 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 7 ms
7,172 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 10 ms
11,268 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 1 ms
4,356 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 5 ms
5,204 KB
testcase_35 AC 3 ms
4,364 KB
testcase_36 AC 11 ms
11,336 KB
testcase_37 AC 10 ms
11,456 KB
testcase_38 AC 5 ms
5,188 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 11 ms
11,352 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 1 ms
4,352 KB
testcase_44 AC 2 ms
4,352 KB
testcase_45 AC 3 ms
4,352 KB
testcase_46 AC 2 ms
4,352 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,372 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 1 ms
4,352 KB
testcase_52 AC 1 ms
4,352 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 1 ms
4,352 KB
testcase_57 AC 1 ms
4,348 KB
testcase_58 AC 2 ms
4,352 KB
testcase_59 AC 2 ms
4,352 KB
testcase_60 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll pow2(ll i) {
    if (i==0) return 1;
    else {
        ll tmp = pow2(i/2);
        if (i&1) return ((tmp*tmp)%MOD)*2%MOD;
        else return tmp*tmp%MOD;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll d, l, r, k; cin >> d >> l >> r >> k;

    ll dl=0, dr=0;
    while ((l>>=1)!=0) dl++;
    while ((r>>=1)!=0) dr++;
    
    ll lca;
    if (dl+dr < k || (k-(dr-dl))%2==1 || (dr-dl) > k) {
        cout << 0 << '\n';
        return 0;
    } else {
        lca = (k-(dr-dl))/2;
    }
    cerr << dl << ' ' << dr << ' ' << lca << '\n';

    vll fac((1<<d), 1);
    rep(i, 1, (1<<d)) fac[i] = fac[i-1]*i%MOD;

    ll ans=1;
    REP(i, d) {
        ll tmp = pow2(i);
        if (i==dl) tmp--;
        if (i==dr) tmp--;
        ans = ans * fac[tmp] % MOD;
    }

    ans = ans*pow2(dl-lca)%MOD;  // lca
    ans = ans*pow2(lca)%MOD;  // left
    if (dr==dl) {
        ans = ans*pow2(lca+dr-dl-1)%MOD;  // right
    } else if (dr-dl==k) {
        ans = ans*pow2(lca+dr-dl)%MOD;  // right
    } else {
        ans = ans*pow2(lca+dr-dl-1)%MOD;  // right
    }
    cout << ans << '\n';
    return 0;
}
0