結果

問題 No.802 だいたい等差数列
ユーザー yyyuuuummmmaaa1yyyuuuummmmaaa1
提出日時 2019-11-11 19:17:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 843 ms / 2,000 ms
コード長 4,279 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 148,452 KB
実行使用メモリ 19,444 KB
最終ジャッジ日時 2023-10-13 08:10:09
合計ジャッジ時間 33,710 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 834 ms
19,192 KB
testcase_01 AC 828 ms
19,220 KB
testcase_02 AC 826 ms
19,132 KB
testcase_03 AC 828 ms
19,216 KB
testcase_04 AC 828 ms
19,196 KB
testcase_05 AC 827 ms
19,216 KB
testcase_06 AC 829 ms
19,132 KB
testcase_07 AC 825 ms
19,128 KB
testcase_08 AC 831 ms
19,216 KB
testcase_09 AC 831 ms
19,240 KB
testcase_10 AC 830 ms
19,248 KB
testcase_11 AC 830 ms
19,192 KB
testcase_12 AC 832 ms
19,196 KB
testcase_13 AC 825 ms
19,444 KB
testcase_14 AC 831 ms
19,312 KB
testcase_15 AC 832 ms
19,140 KB
testcase_16 AC 830 ms
19,196 KB
testcase_17 AC 833 ms
19,144 KB
testcase_18 AC 832 ms
19,192 KB
testcase_19 AC 832 ms
19,440 KB
testcase_20 AC 842 ms
19,188 KB
testcase_21 AC 839 ms
19,400 KB
testcase_22 AC 829 ms
19,380 KB
testcase_23 AC 833 ms
19,148 KB
testcase_24 AC 829 ms
19,132 KB
testcase_25 AC 831 ms
19,136 KB
testcase_26 AC 833 ms
19,196 KB
testcase_27 AC 831 ms
19,420 KB
testcase_28 AC 835 ms
19,128 KB
testcase_29 AC 843 ms
19,392 KB
testcase_30 AC 831 ms
19,252 KB
testcase_31 AC 833 ms
19,196 KB
testcase_32 AC 832 ms
19,192 KB
testcase_33 AC 833 ms
19,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

#define WHATS(var)cout<<__LINE__<<' '<<#var<<"="<<var<<endl;

template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
int i=0;
for(auto it:v){
	if(i > 0){os << ' ';}
	os << it;
	i++;
} 
return os;
}
/*
1 2 3 4 5 6 7 8 9 10 11 12 13 14

12 1 11
13 3 10
14 5 9
15 7 8
16 2 14
17 4 13
18 6 12

1-12

11 1 10
12 3 9
13 5 8
13 6 7
14 2 12
15 4 11
*/

const int MAX_X=2220;

using ll=long long ;



const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 2024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}
int main() {
	init();
	ios::sync_with_stdio(false);
	ll N,M,D1,D2;cin>>N>>M>>D1>>D2;
	M-=1+D1*(N-1);
	Mod answer=0;
	if(M<0){
		
	}else{
		ll K=D2-D1;
		for(int over=0;over<=N-1;++over){
			Mod val=over%2?Mod(-1):Mod(1);
			ll rest=M-(K+1)*over;
			
			if(rest<0)break;
			else{

				Mod cnt=comb(N-1,over)*comb(N+rest,N);
				answer+=val*cnt;
			}
		}
	
	}
	cout<<answer.num<<endl;
	return 0;
}
0