結果
| 問題 |
No.802 だいたい等差数列
|
| ユーザー |
tarattata1
|
| 提出日時 | 2019-09-28 07:52:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,081 bytes |
| コンパイル時間 | 783 ms |
| コンパイル使用メモリ | 72,664 KB |
| 実行使用メモリ | 32,568 KB |
| 最終ジャッジ日時 | 2024-10-01 09:22:37 |
| 合計ジャッジ時間 | 8,377 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 RE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:72:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
72 | scanf("%d%d%d%d", &N, &M, &D1, &D2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
const int max_comb=1400000;
vector<ll> fac(max_comb+1); //n! (mod M)
vector<ll> ifac(max_comb+1); //k!^(-1) (mod M)
ll mpow(ll x, ll n){ //x^n(mod M)
ll ans = 1;
while(n != 0){
if(n&1) ans = ans*x % MOD;
x = x*x % MOD;
n = n >> 1;
}
return ans;
}
ll minv(ll x){
return mpow( x, MOD-2 );
}
ll comb(int a, int b){ // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
if(a == 0 && b == 0)return 1;
if(a < b || a < 0)return 0;
ll tmp = ifac[a-b]* ifac[b] % MOD;
return tmp * fac[a] % MOD;
}
ll perm(int a, int b){ // P(a,b) = a! * (a-b)!^(-1)
if(b == 0)return 1;
if(a < b || a < 0)return 0;
ll tmp = ifac[a-b] % MOD;
return tmp * fac[a] % MOD;
}
void pre_comb()
{
fac[0] = 1;
ifac[0] = 1;
for(int i = 0; i<max_comb; i++){
fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
ifac[i+1] = ifac[i]*minv(i+1) % MOD; // k!^(-1) (mod M)
}
return;
}
int main(int argc, char* argv[])
{
int N,M,D1,D2;
scanf("%d%d%d%d", &N, &M, &D1, &D2);
int d = D2 - D1;
int m = M - D1*(N-1)-1;
if(m<0) {
printf("0\n"); return 0;
}
pre_comb();
vector<ll> a(m+1);
int i;
for(i=0; i<=m; i++) {
a[i]=comb(i+N-1, i);
}
for(i=1; i<=m; i++) {
a[i]=(a[i]+a[i-1])%MOD;
}
ll ans=0;
for(i=0; i<N; i++) {
int tmp=m-i*(d+1);
if(tmp<0) break;
ll ans0 = (a[tmp] * (i%2==0? 1: MOD-1))%MOD;
ans0 = ans0 * comb(N-1, i) %MOD;
ans = (ans + ans0) %MOD;
}
printf("%lld\n", ans);
return 0;
}
tarattata1