結果
問題 | No.916 Encounter On A Tree |
ユーザー |
![]() |
提出日時 | 2019-10-29 20:28:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 149 ms / 2,000 ms |
コード長 | 2,201 bytes |
コンパイル時間 | 1,751 ms |
コンパイル使用メモリ | 175,548 KB |
実行使用メモリ | 85,120 KB |
最終ジャッジ日時 | 2024-09-14 21:35:58 |
合計ジャッジ時間 | 7,632 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; }template<int mod> class ModInt{private:int val;public:int value(){ return val; }ModInt(int x=0){ val=x%mod; }ModInt pow(int n){ModInt res(1),x(val);while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }return res;}ModInt inv(){ return pow(mod-2); }ModInt& operator+=(ModInt rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }ModInt& operator-=(ModInt rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }ModInt& operator*=(ModInt rhs){ val=val*rhs.val%mod; return *this; }ModInt& operator/=(ModInt rhs){ *this*=rhs.inv(); return *this; }ModInt operator+(ModInt rhs){ return ModInt(val)+=rhs; }ModInt operator-(ModInt rhs){ return ModInt(val)-=rhs; }ModInt operator*(ModInt rhs){ return ModInt(val)*=rhs; }ModInt operator/(ModInt rhs){ return ModInt(val)/=rhs; }};signed main(){cin.tie(0);ios::sync_with_stdio(false);int d,l,r,k; cin>>d>>l>>r>>k;const int N=(1<<d)-1;vector<vector<int>> G(N+1);for(int i=1;i<1<<(d-1);i++){G[i].push_back(2*i);G[2*i].push_back(i);G[i].push_back(2*i+1);G[2*i+1].push_back(i);}vector<int> dist(N+1);function<void(int,int)> dfs=[&](int v,int p){for(int u:G[v]) if(u!=p){dist[u]=dist[v]+1;dfs(u,v);}};int depthL=32-__builtin_clz(l);int depthR=32-__builtin_clz(r);dfs(1<<(depthL-1),-1);// for(int i=1;i<=N;i++) cout<<dist[i]<<' '; cout<<endl;using mint=ModInt<1000000007>;mint ans=0;for(int i=1<<(depthR-1);i<1<<depthR;i++) if(dist[i]==k) ans+=1;vector<mint> fact(N+1);fact[0]=1;for(int i=1;i<=N;i++) fact[i]=fact[i-1]*i;for(int i=1;i<=d;i++){int j=1<<(i-1);if(i==depthL) j--;if(i==depthR) j--;ans*=fact[j];}ans*=1<<(depthL-1);cout<<ans.value()<<endl;return 0;}