結果

問題 No.916 Encounter On A Tree
ユーザー ogingingoginging
提出日時 2019-10-25 22:08:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 170,100 KB
実行使用メモリ 38,368 KB
最終ジャッジ日時 2023-10-11 04:42:42
合計ジャッジ時間 7,700 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
38,048 KB
testcase_01 AC 69 ms
38,344 KB
testcase_02 AC 68 ms
38,272 KB
testcase_03 AC 68 ms
38,148 KB
testcase_04 AC 75 ms
38,220 KB
testcase_05 AC 70 ms
38,276 KB
testcase_06 AC 74 ms
38,120 KB
testcase_07 AC 65 ms
38,020 KB
testcase_08 AC 65 ms
38,144 KB
testcase_09 AC 61 ms
38,036 KB
testcase_10 AC 64 ms
38,140 KB
testcase_11 AC 64 ms
38,152 KB
testcase_12 AC 60 ms
38,280 KB
testcase_13 AC 64 ms
37,972 KB
testcase_14 AC 65 ms
38,280 KB
testcase_15 AC 66 ms
38,156 KB
testcase_16 AC 66 ms
38,196 KB
testcase_17 AC 66 ms
38,044 KB
testcase_18 AC 58 ms
38,204 KB
testcase_19 AC 63 ms
38,200 KB
testcase_20 AC 57 ms
38,152 KB
testcase_21 AC 58 ms
38,144 KB
testcase_22 AC 63 ms
38,208 KB
testcase_23 AC 63 ms
38,076 KB
testcase_24 AC 59 ms
38,268 KB
testcase_25 AC 61 ms
38,368 KB
testcase_26 AC 61 ms
38,032 KB
testcase_27 AC 58 ms
38,084 KB
testcase_28 AC 60 ms
38,140 KB
testcase_29 AC 72 ms
38,032 KB
testcase_30 AC 64 ms
38,276 KB
testcase_31 AC 59 ms
38,276 KB
testcase_32 AC 67 ms
38,212 KB
testcase_33 AC 60 ms
38,204 KB
testcase_34 AC 61 ms
38,276 KB
testcase_35 AC 60 ms
38,020 KB
testcase_36 AC 68 ms
38,276 KB
testcase_37 AC 61 ms
38,276 KB
testcase_38 AC 62 ms
38,276 KB
testcase_39 AC 68 ms
38,216 KB
testcase_40 AC 71 ms
38,020 KB
testcase_41 AC 69 ms
38,208 KB
testcase_42 AC 73 ms
38,032 KB
testcase_43 AC 74 ms
38,088 KB
testcase_44 AC 72 ms
38,276 KB
testcase_45 AC 65 ms
38,268 KB
testcase_46 AC 62 ms
38,128 KB
testcase_47 AC 75 ms
38,088 KB
testcase_48 AC 65 ms
38,212 KB
testcase_49 AC 66 ms
38,352 KB
testcase_50 AC 64 ms
38,144 KB
testcase_51 AC 65 ms
38,088 KB
testcase_52 AC 66 ms
38,032 KB
testcase_53 AC 68 ms
38,184 KB
testcase_54 AC 69 ms
37,972 KB
testcase_55 AC 61 ms
38,036 KB
testcase_56 AC 68 ms
38,204 KB
testcase_57 AC 62 ms
38,268 KB
testcase_58 AC 66 ms
38,208 KB
testcase_59 AC 65 ms
38,036 KB
testcase_60 AC 63 ms
38,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<60;
const ll Mod=1e9+7;


vector<ll> inv,fact,invfact;
void Mod_build(int n=1500140){
	fact.resize(n+1);
	inv.resize(n+1);
	invfact.resize(n+1);
	fact[0]=inv[0]=invfact[0]=1;
	inv[1]=1;
	for(ll i=0;i<n;i++){
		fact[i+1]=fact[i]*(i+1)%Mod;
		if(i>0)inv[i+1]=Mod-inv[Mod%(i+1)]*(Mod/(i+1))%Mod;
		invfact[i+1]=invfact[i]*inv[i+1]%Mod;
	}
}
ll perm(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return fact[n]*invfact[n-k]%Mod;
}
ll comb(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return (fact[n]*invfact[n-k]%Mod)*invfact[k]%Mod;
}
ll powMod(ll n,ll k){
	k%=Mod-1;
	if(k<0)k+=Mod-1;
	ll ret=1;
	while(k){
		if(k&1)ret=ret*n%Mod;
		n=n*n%Mod;
		k>>=1;
	}
	return ret;
}

int d,l,r,k;
int depth(int p){
  int cnt=0;
  while(p>=2){
    p=p/2;
    cnt++;
  }
  return cnt;
}

int main(){
  int i,j;
  Mod_build();
  cin>>d>>l>>r>>k;
  l=depth(l);
  r=depth(r);
  if((l+r+k)%2!=0){
    cout<<0<<endl;
    return 0;
  }
  int u=(l+r-k)/2;
  if(u<0||u>min(l,r)){
    cout<<0<<endl;
    return 0;
  }
  ll a=1;
  a*=1<<l;
  for(i=u+1;i<r;i++) {
    a*=2;
    a%=Mod;
  }
  if(l==u) {
    a*=2;
    a%=Mod;
  }

  VI used(d,0);
  used[l]++;
  used[r]++;
  for(i=0;i<d;i++){
    if((1<<i)-used[i]<0) continue;
    a*=fact[(1<<i)-used[i]];
    a%=Mod;
  }
  cout<<a<<endl;
  
}
0