結果

問題 No.916 Encounter On A Tree
ユーザー theory_and_metheory_and_me
提出日時 2019-10-26 01:48:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,229 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 165,968 KB
実行使用メモリ 19,424 KB
最終ジャッジ日時 2023-10-11 14:23:08
合計ジャッジ時間 5,021 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
19,080 KB
testcase_01 AC 15 ms
19,092 KB
testcase_02 AC 15 ms
19,136 KB
testcase_03 AC 15 ms
19,284 KB
testcase_04 AC 15 ms
19,084 KB
testcase_05 AC 15 ms
19,200 KB
testcase_06 AC 15 ms
19,112 KB
testcase_07 AC 15 ms
19,076 KB
testcase_08 AC 15 ms
19,208 KB
testcase_09 AC 15 ms
19,212 KB
testcase_10 AC 15 ms
19,224 KB
testcase_11 AC 15 ms
19,236 KB
testcase_12 AC 16 ms
19,148 KB
testcase_13 AC 16 ms
19,292 KB
testcase_14 AC 16 ms
19,088 KB
testcase_15 AC 15 ms
19,208 KB
testcase_16 AC 15 ms
19,108 KB
testcase_17 AC 15 ms
19,112 KB
testcase_18 AC 15 ms
19,352 KB
testcase_19 AC 15 ms
19,084 KB
testcase_20 AC 15 ms
19,080 KB
testcase_21 AC 16 ms
19,424 KB
testcase_22 AC 15 ms
19,108 KB
testcase_23 AC 15 ms
19,280 KB
testcase_24 AC 16 ms
19,140 KB
testcase_25 AC 15 ms
19,096 KB
testcase_26 AC 16 ms
19,280 KB
testcase_27 AC 16 ms
19,196 KB
testcase_28 AC 16 ms
19,152 KB
testcase_29 AC 15 ms
19,152 KB
testcase_30 AC 16 ms
19,156 KB
testcase_31 AC 15 ms
19,088 KB
testcase_32 AC 16 ms
19,136 KB
testcase_33 AC 16 ms
19,280 KB
testcase_34 AC 15 ms
19,140 KB
testcase_35 AC 15 ms
19,280 KB
testcase_36 AC 15 ms
19,132 KB
testcase_37 AC 15 ms
19,168 KB
testcase_38 AC 16 ms
19,144 KB
testcase_39 AC 15 ms
19,128 KB
testcase_40 AC 16 ms
19,096 KB
testcase_41 AC 16 ms
19,224 KB
testcase_42 AC 16 ms
19,224 KB
testcase_43 AC 15 ms
19,084 KB
testcase_44 AC 15 ms
19,280 KB
testcase_45 AC 15 ms
19,128 KB
testcase_46 AC 15 ms
19,364 KB
testcase_47 AC 16 ms
19,220 KB
testcase_48 AC 16 ms
19,152 KB
testcase_49 AC 15 ms
19,292 KB
testcase_50 AC 16 ms
19,220 KB
testcase_51 AC 16 ms
19,132 KB
testcase_52 AC 16 ms
19,360 KB
testcase_53 AC 15 ms
19,096 KB
testcase_54 AC 15 ms
19,280 KB
testcase_55 AC 14 ms
19,132 KB
testcase_56 AC 15 ms
19,172 KB
testcase_57 AC 15 ms
19,080 KB
testcase_58 AC 15 ms
19,080 KB
testcase_59 AC 15 ms
19,152 KB
testcase_60 AC 15 ms
19,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll fact[2020202];

ll powLL(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res *= a;
        }
        a = a*a;
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact[0] = 1;
    REP(i, 2020201){
    	fact[i+1] = fact[i]*(i+1);
    	fact[i+1] %= mod;
    }

    ll d, l, r, k;
    cin >> d >> l >> r >> k;

    ll L=0, R=0;
    while(l>0){
    	l /= 2;
    	L++;
    }
    while(r>0){
    	r /= 2;
    	R++;
    }

    if(L>R) swap(L, R);

    ll res = 1;
    ll now = 1;
    if(k>=R-L && k<=R+L-2 && (k-(R-L))%2==0){
        ll t = (k - (R-L))/2;
        //dump(t)
    	REP(i, d){
    		if(i==L-1){
                if(R==L){
                    res *= now;
                    res %= mod;

                    res *= (1ll<<(t-1));
                    res %= mod;

                    res *= fact[now-2];
                    res %= mod;
                }else{
                    if(t != 0){
                        res *= (1ll<<(t-1));
                        res %= mod;
                    }

                    res *= fact[now-1];
                    res %= mod;
                }
    		}else{
    			res *= fact[now];
    		}
    		res %= mod;
    		now *= 2;
    	}
    }else{
    	res = 0;
    }
    cout << res << endl;
    return 0;
}
0