結果

問題 No.802 だいたい等差数列
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-02-25 16:02:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 745 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 5,764 ms
コンパイル使用メモリ 260,568 KB
実行使用メモリ 355,260 KB
最終ジャッジ日時 2023-07-24 11:22:32
合計ジャッジ時間 30,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 745 ms
354,988 KB
testcase_01 AC 658 ms
355,240 KB
testcase_02 AC 655 ms
354,972 KB
testcase_03 AC 649 ms
354,952 KB
testcase_04 AC 664 ms
355,096 KB
testcase_05 AC 666 ms
354,992 KB
testcase_06 AC 650 ms
354,976 KB
testcase_07 AC 670 ms
355,176 KB
testcase_08 AC 664 ms
355,108 KB
testcase_09 AC 661 ms
354,976 KB
testcase_10 AC 666 ms
355,044 KB
testcase_11 AC 665 ms
355,044 KB
testcase_12 AC 661 ms
354,948 KB
testcase_13 AC 667 ms
354,952 KB
testcase_14 AC 663 ms
354,972 KB
testcase_15 AC 660 ms
354,972 KB
testcase_16 AC 670 ms
355,028 KB
testcase_17 AC 670 ms
355,056 KB
testcase_18 AC 674 ms
355,116 KB
testcase_19 AC 674 ms
354,956 KB
testcase_20 AC 677 ms
355,052 KB
testcase_21 AC 671 ms
354,988 KB
testcase_22 AC 667 ms
355,168 KB
testcase_23 AC 667 ms
355,112 KB
testcase_24 AC 680 ms
355,180 KB
testcase_25 AC 661 ms
355,032 KB
testcase_26 AC 666 ms
355,180 KB
testcase_27 AC 662 ms
355,044 KB
testcase_28 AC 657 ms
355,044 KB
testcase_29 AC 665 ms
354,972 KB
testcase_30 AC 671 ms
355,260 KB
testcase_31 AC 742 ms
354,988 KB
testcase_32 AC 655 ms
355,092 KB
testcase_33 AC 657 ms
354,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define P pair<ll,ll>
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
void YesNo(bool a){if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
constexpr ll MAX = 15000000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll HOM(ll n,ll k){
  if(n+k-1>=n-1&&n-1>=0){
  return COM(n+k-1,n-1);
  }
  else{
    return 0;
  }
}
int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  COMinit();
  ll n,m,d1,d2;
  cin>>n>>m>>d1>>d2;
  ll d=d2-d1;
  ll tmp=m-d1*(n-1)-1;
  if(tmp<0){
    cout<<0<<endl;
    return 0;
  }
  ll ans=0;
  for(int i=0;i<=n-1;i++){
    ll k=COM(n-1,i)*COM(tmp+n-i*(d+1),n)%mod;
    if(i%2){
      ans-=k;
      ans%=mod;
      ans+=mod;
      ans%=mod;
    }
    else{
      ans+=k;
      ans%=mod;
    }
  }
  cout<<ans<<endl;
}
0