結果
問題 | No.802 だいたい等差数列 |
ユーザー | Aquarius |
提出日時 | 2019-03-18 21:06:06 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,411 bytes |
コンパイル時間 | 1,457 ms |
コンパイル使用メモリ | 167,164 KB |
実行使用メモリ | 25,168 KB |
最終ジャッジ日時 | 2023-09-26 09:13:48 |
合計ジャッジ時間 | 8,303 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,372 KB |
testcase_01 | AC | 3 ms
5,344 KB |
testcase_02 | AC | 3 ms
5,320 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,412 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,368 KB |
testcase_07 | AC | 3 ms
5,388 KB |
testcase_08 | AC | 2 ms
5,328 KB |
testcase_09 | AC | 3 ms
5,588 KB |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | AC | 171 ms
15,924 KB |
testcase_13 | RE | - |
testcase_14 | AC | 346 ms
24,324 KB |
testcase_15 | AC | 239 ms
18,012 KB |
testcase_16 | AC | 360 ms
24,592 KB |
testcase_17 | AC | 163 ms
11,828 KB |
testcase_18 | AC | 133 ms
9,696 KB |
testcase_19 | AC | 233 ms
20,012 KB |
testcase_20 | AC | 469 ms
25,168 KB |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | AC | 199 ms
15,964 KB |
testcase_24 | AC | 167 ms
12,080 KB |
testcase_25 | AC | 2 ms
5,372 KB |
testcase_26 | AC | 168 ms
13,892 KB |
testcase_27 | AC | 139 ms
11,788 KB |
testcase_28 | AC | 198 ms
15,908 KB |
testcase_29 | RE | - |
testcase_30 | AC | 2 ms
5,372 KB |
testcase_31 | AC | 2 ms
5,316 KB |
testcase_32 | AC | 2 ms
5,332 KB |
testcase_33 | AC | 228 ms
18,068 KB |
ソースコード
#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[1000001]; 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; }