結果
問題 | No.1685 One by One |
ユーザー | hitonanode |
提出日時 | 2021-08-07 15:17:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 250 ms / 3,000 ms |
コード長 | 3,074 bytes |
コンパイル時間 | 961 ms |
コンパイル使用メモリ | 86,260 KB |
実行使用メモリ | 65,920 KB |
最終ジャッジ日時 | 2024-06-29 19:22:43 |
合計ジャッジ時間 | 5,882 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 29 ms
12,800 KB |
testcase_04 | AC | 9 ms
6,940 KB |
testcase_05 | AC | 141 ms
33,536 KB |
testcase_06 | AC | 53 ms
21,504 KB |
testcase_07 | AC | 56 ms
21,888 KB |
testcase_08 | AC | 4 ms
6,944 KB |
testcase_09 | AC | 7 ms
6,944 KB |
testcase_10 | AC | 179 ms
54,784 KB |
testcase_11 | AC | 5 ms
6,940 KB |
testcase_12 | AC | 4 ms
6,944 KB |
testcase_13 | AC | 61 ms
24,704 KB |
testcase_14 | AC | 23 ms
7,808 KB |
testcase_15 | AC | 185 ms
45,952 KB |
testcase_16 | AC | 7 ms
6,944 KB |
testcase_17 | AC | 4 ms
6,940 KB |
testcase_18 | AC | 7 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 59 ms
6,944 KB |
testcase_21 | AC | 13 ms
6,940 KB |
testcase_22 | AC | 69 ms
6,940 KB |
testcase_23 | AC | 20 ms
6,944 KB |
testcase_24 | AC | 182 ms
56,192 KB |
testcase_25 | AC | 222 ms
61,056 KB |
testcase_26 | AC | 196 ms
60,032 KB |
testcase_27 | AC | 207 ms
57,344 KB |
testcase_28 | AC | 210 ms
65,920 KB |
testcase_29 | AC | 233 ms
65,920 KB |
testcase_30 | AC | 206 ms
65,920 KB |
testcase_31 | AC | 238 ms
65,920 KB |
testcase_32 | AC | 250 ms
65,920 KB |
testcase_33 | AC | 229 ms
65,792 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 3 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 69 ms
6,940 KB |
testcase_39 | AC | 71 ms
6,944 KB |
testcase_40 | AC | 15 ms
6,940 KB |
testcase_41 | AC | 15 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 1 ms
6,944 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,940 KB |
testcase_46 | AC | 56 ms
23,296 KB |
testcase_47 | AC | 59 ms
23,296 KB |
testcase_48 | AC | 55 ms
23,296 KB |
testcase_49 | AC | 64 ms
23,296 KB |
ソースコード
#include <cassert> #include <iostream> #include <vector> #include <atcoder/modint> using namespace std; using mint = atcoder::modint1000000007; // atcoder::static_modint<P>, P: prime number template <typename modint> struct acl_fac { std::vector<modint> facs, facinvs; acl_fac(int N) { assert(-1 <= N and N < modint::mod()); facs.resize(N + 1, 1); for (int i = 1; i <= N; i++) facs[i] = facs[i - 1] * i; facinvs.assign(N + 1, facs.back().inv()); for (int i = N; i > 0; i--) facinvs[i - 1] = facinvs[i] * i; } modint ncr(int n, int r) const { if (n < 0 or r < 0 or n < r) return 0; return facs[n] * facinvs[r] * facinvs[n - r]; } modint operator[](int i) const { return facs[i]; } modint finv(int i) const { return facinvs[i]; } }; int main() { int N, M; cin >> N >> M; acl_fac<mint> fac(N + M); vector precalc(N + 1, vector<mint>(M + 1)); precalc[0][0] = 1; for (int n = 0; n <= N; n++) { for (int m = 0; m <= M; m++) { if (n + m - 1 >= 0) precalc[n][m] = fac.ncr(n + m - 1, n - 1); if (m >= 2) precalc[n][m] += precalc[n][m - 2]; } } mint ret = 0; if (N % 2 == 0) { int half = (N - 1) / 2; for (int nnonzero = 0; nnonzero <= half * 2; nnonzero++) { mint coeff = 0; for (int npos = 0; npos <= half; npos++) { int nneg = nnonzero - npos; if (nneg < 0 or nneg > half) continue; coeff += fac.ncr(N - 1, npos) * fac.ncr(N - 1 - npos, nneg); } mint tmp = 0; for (int b0 = 0; b0 <= M; b0++) { if (M - nnonzero - b0 < 0) continue; tmp += precalc.at(nnonzero).at(M - nnonzero - b0) * (b0 == 0 ? 1 : 2); } ret += tmp * coeff; } } else { for (int npos = 0; npos <= N / 2; npos++) { for (int nneg = 0; nneg <= N / 2; nneg++) { int nnonzero = npos + nneg; if (M - nnonzero < 0) continue; ret += fac.ncr(N, nnonzero) * fac.ncr(nnonzero, npos) * precalc[nnonzero][M - nnonzero]; } } for (int npos = 0; npos <= N / 2; npos++) { for (int nneg = 0; nneg <= N / 2; nneg++) { int nnonzero = npos + nneg; int m = M - npos - (N - nneg); if (m < 0) continue; ret += fac.ncr(N, nnonzero) * fac.ncr(nnonzero, npos) * precalc[nnonzero][m] * 2; } } for (int npos = 0; npos <= N / 2; npos++) { for (int nneg = 0; nneg <= N / 2; nneg++) { const int nnonzero = npos + nneg; int m = M - (N - nnonzero) - max(npos, nneg) * 2; if (m < 0) continue; ret -= fac.ncr(N, nnonzero) * fac.ncr(nnonzero, npos) * precalc[nnonzero][m]; } } } cout << ret.val() << '\n'; }