結果
問題 | No.1670 Many Gacha |
ユーザー | SSRS |
提出日時 | 2021-09-03 22:21:38 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 276 ms / 2,000 ms |
コード長 | 2,731 bytes |
コンパイル時間 | 1,895 ms |
コンパイル使用メモリ | 179,344 KB |
実行使用メモリ | 31,572 KB |
最終ジャッジ日時 | 2024-05-09 04:45:49 |
合計ジャッジ時間 | 10,161 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 4 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 269 ms
31,036 KB |
testcase_09 | AC | 272 ms
31,380 KB |
testcase_10 | AC | 270 ms
31,228 KB |
testcase_11 | AC | 201 ms
29,504 KB |
testcase_12 | AC | 208 ms
29,948 KB |
testcase_13 | AC | 197 ms
29,336 KB |
testcase_14 | AC | 258 ms
31,252 KB |
testcase_15 | AC | 243 ms
31,076 KB |
testcase_16 | AC | 254 ms
31,200 KB |
testcase_17 | AC | 227 ms
30,872 KB |
testcase_18 | AC | 244 ms
31,052 KB |
testcase_19 | AC | 226 ms
30,872 KB |
testcase_20 | AC | 268 ms
31,436 KB |
testcase_21 | AC | 251 ms
31,288 KB |
testcase_22 | AC | 248 ms
31,064 KB |
testcase_23 | AC | 264 ms
31,396 KB |
testcase_24 | AC | 147 ms
18,200 KB |
testcase_25 | AC | 240 ms
30,380 KB |
testcase_26 | AC | 204 ms
28,956 KB |
testcase_27 | AC | 205 ms
29,180 KB |
testcase_28 | AC | 192 ms
28,456 KB |
testcase_29 | AC | 237 ms
30,004 KB |
testcase_30 | AC | 203 ms
28,824 KB |
testcase_31 | AC | 211 ms
28,964 KB |
testcase_32 | AC | 202 ms
28,924 KB |
testcase_33 | AC | 266 ms
31,184 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 218 ms
30,732 KB |
testcase_36 | AC | 276 ms
31,572 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long modpow(long long a, long long b){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; } long long modinv(long long a){ return modpow(a, MOD - 2); } vector<long long> mf = {1}; vector<long long> mfi = {1}; long long modfact(int n){ if (mf.size() > n){ return mf[n]; } else { for (int i = mf.size(); i <= n; i++){ long long next = mf.back() * i % MOD; mf.push_back(next); mfi.push_back(modinv(next)); } return mf[n]; } } long long modfactinv(int n){ if (mfi.size() > n){ return mfi[n]; } else { return modinv(modfact(n)); } } long long modbinom(int n, int k){ if (n < 0 || k < 0 || k > n){ return 0; } else { return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD; } } vector<long long> ntt(vector<long long> A, bool inv){ int N = A.size(); long long r = 3; if (inv){ r = modinv(r); } vector<long long> B(N); for (int i = N / 2; i > 0; i /= 2){ long long z = modpow(r, (MOD - 1) / (N / i)); long long z2 = 1; for (int j = 0; j < N; j += i * 2){ for (int k = 0; k < i; k++){ A[i + j + k] *= z2; A[i + j + k] %= MOD; B[j / 2 + k] = (A[j + k] + A[i + j + k]) % MOD; B[N / 2 + j / 2 + k] = (A[j + k] - A[i + j + k] + MOD) % MOD; } z2 = z2 * z % MOD; } swap(A, B); } if (inv){ int Ninv = modinv(N); for (int i = 0; i < N; i++){ A[i] = A[i] * Ninv % MOD; } } return A; } vector<long long> convolution(vector<long long> A, vector<long long> B, int d = -1){ int deg = A.size() + B.size() - 1; int N = 1; while (N < deg){ N *= 2; } A.resize(N); B.resize(N); A = ntt(A, false); B = ntt(B, false); vector<long long> ans(N); for (int i = 0; i < N; i++){ ans[i] = A[i] * B[i] % MOD; } ans = ntt(ans, true); if (d != -1){ deg = d; } ans.resize(deg); return ans; } int main(){ int N, M; cin >> N >> M; vector<int> A(M); for (int i = 0; i < M; i++){ cin >> A[i]; } vector<int> B(N, -1); for (int i = 0; i < M; i++){ for (int j = N - A[i]; j < N; j++){ if (B[j] != -1){ break; } B[j] = A[i]; } } long long ans = 0; vector<long long> f(N + 1); for (int i = 0; i <= N; i++){ f[i] = modfact(N - 1 - i) * B[i] % MOD; } vector<long long> g(N + 1); for (int i = 0; i <= N; i++){ g[i] = modfactinv(i); } vector<long long> h = convolution(f, g); for (int i = 0; i < N; i++){ long long M = 1; M *= modinv(modbinom(N, i)); M *= modinv(N - i); M %= MOD; M *= modfactinv(N - 1 - i); M %= MOD; ans += M * h[i] % MOD; } ans %= MOD; cout << ans << endl; }