結果
問題 | No.916 Encounter On A Tree |
ユーザー | betrue12 |
提出日時 | 2019-10-25 22:13:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 2,232 bytes |
コンパイル時間 | 1,742 ms |
コンパイル使用メモリ | 172,600 KB |
実行使用メモリ | 27,964 KB |
最終ジャッジ日時 | 2024-09-13 04:07:39 |
合計ジャッジ時間 | 5,121 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 48 ms
27,752 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 48 ms
27,788 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 50 ms
27,820 KB |
testcase_08 | AC | 50 ms
27,888 KB |
testcase_09 | AC | 50 ms
27,792 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 52 ms
27,780 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 51 ms
27,744 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 51 ms
27,844 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 50 ms
27,776 KB |
testcase_18 | AC | 49 ms
27,752 KB |
testcase_19 | AC | 50 ms
27,740 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 54 ms
27,804 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 52 ms
27,808 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 50 ms
27,832 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 50 ms
27,808 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 53 ms
27,836 KB |
testcase_30 | AC | 1 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 50 ms
27,928 KB |
testcase_35 | AC | 49 ms
27,740 KB |
testcase_36 | AC | 50 ms
27,924 KB |
testcase_37 | AC | 50 ms
27,856 KB |
testcase_38 | AC | 52 ms
27,832 KB |
testcase_39 | AC | 2 ms
6,944 KB |
testcase_40 | AC | 51 ms
27,856 KB |
testcase_41 | AC | 50 ms
27,792 KB |
testcase_42 | AC | 50 ms
27,932 KB |
testcase_43 | AC | 50 ms
27,852 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 50 ms
27,812 KB |
testcase_46 | AC | 2 ms
6,944 KB |
testcase_47 | AC | 49 ms
27,740 KB |
testcase_48 | AC | 2 ms
6,940 KB |
testcase_49 | AC | 49 ms
27,856 KB |
testcase_50 | AC | 50 ms
27,964 KB |
testcase_51 | AC | 50 ms
27,912 KB |
testcase_52 | AC | 49 ms
27,840 KB |
testcase_53 | AC | 49 ms
27,792 KB |
testcase_54 | AC | 2 ms
6,940 KB |
testcase_55 | AC | 50 ms
27,752 KB |
testcase_56 | AC | 50 ms
27,912 KB |
testcase_57 | AC | 50 ms
27,748 KB |
testcase_58 | AC | 51 ms
27,736 KB |
testcase_59 | AC | 51 ms
27,780 KB |
testcase_60 | AC | 51 ms
27,852 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b) % MOD; } void mul(int64_t& a, int64_t b){ a = a*b % MOD; } vector<int64_t> fact, seq_inv, fact_inv; void create_fact_mod(int num){ fact[0] = fact[1] = 1; for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD; } void create_seq_inv_mod(int num){ seq_inv[0] = seq_inv[1] = 1; for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD; } void create_fact_inv_mod(int num){ fact_inv[0] = fact_inv[1] = 1; for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD; } void create_mod_tables(int num){ fact.resize(num+1); seq_inv.resize(num+1); fact_inv.resize(num+1); create_fact_mod(num); create_seq_inv_mod(num); create_fact_inv_mod(num); } int64_t comb_mod(int n, int k){ return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD; } int64_t perm_mod(int n, int k){ return fact[n] * fact_inv[n-k] % MOD; } int64_t power_mod(int64_t num, int64_t power){ int64_t prod = 1; num %= MOD; while(power > 0){ if(power&1) prod = prod * num % MOD; num = num * num % MOD; power >>= 1; } return prod; } int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){ int64_t d = a; if(b != 0){ d = extgcd(b, a%b, y, x); y -= (a/b) * x; }else{ x = 1; y = 0; } return d; } int64_t inv_mod(int64_t a){ int64_t x, y; extgcd(a, MOD, x, y); return (MOD + x%MOD) % MOD; } void fail(){ cout << 0 << endl; exit(0); } int main(){ int D, L, R, K; cin >> D >> L >> R >> K; int ld = 1, rd = 1; while((1<<ld) <= L) ld++; while((1<<rd) <= R) rd++; int rest = K - (rd-ld); if(rest%2) fail(); if(rest < 0) fail(); int lca = ld - rest/2; if(lca <= 0) fail(); int64_t ans = 1<<(lca-1); mul(ans, 2); if(lca < ld) mul(ans, 1<<(ld-lca-1)); mul(ans, 1<<(rd-lca-1)); create_mod_tables(1<<20); for(int d=1; d<=D; d++){ int num = 1<<(d-1); if(d==ld) num--; if(d==rd) num--; mul(ans, fact[num]); } cout << ans << endl; return 0; }