結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 234 ms
19,068 KB
testcase_01 AC 233 ms
18,812 KB
testcase_02 AC 233 ms
18,560 KB
testcase_03 AC 232 ms
18,752 KB
testcase_04 AC 229 ms
18,324 KB
testcase_05 AC 242 ms
18,824 KB
testcase_06 AC 226 ms
18,640 KB
testcase_07 AC 228 ms
18,748 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 230 ms
18,552 KB
testcase_11 WA -
testcase_12 AC 228 ms
18,424 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 235 ms
18,612 KB
testcase_17 AC 239 ms
18,844 KB
testcase_18 AC 232 ms
18,844 KB
testcase_19 AC 226 ms
18,840 KB
testcase_20 AC 227 ms
18,612 KB
testcase_21 AC 225 ms
19,044 KB
testcase_22 AC 226 ms
18,388 KB
testcase_23 AC 221 ms
18,996 KB
testcase_24 AC 225 ms
18,820 KB
testcase_25 AC 223 ms
18,512 KB
testcase_26 AC 226 ms
18,824 KB
testcase_27 AC 228 ms
18,624 KB
testcase_28 AC 225 ms
18,572 KB
testcase_29 AC 234 ms
18,676 KB
testcase_30 AC 221 ms
18,424 KB
testcase_31 WA -
testcase_32 AC 224 ms
18,548 KB
testcase_33 WA -
testcase_34 AC 232 ms
19,044 KB
testcase_35 AC 232 ms
18,508 KB
testcase_36 WA -
testcase_37 AC 227 ms
18,524 KB
testcase_38 AC 230 ms
18,508 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 230 ms
18,508 KB
testcase_43 AC 230 ms
18,996 KB
testcase_44 AC 221 ms
18,616 KB
testcase_45 AC 227 ms
18,808 KB
testcase_46 AC 234 ms
18,304 KB
testcase_47 WA -
testcase_48 AC 224 ms
18,632 KB
testcase_49 WA -
testcase_50 AC 229 ms
18,560 KB
testcase_51 WA -
testcase_52 AC 234 ms
18,972 KB
testcase_53 WA -
testcase_54 AC 236 ms
18,500 KB
testcase_55 AC 231 ms
19,036 KB
testcase_56 AC 231 ms
18,564 KB
testcase_57 AC 243 ms
18,620 KB
testcase_58 WA -
testcase_59 AC 227 ms
18,620 KB
testcase_60 AC 225 ms
18,844 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 = pow(2, (k - (r_dp - l_dp)) / 2);
                tmp /= 2;
        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