結果

問題 No.802 だいたい等差数列
ユーザー yyyuuuummmmaaa1
提出日時 2019-11-11 19:17:03
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 814 ms / 2,000 ms
コード長 4,279 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 163,712 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-09-15 05:20:20
合計ジャッジ時間 31,396 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0