結果

問題 No.802 だいたい等差数列
ユーザー AquariusAquarius
提出日時 2019-03-18 21:07:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 640 ms / 2,000 ms
コード長 1,411 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 167,176 KB
実行使用メモリ 30,096 KB
最終ジャッジ日時 2023-09-26 09:17:38
合計ジャッジ時間 9,925 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,368 KB
testcase_01 AC 3 ms
5,384 KB
testcase_02 AC 3 ms
5,392 KB
testcase_03 AC 3 ms
5,352 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,344 KB
testcase_06 AC 3 ms
5,360 KB
testcase_07 AC 3 ms
5,360 KB
testcase_08 AC 2 ms
5,348 KB
testcase_09 AC 3 ms
5,340 KB
testcase_10 AC 497 ms
27,092 KB
testcase_11 AC 540 ms
29,760 KB
testcase_12 AC 172 ms
16,140 KB
testcase_13 AC 548 ms
29,868 KB
testcase_14 AC 345 ms
26,152 KB
testcase_15 AC 237 ms
17,980 KB
testcase_16 AC 357 ms
26,376 KB
testcase_17 AC 161 ms
11,824 KB
testcase_18 AC 132 ms
9,632 KB
testcase_19 AC 231 ms
20,032 KB
testcase_20 AC 474 ms
26,396 KB
testcase_21 AC 640 ms
29,900 KB
testcase_22 AC 551 ms
30,096 KB
testcase_23 AC 198 ms
16,004 KB
testcase_24 AC 164 ms
11,864 KB
testcase_25 AC 2 ms
5,400 KB
testcase_26 AC 165 ms
13,912 KB
testcase_27 AC 137 ms
11,784 KB
testcase_28 AC 196 ms
15,908 KB
testcase_29 AC 632 ms
29,876 KB
testcase_30 AC 2 ms
5,536 KB
testcase_31 AC 2 ms
5,340 KB
testcase_32 AC 2 ms
5,332 KB
testcase_33 AC 228 ms
18,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T t; cin >> t; return t; }

const long mod = 1000000007;

long powmod(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return powmod(b, e - 1) * b % mod;
  long t = powmod(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return powmod(n, mod - 2);
}

long f[2000001];
long combi(long n, long r) {
  if (r < 0 || r > n) return 0;
  return f[n] * inv(f[r] * f[n - r] % mod) % mod;
}

long hcombi(long n, long r) {
  if (r < 0) return 0;
  return combi(n + r - 1, r);
}

long p[1000001];
long q[1000001];
void pre(long n, long m) {
  f[0] = 1;
  for (long i = 1; i <= n + m; ++i) {
    f[i] = f[i - 1] * i % mod;
  }
  
  for (long i = 0; i < max(n, m); ++i) {
    p[i + 1] = (p[i] + hcombi(n, i)) % mod;
    q[i + 1] = (q[i] + i * hcombi(n, i) % mod) % mod;
  }
}

long sub(long n, long m, long l) {
  pre(n, m);
  
  long sum = 0;
  for (long k = 0; k <= min(n, m); ++k) {
    long s = m - l * k;
    if (s < 0) continue;
    long a = s * p[s] % mod;
    long b = q[s];
    long c = (a + mod - b) % mod;
    long d = k % 2 == 0 ? 1 : mod - 1;
    long e = combi(n, k) * c % mod * d % mod;
    sum = (sum + e) % mod;
  }
  return sum;
}

int main() {
  long n, m, a, b;
  cin >> n >> m >> a >> b;
  cout << sub(n - 1, m - a * (n - 1), b - a + 1) << endl;
  return 0;
}
0