結果

問題 No.916 Encounter On A Tree
ユーザー kk
提出日時 2021-01-20 18:01:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 3,909 ms
コンパイル使用メモリ 200,912 KB
実行使用メモリ 10,980 KB
最終ジャッジ日時 2023-08-24 21:48:04
合計ジャッジ時間 6,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 10 ms
10,724 KB
testcase_02 AC 10 ms
10,612 KB
testcase_03 WA -
testcase_04 AC 10 ms
10,752 KB
testcase_05 AC 10 ms
10,648 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 10 ms
10,856 KB
testcase_11 AC 10 ms
10,792 KB
testcase_12 AC 10 ms
10,648 KB
testcase_13 AC 10 ms
10,808 KB
testcase_14 AC 10 ms
10,668 KB
testcase_15 AC 11 ms
10,948 KB
testcase_16 AC 10 ms
10,648 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 9 ms
10,656 KB
testcase_23 WA -
testcase_24 AC 10 ms
10,792 KB
testcase_25 WA -
testcase_26 AC 9 ms
10,716 KB
testcase_27 WA -
testcase_28 AC 10 ms
10,764 KB
testcase_29 WA -
testcase_30 AC 10 ms
10,768 KB
testcase_31 AC 9 ms
10,704 KB
testcase_32 AC 10 ms
10,912 KB
testcase_33 AC 10 ms
10,776 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 9 ms
10,724 KB
testcase_40 WA -
testcase_41 AC 10 ms
10,776 KB
testcase_42 AC 10 ms
10,704 KB
testcase_43 AC 9 ms
10,596 KB
testcase_44 AC 10 ms
10,724 KB
testcase_45 AC 9 ms
10,652 KB
testcase_46 AC 11 ms
10,864 KB
testcase_47 AC 9 ms
10,716 KB
testcase_48 AC 10 ms
10,588 KB
testcase_49 AC 10 ms
10,660 KB
testcase_50 AC 10 ms
10,704 KB
testcase_51 WA -
testcase_52 AC 9 ms
10,784 KB
testcase_53 AC 10 ms
10,740 KB
testcase_54 AC 9 ms
10,712 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 10 ms
10,732 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 (1 <= x && x <= d)
    return x;
  return -1;
}

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 * 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 * tmp * 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