結果

問題 No.916 Encounter On A Tree
ユーザー east1016east1016
提出日時 2019-10-25 23:23:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 3,245 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 170,216 KB
実行使用メモリ 11,808 KB
最終ジャッジ日時 2023-10-11 09:44:01
合計ジャッジ時間 3,933 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
11,608 KB
testcase_01 AC 10 ms
11,608 KB
testcase_02 AC 10 ms
11,612 KB
testcase_03 AC 10 ms
11,484 KB
testcase_04 AC 9 ms
11,484 KB
testcase_05 AC 9 ms
11,716 KB
testcase_06 AC 9 ms
11,608 KB
testcase_07 AC 10 ms
11,560 KB
testcase_08 AC 10 ms
11,492 KB
testcase_09 AC 8 ms
11,620 KB
testcase_10 AC 10 ms
11,552 KB
testcase_11 AC 9 ms
11,716 KB
testcase_12 AC 9 ms
11,608 KB
testcase_13 AC 9 ms
11,808 KB
testcase_14 AC 8 ms
11,660 KB
testcase_15 AC 9 ms
11,496 KB
testcase_16 AC 10 ms
11,496 KB
testcase_17 AC 9 ms
11,472 KB
testcase_18 AC 9 ms
11,492 KB
testcase_19 AC 9 ms
11,620 KB
testcase_20 AC 9 ms
11,608 KB
testcase_21 AC 9 ms
11,616 KB
testcase_22 AC 9 ms
11,612 KB
testcase_23 AC 10 ms
11,664 KB
testcase_24 AC 9 ms
11,604 KB
testcase_25 AC 10 ms
11,744 KB
testcase_26 AC 9 ms
11,616 KB
testcase_27 AC 9 ms
11,668 KB
testcase_28 AC 10 ms
11,744 KB
testcase_29 AC 9 ms
11,664 KB
testcase_30 AC 10 ms
11,620 KB
testcase_31 AC 9 ms
11,488 KB
testcase_32 AC 10 ms
11,488 KB
testcase_33 AC 9 ms
11,604 KB
testcase_34 AC 9 ms
11,752 KB
testcase_35 AC 10 ms
11,624 KB
testcase_36 AC 9 ms
11,556 KB
testcase_37 AC 10 ms
11,488 KB
testcase_38 AC 9 ms
11,612 KB
testcase_39 AC 9 ms
11,624 KB
testcase_40 AC 10 ms
11,552 KB
testcase_41 AC 9 ms
11,660 KB
testcase_42 AC 9 ms
11,600 KB
testcase_43 AC 10 ms
11,496 KB
testcase_44 AC 9 ms
11,484 KB
testcase_45 AC 9 ms
11,600 KB
testcase_46 AC 10 ms
11,496 KB
testcase_47 AC 10 ms
11,596 KB
testcase_48 AC 9 ms
11,552 KB
testcase_49 AC 10 ms
11,488 KB
testcase_50 AC 9 ms
11,480 KB
testcase_51 AC 9 ms
11,472 KB
testcase_52 AC 10 ms
11,552 KB
testcase_53 AC 9 ms
11,680 KB
testcase_54 AC 8 ms
11,808 KB
testcase_55 AC 10 ms
11,556 KB
testcase_56 AC 9 ms
11,624 KB
testcase_57 AC 9 ms
11,540 KB
testcase_58 AC 9 ms
11,616 KB
testcase_59 AC 10 ms
11,480 KB
testcase_60 AC 9 ms
11,560 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:45:12: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   45 | void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
      |            ^~~~

ソースコード

diff #

#include <bits/stdc++.h>  // ver2.2.4
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(iY,0,a.size()){Verr(a[iY]);}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

int stpow(int n){
  if(n==0)return 1;
  int a=1;
  rep(i,1,n+1)a=a*i%MOD;
  return a;
}
Vi stpowV(){
  Vi a(1100001);
  a[0]=1;
  repeq(i,1,1100000)a[i]=a[i-1]*i%MOD;
  return a;
}

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,l,r,k;
  cin >> n >> l >> r >> k;
  Vi stp = stpowV();
  
  int qw,er,ty;
  int depl=0,depr=0;
  qw = 1;
  while(1){
    if(qw*2 <= l) {
      qw *= 2;
      depl++;
    }
    else break;
  }
  depl++;
  cerr << depl <<endl;
  qw = 1;
  while(1){
    if(qw*2 <= r) {
      qw *= 2;
      depr++;
    }
    else break;
  }
  depr++;
  cerr << depr << endl;
  
  if(depl==depr && k==0) {cout<<0<<endl;return 0;}
  //ここまでok
  
  int minn = abs(depl-depr), maxx = depl + depr;
  if(depr==1) maxx -= 2;
  if(depl==1) maxx -= 2;
  
  if(k < minn || k > maxx) {cout<<0<<endl;return 0;}
  if(k%2 != maxx%2) {cout<<0<<endl;return 0;}
  
  int upper = (k-minn)/2, stand = mypow(2,minn,MOD);
  if(upper==0) upper++;
  int deci = stand * mypow(2,upper-1,MOD) % MOD;
  int ue = min(depr,depl);
  deci %= MOD;
  int ans = mypow(2,ue-1,MOD) * deci % MOD;
  ans %= MOD;
  cerr<<"nowans="<<ans<<endl;
  
  repeq(i,1,n){
    qw = mypow(2,i-1,MOD);
    
    if(i==depl) qw--;
    if(i==depr) qw--;
    
    if(qw<0) qw += MOD;
    
    ans = ans * stp[qw] % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
  
  cerr<<'#'<<endl;
  cerr<<deci<<endl;
  
  return 0;
}
0