結果
| 問題 |
No.916 Encounter On A Tree
|
| ユーザー |
auaua
|
| 提出日時 | 2019-10-25 23:09:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,206 bytes |
| コンパイル時間 | 2,255 ms |
| コンパイル使用メモリ | 160,472 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-13 07:16:55 |
| 合計ジャッジ時間 | 3,348 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 35 WA * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll depth(ll a){
ll cnt=0;
while(a){
cnt++;
a/=2;
}
return cnt;
}
ll e(ll d){
ll res=1;
ll s=d;
while(s>0){
s--;
res*=2;
res%=inf;
}
return res;
}
int main(){
ll d,l,r,k;cin>>d>>l>>r>>k;
ll ans=1;
if((depth(l)+depth(r)-k)%2||depth(l)+depth(r)-k<=0){
cout<<0<<endl;
return 0;
}
ll anc=(depth(l)+depth(r)-k)/2;
ans*=e(depth(r)-anc-1);
ans%=inf;
if(depth(l)>anc)ans*=e(depth(l)-anc-1);
ans%=inf;
ans*=2;
ans%=inf;
ll f=0;
if(depth(r)==depth(l))f=1;
rep(i,d){
k=e(i);
if(f&&i==depth(r)-1)k-=2;
else if(depth(l)!=anc&&i==depth(l)-1)k--;
else if(i==depth(r)-1)k--;
while(k>1){
ans*=k;
ans%=inf;
k--;
}
}
cout<<ans<<endl;
}
auaua