結果

問題 No.916 Encounter On A Tree
ユーザー risujirohrisujiroh
提出日時 2019-10-25 21:47:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 2,946 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 167,920 KB
実行使用メモリ 27,948 KB
最終ジャッジ日時 2023-09-30 22:05:29
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
27,848 KB
testcase_01 AC 34 ms
27,836 KB
testcase_02 AC 34 ms
27,456 KB
testcase_03 AC 34 ms
27,856 KB
testcase_04 AC 34 ms
27,352 KB
testcase_05 AC 34 ms
27,468 KB
testcase_06 AC 34 ms
27,296 KB
testcase_07 AC 34 ms
27,928 KB
testcase_08 AC 34 ms
27,832 KB
testcase_09 AC 34 ms
27,832 KB
testcase_10 AC 34 ms
27,308 KB
testcase_11 AC 35 ms
27,280 KB
testcase_12 AC 34 ms
27,300 KB
testcase_13 AC 34 ms
27,948 KB
testcase_14 AC 34 ms
27,384 KB
testcase_15 AC 34 ms
27,520 KB
testcase_16 AC 34 ms
27,456 KB
testcase_17 AC 35 ms
27,452 KB
testcase_18 AC 34 ms
27,452 KB
testcase_19 AC 34 ms
27,304 KB
testcase_20 AC 34 ms
27,832 KB
testcase_21 AC 34 ms
27,384 KB
testcase_22 AC 34 ms
27,352 KB
testcase_23 AC 35 ms
27,456 KB
testcase_24 AC 34 ms
27,280 KB
testcase_25 AC 34 ms
27,920 KB
testcase_26 AC 34 ms
27,456 KB
testcase_27 AC 34 ms
27,404 KB
testcase_28 AC 34 ms
27,404 KB
testcase_29 AC 35 ms
27,300 KB
testcase_30 AC 34 ms
27,380 KB
testcase_31 AC 35 ms
27,516 KB
testcase_32 AC 34 ms
27,456 KB
testcase_33 AC 35 ms
27,332 KB
testcase_34 AC 34 ms
27,280 KB
testcase_35 AC 34 ms
27,460 KB
testcase_36 AC 34 ms
27,388 KB
testcase_37 AC 34 ms
27,372 KB
testcase_38 AC 34 ms
27,304 KB
testcase_39 AC 35 ms
27,336 KB
testcase_40 AC 34 ms
27,288 KB
testcase_41 AC 34 ms
27,468 KB
testcase_42 AC 34 ms
27,460 KB
testcase_43 AC 34 ms
27,460 KB
testcase_44 AC 35 ms
27,920 KB
testcase_45 AC 34 ms
27,404 KB
testcase_46 AC 34 ms
27,452 KB
testcase_47 AC 34 ms
27,300 KB
testcase_48 AC 34 ms
27,304 KB
testcase_49 AC 34 ms
27,456 KB
testcase_50 AC 35 ms
27,460 KB
testcase_51 AC 34 ms
27,288 KB
testcase_52 AC 35 ms
27,408 KB
testcase_53 AC 34 ms
27,832 KB
testcase_54 AC 34 ms
27,800 KB
testcase_55 AC 34 ms
27,280 KB
testcase_56 AC 34 ms
27,296 KB
testcase_57 AC 34 ms
27,384 KB
testcase_58 AC 34 ms
27,288 KB
testcase_59 AC 34 ms
27,456 KB
testcase_60 AC 33 ms
27,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  constexpr ModInt() : v(0) {}
  constexpr ModInt(unsigned _v, int) : v(_v) {}
  template<class Z> ModInt(const Z& a) : v((a < 0 ? P - -a % P : a) % P) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  friend M operator*(M l, M r) { return M(l) *= r; }
  friend M operator/(M l, M r) { return M(l) /= r; }
  friend M operator+(M l, M r) { return M(l) += r; }
  friend M operator-(M l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
  friend bool operator!=(M l, M r) { return !(l == r); }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  template<class Z> M pow(Z n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
};
using Mint = ModInt<(unsigned)1e9 + 7>;
constexpr int N = 1 << 21;
struct Fact {
  V<Mint> v;
  Fact(int n) : v(n + 1, 1) {
    for (int i = 1; i <= n; ++i) v[i] = i * v[i - 1];
  }
  Mint operator[](int i) const { return v[i]; }
} fact(N);
struct Finv {
  V<Mint> v;
  Finv(int n) : v(n + 1, 1 / fact[n]) {
    for (int i = n; i; --i) v[i - 1] = i * v[i];
  }
  Mint operator[](int i) const { return v[i]; }
} finv(N);
struct Minv {
  V<Mint> v;
  Minv(int n) : v(n) {
    for (int i = 1; i <= n; ++i) v[i - 1] = fact[i - 1] * finv[i];
  }
  Mint operator[](int i) const { return v[i - 1]; }
} minv(N);
Mint comb(int n, int r) {
  if (r < 0 or r > n) return 0;
  return fact[n] * finv[r] * finv[n - r];
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int d, l, r, k; cin >> d >> l >> r >> k;
  l = __lg(l);
  r = __lg(r);
  if (l > r) swap(l, r);
  if (k < r - l or k > l + r or (k - (r - l)) & 1) {
    return cout << 0 << '\n', 0;
  }
  cerr << d << ' ' << l << ' ' << r << ' ' << k << '\n';
  Mint res = 1;
  for (int i = 0; i < d; ++i) {
    res *= fact[1 << i];
  }
  k = (k - (r - l)) / 2;
  k = max(k - 1, 0);
  if (l == r) {
    res *= minv[(1 << l) - 1];
    res *= 1 << k;
  } else {
    res *= minv[1 << l];
    res *= 1 << k;
  }
  cout << res << '\n';
}
0