結果
問題 |
No.802 だいたい等差数列
|
ユーザー |
![]() |
提出日時 | 2019-03-10 01:42:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 992 bytes |
コンパイル時間 | 1,613 ms |
コンパイル使用メモリ | 170,576 KB |
実行使用メモリ | 33,712 KB |
最終ジャッジ日時 | 2024-07-01 19:34:03 |
合計ジャッジ時間 | 3,370 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> 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) typedef long long ll; const ll mod=1e9+7 ; vector<ll> inv,fact,invfact; void mod_build(int n=101010){ fact.resize(n+1); inv.resize(n+1); invfact.resize(n+1); fact[0]=inv[0]=invfact[0]=1; inv[1]=1; rep(i,n){ fact[i+1]=fact[i]*(i+1)%mod; if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod; invfact[i+1]=invfact[i]*inv[i+1]%mod; } } ll perm(int n,int k){ if(n<0||k<0||k>n)return 0; return fact[n]*invfact[n-k]%mod; } ll comb(ll n,ll k){ if(n<0||k<0||k>n)return 0; return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod; } int main(){ ll n,m,d1,d2; cin>>n>>m>>d1>>d2; assert(2<=n&&n<=300000); assert(1<=m&&m<=1000000); assert(0<=d1&&d1<=d2&&d2<=m); m-=(n-1)*(d1-1); d2-=d1-1; mod_build(max(m+1,n)); ll ans=0; rep(i,n){ ll ret=comb(m-d2*i,n)*comb(n-1,i)%mod; if(i%2)ans+=mod-ret; else ans+=ret; } cout<<ans%mod<<endl; return 0; }