結果
問題 |
No.916 Encounter On A Tree
|
ユーザー |
![]() |
提出日時 | 2019-10-25 23:18:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,545 bytes |
コンパイル時間 | 1,510 ms |
コンパイル使用メモリ | 168,244 KB |
実行使用メモリ | 81,728 KB |
最終ジャッジ日時 | 2024-09-13 08:44:42 |
合計ジャッジ時間 | 6,154 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 50 WA * 6 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=x;i<y;i++) #define range(a) (a).begin(),(a).end() #define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl; #define pprint(A,m,n) rep(j,0,m){print(A[j],n);} const long mod=1e9+7; const int size=1e7; const int INF=1e9; int depth(long v){ int i=0; while(v){ i++; v/=2; }return i; } long calc(int a,int b,long d){ long fact[size]; long res=1;fact[0]=1; rep(i,1,size){ (res*=i)%=mod; fact[i]=res; } long node=1;long ans=1; rep(i,1,d+1){ if(i==a&&i==b) (ans*=fact[node-2])%=mod; else if(i==a||i==b) (ans*=fact[node-1])%=mod; else (ans*=fact[node])%=mod; node*=2; }return ans; } long modpow(long x,int n,long p){ int i=0;long res=1; while(n>=(1<<i)){ if(n&(1<<i)) (res*=x)%=p; i++;x=x*x%p; }return res; } int main(){ long d,l,r,k;cin>>d>>l>>r>>k; int a=depth(l);int b=depth(r); if((a+b-k)%2==1||b-a>k){ cout<<0<<endl; return 0; } long ans=calc(a,b,d); if(b-a==k) (ans*=modpow(2,b-1,mod))%=mod; else (ans*=modpow(2,(a+b+k)/2-2,mod))%=mod; cout<<ans<<endl; } //63 64 68 69 70 /*タスクを並列に行う x=(x ? true : false) sorted auto it=lower_bound(v.begin(),v.end(),w) v[it-v.begin()]>=w auto it=upper_bound(v.begin(),v.end(),w) v[it-v.begin()]>w void func(int* vec){} puts(string) cout<<string<<endl; 1.*a/b int to double (int)a-48 char to int (char)(i+97) int to char stoi(s) string to int stoll(s) cout.precision(16); cout<<fixed<<a; printf("%.6lf\n",a); accumulate(a,a+n,0); */