結果
| 問題 |
No.916 Encounter On A Tree
|
| ユーザー |
|
| 提出日時 | 2020-04-17 13:37:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,198 bytes |
| コンパイル時間 | 1,752 ms |
| コンパイル使用メモリ | 167,420 KB |
| 実行使用メモリ | 27,008 KB |
| 最終ジャッジ日時 | 2024-10-03 10:16:23 |
| 合計ジャッジ時間 | 5,037 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 53 WA * 3 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;
ll fac[3000000];
void init(){
fac[0] = 1;
fac[1] = 1;
for(int i=2;i<3000000;i++){
fac[i] = (fac[i-1] * i)%MOD;
}
}
int depth(int p){
int i = 0;
int res = 1;
while(res <= p){
res *= 2;
i ++;
}
return i;
}
int main(){
init();
int d,l,r,k;
cin >> d >> l >> r >> k;
int ld = depth(l);
int rd = depth(r);
if((k-(rd-ld))%2 == 0 && (k-(rd-ld))/2 <= ld){
int lca_d = ld - (k-(rd-ld))/2 ;
ll ans;
if(lca_d == ld) ans = ((1<<(ld-1)) * (1<<(rd-ld)))%MOD;
else ans = ((((1<<(lca_d-1)) * (1<<(ld-lca_d-1)))%MOD * (1<<(rd-lca_d-1)))%MOD * 2)%MOD;
ll res = 2;
for(ll i=2;i<=d;i++){
if(i==ld && i==rd) ans = (ans * fac[res-2])%MOD;
else if(i==ld || i==rd) ans = (ans * fac[res-1])%MOD;
else ans = (ans * fac[res])%MOD;
res *= 2;
}
cout << ans << endl;
}else{
cout << 0 << endl;
return 0;
}
return 0;
}