結果
問題 | No.916 Encounter On A Tree |
ユーザー |
![]() |
提出日時 | 2019-10-26 01:48:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 2,229 bytes |
コンパイル時間 | 1,601 ms |
コンパイル使用メモリ | 166,680 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-09-13 13:04:53 |
合計ジャッジ時間 | 4,055 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 56 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const ull mod = 1e9 + 7; #define REP(i,n) for(int i=0;i<(int)n;++i) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){ os << "(" << v.first << ", " << v.second << ")"; return os; } template<class T> ostream& operator << (ostream& os, const vector<T> v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os; } template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os; } ll fact[2020202]; ll powLL(ll a, ll n){ ll res = 1; while(n>0){ if(n&1){ res *= a; } a = a*a; n >>= 1; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); fact[0] = 1; REP(i, 2020201){ fact[i+1] = fact[i]*(i+1); fact[i+1] %= mod; } ll d, l, r, k; cin >> d >> l >> r >> k; ll L=0, R=0; while(l>0){ l /= 2; L++; } while(r>0){ r /= 2; R++; } if(L>R) swap(L, R); ll res = 1; ll now = 1; if(k>=R-L && k<=R+L-2 && (k-(R-L))%2==0){ ll t = (k - (R-L))/2; //dump(t) REP(i, d){ if(i==L-1){ if(R==L){ res *= now; res %= mod; res *= (1ll<<(t-1)); res %= mod; res *= fact[now-2]; res %= mod; }else{ if(t != 0){ res *= (1ll<<(t-1)); res %= mod; } res *= fact[now-1]; res %= mod; } }else{ res *= fact[now]; } res %= mod; now *= 2; } }else{ res = 0; } cout << res << endl; return 0; }