結果

問題 No.916 Encounter On A Tree
ユーザー batsumarubatsumaru
提出日時 2019-10-25 23:13:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,150 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 166,996 KB
実行使用メモリ 15,972 KB
最終ジャッジ日時 2023-10-11 09:15:13
合計ジャッジ時間 4,100 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 13 ms
15,652 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 13 ms
15,640 KB
testcase_08 AC 12 ms
15,628 KB
testcase_09 AC 13 ms
15,712 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 12 ms
15,632 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 12 ms
15,704 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 13 ms
15,640 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 13 ms
15,640 KB
testcase_19 AC 12 ms
15,696 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 WA -
testcase_22 AC 2 ms
4,352 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 13 ms
15,696 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 13 ms
15,656 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 12 ms
15,840 KB
testcase_35 AC 12 ms
15,684 KB
testcase_36 AC 12 ms
15,624 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 13 ms
15,636 KB
testcase_41 AC 12 ms
15,700 KB
testcase_42 AC 12 ms
15,692 KB
testcase_43 AC 12 ms
15,836 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 12 ms
15,632 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 12 ms
15,848 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 13 ms
15,648 KB
testcase_50 AC 12 ms
15,636 KB
testcase_51 AC 12 ms
15,688 KB
testcase_52 WA -
testcase_53 AC 11 ms
15,648 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 12 ms
15,704 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 12 ms
15,648 KB
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void no() {
  cout << 0 << endl;
  exit(0);
}

ll modpow(ll a, ll b, ll m) {
  if (b == 0) return 1;
  ll ret;
  if (b % 2 == 0) {
    ll t = modpow(a, b / 2, m) % m;
    ret = t * t % m;
  } else {
    ll t = modpow(a, (b - 1) / 2, m) % m;
    ret = a * t % m * t % m;
  }
  ret %= m;
  return ret;
}

/* 二項係数 C(n,k) mod p を計算 */
const int MOD = 1000000007;
const int MAX = (1 << 19) + 10;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll d, l, r, k;
  cin >> d >> l >> r >> k;
  // l,rの深さ(0-indexed)を求める
  auto depth = [](ll x) {
    ll res = 0, cur = 2;
    while (1) {
      if (x < cur) return res;
      res++;
      cur *= 2;
    }
  };
  ll dl = depth(l), dr = depth(r);
  // DUMP(dl);
  // DUMP(dr);
  if (dl + dr < k) no();
  if ((-k + dl + dr) % 2 == 1) no();
  ll da = (-k + dl + dr) / 2;  // l,rの最近共通祖先の深さ
  // DUMP(da);
  if (da > dl) no();
  if (dr == da) no();
  ll ans;
  if (dl == 0) {
    ans = modpow(2, dr, MOD);
  } else if (dl == dr) {
    ans = modpow(2, 2 * dl - da - 1, MOD);
  } else if (da == dl) {
    ans = modpow(2, dr, MOD);
  } else {
    ans = modpow(2, dr - da, MOD) * ((modpow(2, dl, MOD) - 1 + MOD) % MOD);
  }

  COMinit();
  REP(i, d) {
    ll dec = (dl == i) + (dr == i);
    (ans *= fac[(1 << i) - dec]) %= MOD;
  }
  cout << ans << endl;
}
0