結果

問題 No.802 だいたい等差数列
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-02-25 15:56:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,142 bytes
コンパイル時間 5,077 ms
コンパイル使用メモリ 263,808 KB
実行使用メモリ 73,800 KB
最終ジャッジ日時 2024-04-08 13:28:21
合計ジャッジ時間 21,820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
73,800 KB
testcase_01 AC 194 ms
73,800 KB
testcase_02 AC 187 ms
73,800 KB
testcase_03 AC 200 ms
73,800 KB
testcase_04 AC 183 ms
73,800 KB
testcase_05 AC 184 ms
73,800 KB
testcase_06 AC 184 ms
73,800 KB
testcase_07 AC 181 ms
73,800 KB
testcase_08 AC 186 ms
73,800 KB
testcase_09 AC 181 ms
73,800 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 186 ms
73,800 KB
testcase_15 AC 192 ms
73,800 KB
testcase_16 AC 188 ms
73,800 KB
testcase_17 AC 179 ms
73,800 KB
testcase_18 AC 182 ms
73,800 KB
testcase_19 AC 183 ms
73,800 KB
testcase_20 AC 188 ms
73,800 KB
testcase_21 AC 188 ms
73,800 KB
testcase_22 RE -
testcase_23 AC 189 ms
73,800 KB
testcase_24 AC 185 ms
73,800 KB
testcase_25 AC 184 ms
73,800 KB
testcase_26 AC 180 ms
73,800 KB
testcase_27 RE -
testcase_28 AC 190 ms
73,800 KB
testcase_29 AC 190 ms
73,800 KB
testcase_30 AC 188 ms
73,800 KB
testcase_31 AC 185 ms
73,800 KB
testcase_32 AC 183 ms
73,800 KB
testcase_33 AC 187 ms
73,800 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 = 3000000;
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(int n,int 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-1-d1*(n-1);
  if(tmp<0){
    cout<<0<<endl;
    return 0;
  }
  ll ans=0;
  for(int i=0;i<n;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