結果
問題 | No.916 Encounter On A Tree |
ユーザー |
|
提出日時 | 2019-10-25 22:08:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,566 bytes |
コンパイル時間 | 1,879 ms |
コンパイル使用メモリ | 171,796 KB |
実行使用メモリ | 38,556 KB |
最終ジャッジ日時 | 2024-09-13 04:02:02 |
合計ジャッジ時間 | 7,147 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 56 |
ソースコード
#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; }