結果

問題 No.916 Encounter On A Tree
ユーザー nejinejinejineji
提出日時 2019-10-25 23:34:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 2,336 bytes
コンパイル時間 1,652 ms
コンパイル使用メモリ 168,496 KB
実行使用メモリ 18,996 KB
最終ジャッジ日時 2023-10-11 10:07:31
合計ジャッジ時間 18,821 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
18,560 KB
testcase_01 AC 246 ms
18,672 KB
testcase_02 AC 246 ms
18,748 KB
testcase_03 AC 247 ms
18,632 KB
testcase_04 AC 246 ms
18,820 KB
testcase_05 AC 246 ms
18,516 KB
testcase_06 AC 244 ms
18,476 KB
testcase_07 AC 246 ms
18,748 KB
testcase_08 AC 246 ms
18,808 KB
testcase_09 AC 247 ms
18,996 KB
testcase_10 AC 246 ms
18,484 KB
testcase_11 AC 246 ms
18,612 KB
testcase_12 AC 245 ms
18,724 KB
testcase_13 AC 246 ms
18,684 KB
testcase_14 AC 247 ms
18,552 KB
testcase_15 AC 246 ms
18,816 KB
testcase_16 AC 246 ms
18,432 KB
testcase_17 AC 246 ms
18,504 KB
testcase_18 AC 248 ms
18,816 KB
testcase_19 AC 246 ms
18,812 KB
testcase_20 AC 246 ms
18,612 KB
testcase_21 AC 246 ms
18,744 KB
testcase_22 AC 245 ms
18,500 KB
testcase_23 AC 246 ms
18,812 KB
testcase_24 AC 246 ms
18,504 KB
testcase_25 AC 246 ms
18,672 KB
testcase_26 AC 246 ms
18,412 KB
testcase_27 AC 245 ms
18,816 KB
testcase_28 AC 246 ms
18,548 KB
testcase_29 AC 246 ms
18,740 KB
testcase_30 AC 245 ms
18,644 KB
testcase_31 AC 245 ms
18,608 KB
testcase_32 AC 246 ms
18,552 KB
testcase_33 AC 246 ms
18,672 KB
testcase_34 AC 246 ms
18,612 KB
testcase_35 AC 247 ms
18,672 KB
testcase_36 AC 246 ms
18,512 KB
testcase_37 AC 247 ms
18,744 KB
testcase_38 AC 246 ms
18,692 KB
testcase_39 AC 246 ms
18,716 KB
testcase_40 AC 246 ms
18,516 KB
testcase_41 AC 245 ms
18,312 KB
testcase_42 AC 245 ms
18,500 KB
testcase_43 AC 246 ms
18,364 KB
testcase_44 AC 244 ms
18,740 KB
testcase_45 AC 245 ms
18,508 KB
testcase_46 AC 247 ms
18,308 KB
testcase_47 AC 247 ms
18,428 KB
testcase_48 AC 245 ms
18,752 KB
testcase_49 AC 245 ms
18,516 KB
testcase_50 AC 245 ms
18,820 KB
testcase_51 AC 245 ms
18,688 KB
testcase_52 AC 245 ms
18,608 KB
testcase_53 AC 246 ms
18,632 KB
testcase_54 AC 246 ms
18,320 KB
testcase_55 AC 245 ms
18,744 KB
testcase_56 AC 245 ms
18,684 KB
testcase_57 AC 245 ms
18,820 KB
testcase_58 AC 246 ms
18,504 KB
testcase_59 AC 245 ms
18,756 KB
testcase_60 AC 246 ms
18,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define SIZE(v) ll(v.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
typedef long long ll;

ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
       x %= MOD;
       if (t == 0) {
               return 1;
       }
       else {
               ll v = mod_pow(x, t / 2);
               if (t % 2 == 0) {
                       return v * v % MOD;
               }
               else {
                       return v * v%MOD * x %MOD;
               }
       }
}

ll mod_inv(ll x) {
       return mod_pow(x, MOD - 2);
}

vll fct(1e6), invfct(1e6);
void init(){
        fct[0] = invfct[0] = 1;
        REP(i,1,1e6-1){
                fct[i] = mod_m(fct[i-1], i);
                invfct[i] = mod_inv(fct[i]);
        }
}

int main(){
        init();
        ll n, l, r, k;
        cin >> n >> l >> r >> k;
        ll l_dp = 0; ll r_dp = 0;
        while(l > 0){
                l_dp++;
                l /= 2;
        }
        while(r > 0){
                r_dp++;
                r /= 2;
        }
        if((l_dp + r_dp) % 2 != k % 2){
                cout << 0 << endl;
                return 0;
        }else if(abs(l_dp - r_dp) > k || k > l_dp + r_dp - 2){
                cout << 0 << endl;
                return 0;
        }
        if(l_dp > r_dp){
                swap(l_dp, r_dp);
        }
        ll tmp;
        if(k == r_dp - l_dp){
                tmp = 1;
        }else{
                tmp = pow(2, (k - (r_dp - l_dp)) / 2 - 1);
                
        }
        ll ans = 1;
        REP(i,1,n){
                ll t = pow(2, i-1);
                ans = mod_m(ans, fct[t]);
                if(l_dp == i){
                        if(l_dp == r_dp){
                                t--;
                        }
                        ans = mod_m(ans, mod_inv(t));
                        ans = mod_m(ans, tmp);
                }
        }
        cout << ans << endl;
}
0