結果

問題 No.802 だいたい等差数列
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2019-09-21 00:13:18
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,240 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 30,304 KB
実行使用メモリ 13,616 KB
最終ジャッジ日時 2023-10-13 09:00:34
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
13,496 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 21 ms
13,412 KB
testcase_04 AC 21 ms
13,500 KB
testcase_05 AC 22 ms
13,492 KB
testcase_06 AC 22 ms
13,544 KB
testcase_07 AC 21 ms
13,616 KB
testcase_08 AC 21 ms
13,504 KB
testcase_09 AC 22 ms
13,432 KB
testcase_10 AC 22 ms
13,556 KB
testcase_11 WA -
testcase_12 AC 21 ms
13,504 KB
testcase_13 WA -
testcase_14 AC 22 ms
13,596 KB
testcase_15 AC 22 ms
13,588 KB
testcase_16 AC 23 ms
13,596 KB
testcase_17 AC 21 ms
13,464 KB
testcase_18 AC 21 ms
13,432 KB
testcase_19 AC 22 ms
13,552 KB
testcase_20 AC 24 ms
13,444 KB
testcase_21 WA -
testcase_22 AC 21 ms
13,588 KB
testcase_23 WA -
testcase_24 RE -
testcase_25 AC 22 ms
13,508 KB
testcase_26 WA -
testcase_27 AC 21 ms
13,572 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 22 ms
13,556 KB
testcase_31 AC 22 ms
13,428 KB
testcase_32 AC 22 ms
13,432 KB
testcase_33 AC 21 ms
13,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int mod = 1000000007;
int n, m, d1, d2;

/*
[x^m] 1/(1-x) x/(1-x) (x^d1 + ... + x^d2)^{n-1}
[x^m] x/(1-x)^2 x^{d1 (n-1)} [(1 - x^{d2-d1+1}) / (1-x) ]^{n-1}
[x^{m-d1(n-1)-1}] (1 - x^{d2-d1+1})^{n-1} / (1-x)^{n+1}

[x^{k}] (1 - x^{e})^{n-1} / (1-x)^{n+1}

\sum_i (-1)^i\binom{n-1}{i} \binom{k-ie+n}{n}
=
\sum_i (-1)^i (k-ie+n)! / (n i! (n-1-i)! (k-ie)!) 
*/

int modpow(int x, int n){
  int r=1;
  for(;n;n>>=1){
    if(n&1) r = (long long) r * x % mod;
    x = (long long) x * x % mod;
  }
  return r;
}

int fact[1500000];
int ifact[1500000];

int main(){
  int i, k, e, r;
  scanf("%d%d%d%d",&n,&m,&d1,&d2);
  fact[0] = 1;
  for(i=1;i<sizeof(fact)/sizeof(fact[0]);i++)
    fact[i] = (long long) fact[i-1] * i % mod;
  i--;
  ifact[i]=modpow(fact[i], mod-2);
  for(i--;i>=0;i--)
    ifact[i] = (long long) ifact[i+1] * (i+1) % mod;
  k = m - d1*(n-1) - 1;
  e = d2 - d1 + 1;

  if(k < 0){
    puts("0");
    return 0;
  }

  r = 0;
  for(i=0; i<=n-1 && i*e <= k; i++){
    int z;
    z = (long long) fact[k-i*e+n] * ifact[i] % mod * ifact[n-1-i] % mod * ifact[k-i*e] % mod;
    if(i&1) r -= z;
    else r += z;
    r = r % mod;
  }
  r = (long long) r * modpow(n, mod-2) % mod;
  printf("%d\n", r);

  return 0;
}
0