結果
問題 | No.916 Encounter On A Tree |
ユーザー |
![]() |
提出日時 | 2019-10-25 22:51:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 1,444 bytes |
コンパイル時間 | 1,795 ms |
コンパイル使用メモリ | 175,500 KB |
実行使用メモリ | 85,256 KB |
最終ジャッジ日時 | 2024-09-13 06:30:54 |
合計ジャッジ時間 | 7,497 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 56 |
ソースコード
#include<bits/stdc++.h> #define int long long using 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; int n=1<<(d-1); vector<vector<int>> G(2*n); for(int i=1;i<n;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(2*n); 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 heightL=32-__builtin_clz(l); int heightR=32-__builtin_clz(r); // cout<<heightL<<' '<<heightR<<endl; dfs(1<<(heightL-1),-1); // for(int i=1;i<2*n;i++) cout<<dist[i]<<' '; cout<<endl; int ans=0; for(int i=1<<(heightR-1);i<(1<<heightR);i++){ if(dist[i]==k) ans++; } // cout<<ans<<endl; vector<int> fact(1<<d); fact[0]=1; for(int i=1;i<(1<<d);i++) fact[i]=fact[i-1]*i%mod; ans=ans*(1<<(heightL-1))%mod; // cout<<ans<<endl; for(int i=1;i<=d;i++){ int j=1<<(i-1); if(i==heightL) j--; if(i==heightR) j--; // cout<<i<<' '<<j<<endl; ans=ans*fact[j]%mod; } cout<<ans<<endl; }