結果

問題 No.802 だいたい等差数列
ユーザー tko919tko919
提出日時 2020-01-10 17:35:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,553 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 169,388 KB
実行使用メモリ 18,940 KB
最終ジャッジ日時 2023-08-15 14:34:32
合計ジャッジ時間 4,610 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
18,796 KB
testcase_01 AC 30 ms
18,708 KB
testcase_02 AC 31 ms
18,744 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 30 ms
18,800 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 31 ms
18,768 KB
testcase_07 AC 31 ms
18,924 KB
testcase_08 AC 30 ms
18,712 KB
testcase_09 AC 31 ms
18,820 KB
testcase_10 AC 30 ms
18,784 KB
testcase_11 AC 30 ms
18,796 KB
testcase_12 AC 30 ms
18,752 KB
testcase_13 AC 31 ms
18,732 KB
testcase_14 AC 31 ms
18,776 KB
testcase_15 AC 31 ms
18,652 KB
testcase_16 AC 31 ms
18,672 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 32 ms
18,716 KB
testcase_20 AC 35 ms
18,672 KB
testcase_21 AC 34 ms
18,716 KB
testcase_22 AC 31 ms
18,872 KB
testcase_23 AC 34 ms
18,940 KB
testcase_24 RE -
testcase_25 AC 30 ms
18,780 KB
testcase_26 AC 31 ms
18,800 KB
testcase_27 AC 30 ms
18,640 KB
testcase_28 AC 33 ms
18,700 KB
testcase_29 AC 34 ms
18,940 KB
testcase_30 AC 31 ms
18,704 KB
testcase_31 AC 31 ms
18,656 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 31 ms
18,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<unsigned mod>struct mint {
   static int get_mod(){return mod;}
   int val;
   int inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=(ll)val*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=(ll)val*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
using Mint=mint<1000000007>;
struct factorial {
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
   int N,M,D1,D2; scanf("%d%d%d%d",&N,&M,&D1,&D2);
   int d=D2-D1+1,m=M-D1*(N-1)-1;
   if(m<0){printf("0\n"); return 0;}
   factorial fact(2010000); Mint res;
   rep(i,0,N){
      if(m-d*i+N<0)break;
      Mint add=fact.nCr(N-1,i)*fact.nCr(m-d*i+N,N);
      if(i&1)add*=-1; res+=add;
   }
   printf("%d\n",res.val);
   return 0;
}
0