結果

問題 No.802 だいたい等差数列
ユーザー 37zigen37zigen
提出日時 2019-03-18 02:55:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 844 bytes
コンパイル時間 1,221 ms
コンパイル使用メモリ 144,888 KB
実行使用メモリ 22,072 KB
最終ジャッジ日時 2023-09-22 17:05:23
合計ジャッジ時間 23,298 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 580 ms
21,752 KB
testcase_01 AC 582 ms
21,760 KB
testcase_02 AC 581 ms
21,740 KB
testcase_03 AC 581 ms
21,756 KB
testcase_04 AC 581 ms
21,752 KB
testcase_05 AC 581 ms
21,760 KB
testcase_06 AC 581 ms
21,756 KB
testcase_07 AC 581 ms
21,808 KB
testcase_08 AC 581 ms
21,756 KB
testcase_09 AC 581 ms
21,820 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 582 ms
21,756 KB
testcase_13 WA -
testcase_14 AC 597 ms
22,016 KB
testcase_15 AC 624 ms
21,748 KB
testcase_16 AC 584 ms
21,808 KB
testcase_17 AC 582 ms
21,792 KB
testcase_18 AC 581 ms
21,864 KB
testcase_19 AC 592 ms
21,820 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 621 ms
21,748 KB
testcase_24 AC 581 ms
21,840 KB
testcase_25 AC 582 ms
21,752 KB
testcase_26 AC 582 ms
21,808 KB
testcase_27 AC 580 ms
21,760 KB
testcase_28 AC 622 ms
21,732 KB
testcase_29 WA -
testcase_30 AC 582 ms
21,896 KB
testcase_31 AC 580 ms
21,756 KB
testcase_32 AC 581 ms
21,728 KB
testcase_33 AC 583 ms
21,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

long long mo=(long long)1e9+7;

long long fac[2000000];
long long ifac[2000000];

long long modpow(long long a,long long n){
  long long ret=1;
  for(;n>0;n>>=1,a=a*a%mo){
    if(n%2==1){
      ret=ret*a%mo;
    }
  }
  return ret;
}

long long inv(long a){
  return modpow(a,mo-2);
}

long long comb(int n,int k){
  return fac[n]*ifac[k]%mo*ifac[n-k]%mo;
}

void build(){
  fac[0]=1;
  for(int i=1;i<1000000;++i){
    fac[i]=fac[i-1]*i%mo;
  }
  for(int i=0;i<1000000;++i){
    ifac[i]=inv(fac[i]);
  }
}


int main(){
  build();
  long long N,M,D1,D2;
  std::cin>>N>>M>>D1>>D2;
  long long ans=0;
  for(int i=0;i<=N-1;++i){
    long long  res=M-1-(long long)D1*(N-1)-(long long)i*(D2-D1+1);
    if(res<0)continue;
    ans=(ans+modpow(mo-1,i)*comb(N-1,i)%mo*comb(N+res,res)%mo)%mo;
  }
  std::cout<<ans<<std::endl;
}
0