結果

問題 No.916 Encounter On A Tree
ユーザー nejinejinejineji
提出日時 2019-10-25 23:24:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,316 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 168,328 KB
実行使用メモリ 19,076 KB
最終ジャッジ日時 2023-10-11 09:47:31
合計ジャッジ時間 18,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
18,748 KB
testcase_01 AC 246 ms
18,476 KB
testcase_02 AC 246 ms
18,608 KB
testcase_03 AC 246 ms
18,508 KB
testcase_04 AC 245 ms
18,516 KB
testcase_05 AC 246 ms
18,700 KB
testcase_06 AC 247 ms
18,660 KB
testcase_07 AC 245 ms
18,516 KB
testcase_08 AC 245 ms
18,804 KB
testcase_09 AC 245 ms
18,840 KB
testcase_10 AC 246 ms
18,436 KB
testcase_11 AC 246 ms
18,680 KB
testcase_12 AC 246 ms
18,500 KB
testcase_13 AC 247 ms
18,676 KB
testcase_14 WA -
testcase_15 AC 245 ms
18,840 KB
testcase_16 AC 249 ms
18,816 KB
testcase_17 AC 246 ms
18,696 KB
testcase_18 AC 246 ms
18,688 KB
testcase_19 AC 245 ms
18,732 KB
testcase_20 AC 246 ms
18,764 KB
testcase_21 AC 246 ms
18,940 KB
testcase_22 AC 246 ms
18,572 KB
testcase_23 AC 245 ms
18,740 KB
testcase_24 AC 245 ms
18,544 KB
testcase_25 AC 246 ms
18,792 KB
testcase_26 AC 245 ms
18,508 KB
testcase_27 AC 245 ms
18,684 KB
testcase_28 AC 246 ms
18,704 KB
testcase_29 AC 245 ms
18,812 KB
testcase_30 AC 245 ms
18,668 KB
testcase_31 WA -
testcase_32 AC 246 ms
18,692 KB
testcase_33 WA -
testcase_34 AC 245 ms
18,948 KB
testcase_35 AC 246 ms
18,696 KB
testcase_36 AC 247 ms
19,036 KB
testcase_37 AC 246 ms
18,600 KB
testcase_38 AC 246 ms
18,500 KB
testcase_39 WA -
testcase_40 AC 245 ms
18,748 KB
testcase_41 AC 245 ms
18,692 KB
testcase_42 AC 245 ms
18,408 KB
testcase_43 AC 245 ms
18,600 KB
testcase_44 AC 246 ms
18,316 KB
testcase_45 AC 246 ms
19,068 KB
testcase_46 AC 246 ms
18,412 KB
testcase_47 AC 245 ms
18,596 KB
testcase_48 AC 245 ms
18,440 KB
testcase_49 AC 246 ms
18,692 KB
testcase_50 AC 246 ms
19,024 KB
testcase_51 AC 246 ms
18,512 KB
testcase_52 AC 245 ms
18,684 KB
testcase_53 AC 246 ms
18,504 KB
testcase_54 AC 246 ms
18,660 KB
testcase_55 AC 246 ms
18,812 KB
testcase_56 AC 245 ms
18,564 KB
testcase_57 AC 245 ms
18,564 KB
testcase_58 AC 246 ms
18,688 KB
testcase_59 AC 246 ms
18,724 KB
testcase_60 AC 246 ms
18,568 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){
                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