結果
問題 | No.916 Encounter On A Tree |
ユーザー |
|
提出日時 | 2019-10-25 22:43:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 754 bytes |
コンパイル時間 | 571 ms |
コンパイル使用メモリ | 65,236 KB |
実行使用メモリ | 11,768 KB |
最終ジャッジ日時 | 2024-09-13 06:13:28 |
合計ジャッジ時間 | 3,415 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 56 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> using namespace std; long mod=1e9+7; long F[(1<<20)+1]; int d,l,r,k; long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;} main() { F[0]=1; for(long i=1;i<=1<<20;i++)F[i]=F[i-1]*i%mod; cin>>d>>l>>r>>k; long ans=1; for(int i=0;i<d;i++)ans=ans*F[1<<i]%mod; int cl=0,cr=0; while(l>=1<<cl)cl++; while(r>=1<<cr)cr++; int diff=cr-cl; if(k<diff||k-diff&1) { cout<<0<<endl; return 0; } k-=diff; long out=1LL<<diff; if(k==0) { ans=ans*power(1<<cr-1,mod-2)%mod*out%mod; } else { k/=2; if(cl<=k) { cout<<0<<endl; return 0; } out<<=k; if(cl<cr) { ans=ans*power(1<<cr,mod-2)%mod*out%mod; } else { ans=ans*power((1<<cr-1)-1,mod-2)%mod*(out/2)%mod; } } cout<<ans<<endl; }