結果

問題 No.802 だいたい等差数列
ユーザー heno239
提出日時 2019-03-10 00:36:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 2,174 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 110,040 KB
実行使用メモリ 23,936 KB
最終ジャッジ日時 2024-07-01 19:33:11
合計ジャッジ時間 3,104 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
ll mod_inverse(ll a) {
ll n = mod - 2;
ll res = 1;
while (n) {
if (n & 1)res = res * a%mod;
a = a * a%mod; n >>= 1;
}
return res;
}
const int N_MAX = 1300001;
ll p[N_MAX], invp[N_MAX];
void init() {
p[0] = 1;
rep1(i, N_MAX - 1) {
p[i] = p[i - 1] * i%mod;
}
invp[N_MAX - 1] = mod_inverse(p[N_MAX - 1]);
per(i, N_MAX - 1) {
invp[i] = invp[i + 1] * (i + 1) % mod;
}
}
//xCy
ll comb(ll x, ll y) {
if (x < y || y<0)return 0;
ll res = p[x];
(res *= invp[y]) %= mod;
(res *= invp[x - y]) %= mod;
return res;
}
//xPy
ll comb2(ll x, ll y) {
return p[x] * invp[x - y] % mod;
}
int main() {
init();
ll n, m; cin >> n >> m;
ll d1, d2; cin >> d1 >> d2;
//a1<a2<...<an
//1d2-d1+1
m -= (d1-1)*(n - 1);
d2 -= d1-1;
ll ans = 0;
//i
rep(i, n) {
//d2+1d2n-1
ll rest = m - d2 * i;
//1<=a1<a2<...<an<=mamCn
ll csum = comb(rest, n)*comb(n - 1, i)%mod;
if (i % 2)ans += mod-csum;
else ans += csum;
}
cout << ans % mod << endl;
//stop
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0