結果
問題 | No.916 Encounter On A Tree |
ユーザー |
![]() |
提出日時 | 2019-10-29 21:32:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,151 bytes |
コンパイル時間 | 1,693 ms |
コンパイル使用メモリ | 170,344 KB |
実行使用メモリ | 7,372 KB |
最終ジャッジ日時 | 2024-09-14 21:37:16 |
合計ジャッジ時間 | 3,206 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 56 |
ソースコード
#include<bits/stdc++.h>#define int long longusing namespace std;template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }const int mod=1e9+7;signed main(){cin.tie(0);ios::sync_with_stdio(false);int d,l,r,k; cin>>d>>l>>r>>k;if(l>r) swap(l,r);l=32-__builtin_clz(l)-1;r=32-__builtin_clz(r)-1;int lca=-1;if(l+r-k>=0 and (l+r-k)%2==0) lca=(l+r-k)/2;if(lca==-1 or lca>l or lca>r){cout<<0<<endl;return 0;}// cout<<l<<' '<<r<<' '<<lca<<endl;vector<int> fact((1<<(d-1))+1);fact[0]=1;for(int i=1;i<=1<<(d-1);i++) fact[i]=fact[i-1]*i%mod;int ans=1;if(lca==l){ans=ans*(1<<lca)%mod;ans=ans*(1<<(r-lca))%mod;}else{ans=ans*(1<<lca)%mod;ans=ans*(1<<(l-lca))%mod;ans=ans*(1<<(r-lca-1))%mod;}// cout<<ans<<endl;for(int i=0;i<d;i++){int cnt=1<<i;if(i==l) cnt--;if(i==r) cnt--;ans=ans*fact[cnt]%mod;}cout<<ans<<endl;return 0;}