結果

問題 No.916 Encounter On A Tree
ユーザー fine
提出日時 2019-10-25 23:45:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 168,732 KB
実行使用メモリ 11,732 KB
最終ジャッジ日時 2024-09-13 09:48:51
合計ジャッジ時間 3,456 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll depth(ll x) {
    ll hoge = 1;
    ll ans = 0;
    while (x >= hoge) {
        ans++;
        hoge <<= 1;
    }
    return ans;
}

ll f[1 << 20];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll d, l, r, K;
    cin >> d >> l >> r >> K;
    ll ld = depth(l);
    ll rd = depth(r);
    ll hoge = rd - ld;
    ll maxk = hoge + 2 * (ld - 1);
    if (K == 0 || K < hoge || K > maxk || (K - hoge) % 2 == 1) {
        cout << 0 << "\n";
        return 0;
    }

    ll foo = (K - hoge + 1) / 2;
    foo = (foo >= 2 ? (1 << (foo - 1)) : 1);
    
    ll ans = foo * (1LL << (rd - 1)) % MOD;

    f[0] = 1;
    for (int i = 1; i < (1 << d); i++) {
        f[i] = f[i - 1] * i % MOD;
    }

    for (int i = 1; i <= d; i++) {
        (ans *= f[(1 << (i - 1)) - (i == ld) - (i == rd)]) %= MOD;
    }
    cout << ans << "\n";

    return 0;
}
0