結果

問題 No.916 Encounter On A Tree
ユーザー kk
提出日時 2021-01-20 18:09:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,504 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 201,300 KB
実行使用メモリ 10,956 KB
最終ジャッジ日時 2023-08-24 21:56:44
合計ジャッジ時間 5,094 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,852 KB
testcase_01 AC 10 ms
10,808 KB
testcase_02 AC 10 ms
10,740 KB
testcase_03 AC 10 ms
10,772 KB
testcase_04 AC 10 ms
10,748 KB
testcase_05 AC 10 ms
10,848 KB
testcase_06 AC 10 ms
10,760 KB
testcase_07 AC 10 ms
10,788 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 10 ms
10,816 KB
testcase_11 AC 10 ms
10,764 KB
testcase_12 AC 10 ms
10,808 KB
testcase_13 AC 10 ms
10,832 KB
testcase_14 AC 10 ms
10,724 KB
testcase_15 AC 10 ms
10,756 KB
testcase_16 AC 10 ms
10,840 KB
testcase_17 AC 10 ms
10,712 KB
testcase_18 AC 10 ms
10,752 KB
testcase_19 AC 10 ms
10,712 KB
testcase_20 AC 10 ms
10,812 KB
testcase_21 AC 10 ms
10,768 KB
testcase_22 AC 10 ms
10,696 KB
testcase_23 AC 10 ms
10,840 KB
testcase_24 AC 10 ms
10,748 KB
testcase_25 AC 10 ms
10,844 KB
testcase_26 AC 9 ms
10,756 KB
testcase_27 AC 10 ms
10,704 KB
testcase_28 AC 10 ms
10,792 KB
testcase_29 AC 10 ms
10,744 KB
testcase_30 AC 10 ms
10,768 KB
testcase_31 AC 10 ms
10,852 KB
testcase_32 AC 10 ms
10,740 KB
testcase_33 AC 10 ms
10,956 KB
testcase_34 AC 10 ms
10,764 KB
testcase_35 AC 9 ms
10,764 KB
testcase_36 WA -
testcase_37 AC 9 ms
10,708 KB
testcase_38 AC 11 ms
10,764 KB
testcase_39 AC 10 ms
10,696 KB
testcase_40 WA -
testcase_41 AC 10 ms
10,692 KB
testcase_42 AC 10 ms
10,696 KB
testcase_43 AC 10 ms
10,884 KB
testcase_44 AC 10 ms
10,736 KB
testcase_45 AC 10 ms
10,792 KB
testcase_46 AC 10 ms
10,788 KB
testcase_47 AC 10 ms
10,768 KB
testcase_48 AC 10 ms
10,696 KB
testcase_49 AC 9 ms
10,812 KB
testcase_50 AC 10 ms
10,756 KB
testcase_51 WA -
testcase_52 AC 10 ms
10,752 KB
testcase_53 AC 10 ms
10,804 KB
testcase_54 AC 10 ms
10,788 KB
testcase_55 AC 10 ms
10,708 KB
testcase_56 AC 10 ms
10,768 KB
testcase_57 AC 10 ms
10,780 KB
testcase_58 WA -
testcase_59 AC 10 ms
10,704 KB
testcase_60 AC 10 ms
10,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long MOD = 1e9 + 7;

int depth(int x) {
  int d = 0;
  while (x) {
    x >>= 1;
    ++d;
  }
  return d;
}

int lca(int l, int r, int k, int d) {
  int x = depth(l) + depth(r) - k;
  if (x % 2)
    return -1;
  x /= 2;
  if (x < 1 || d < x) return -1;
  if (x > depth(l)) return -1;
  return x;
}

int solve(int d, int l, int r, int k) {
  vector<long long> f(1000000);
  f[0] = 1;
  for (int i = 1; i < 1000000; i++)
    f[i] = f[i-1]  * i % MOD;
  
  int x = lca(l, r, k, d);
  if (x == -1)
    return 0;
  
  long long ret = 1;
  if (depth(l) == depth(x)) {
    for (int i = 1; i <= d; i++) {
      int j = 1<<(i-1);
      ret = ret * f[j] % MOD;
    }
  } else if (depth(l) < depth(r)) {
    for (int i = 1; i <= d; i++) {
      int j = 1<<(i-1);
      if (i == depth(r)) {
        int tmp = 1<<(i-x-1);
        ret = ret * tmp % MOD;
        ret = ret * f[j-1] % MOD;
      } else {
        ret = ret * f[j] % MOD;
      }
    }
  } else {
    for (int i = 1; i <= d; i++) {
      int j = 1<<(i-1);
      if (i == depth(r)) {
        int tmp = 1<<(i-x-1);
        ret = ret * j % MOD;
        ret = ret * tmp % MOD;
        ret = ret * f[j-2] % MOD;
      } else {
        ret = ret * f[j] % MOD;
      }
    }
  }
  return ret;
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

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