結果

問題 No.802 だいたい等差数列
ユーザー akakimidoriakakimidori
提出日時 2019-03-17 22:26:47
言語 C
(gcc 12.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,035 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 30,372 KB
実行使用メモリ 11,956 KB
最終ジャッジ日時 2023-09-22 07:50:34
合計ジャッジ時間 2,434 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 RE -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 16 ms
9,696 KB
testcase_11 AC 19 ms
11,788 KB
testcase_12 AC 11 ms
6,420 KB
testcase_13 AC 19 ms
11,464 KB
testcase_14 AC 15 ms
8,724 KB
testcase_15 AC 10 ms
5,640 KB
testcase_16 AC 16 ms
9,276 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 13 ms
7,396 KB
testcase_20 AC 0 ms
4,380 KB
testcase_21 AC 26 ms
11,940 KB
testcase_22 AC 20 ms
11,956 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 RE -
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 12 ms
6,468 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 0 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 8 ms
5,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

const int mod=1000000007;

int inv(int a){
  int t=1;
  while(a>1){
    t=(int64)t*(mod-mod/a)%mod;
    a=mod%a;
  }
  return t;
}

int *fact=NULL;
int *iFact=NULL;
void init(int n){
  fact=(int *)calloc(n+1,sizeof(int));
  fact[0]=1;
  int i;
  for(i=1;i<=n;i++) fact[i]=(int64)fact[i-1]*i%mod;
  iFact=(int *)calloc(n,sizeof(int));
  iFact[n]=inv(fact[n]);
  for(i=n-1;i>=0;i--) iFact[i]=(int64)(i+1)*iFact[i+1]%mod;
}

int comb(int n,int k){
  if(!(0<=k && k<=n)) return 0;
  return (int64)fact[n]*iFact[k]%mod*iFact[n-k]%mod;
}

void run(void){
  int n,m,a,b;
  scanf("%d%d%d%d",&n,&m,&a,&b);
  if(1+(int64)(n-1)*a>m){
    puts("0");
    return;
  }
  m-=(n-1)*a;
  b-=a;
  if(b==0){
    printf("%d\n",m);
    return;
  }
  //0..b,1..m
  init(n+m+1);
  int ans=comb(n+m-1,n);
  for(int i=1;(b+1)*i<=m;i++){
    ans=((int64)ans+mod+(int64)(i&1?-1:1)*comb(n-1,i)*comb(n+(m-i*(b+1))-1,n)%mod)%mod;
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}
0