結果

問題 No.802 だいたい等差数列
ユーザー bachoppibachoppi
提出日時 2020-08-06 18:04:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,511 bytes
コンパイル時間 2,580 ms
コンパイル使用メモリ 119,580 KB
実行使用メモリ 237,956 KB
最終ジャッジ日時 2023-10-21 13:57:12
合計ジャッジ時間 9,600 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 396 ms
237,956 KB
testcase_01 AC 390 ms
237,956 KB
testcase_02 AC 404 ms
237,956 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 390 ms
237,956 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 405 ms
237,956 KB
testcase_07 AC 395 ms
237,956 KB
testcase_08 AC 407 ms
237,956 KB
testcase_09 AC 401 ms
237,956 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define pai 3.141592653589793238462643383279


const int MAX = 10000000;
const int MOD = 1000000007;

long long 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;
    }
}

// 二項係数計算
long long 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;
}


int main(){
  int n, m, d1, d2; cin >> n >> m >> d1 >> d2;
  int zenbu = m-1-(n-1)*d1;
  if(zenbu<0){
    cout << 0 << endl; return 0;
  }
  COMinit(); ll ans = 0;
  rep(i, n){
    if(i%2){
      ans-=COM(zenbu+n-(d2-d1+1)*i, n)*COM(n-1, i)%mod; if(ans<0) ans+=mod; ans%=mod;
    }
    else{
      ans+=COM(zenbu+n-(d2-d1+1)*i, n)*COM(n-1, i); ans%=mod;
    }
    //cout << ans << endl;
  }
  cout << ans << endl;
}
0