結果
問題 | No.2513 Power Eraser |
ユーザー | SSRS |
提出日時 | 2023-10-20 22:11:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5,716 ms / 6,000 ms |
コード長 | 3,774 bytes |
コンパイル時間 | 3,642 ms |
コンパイル使用メモリ | 252,732 KB |
実行使用メモリ | 35,448 KB |
最終ジャッジ日時 | 2024-09-20 19:27:53 |
合計ジャッジ時間 | 53,516 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
35,448 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 7 ms
5,376 KB |
testcase_04 | AC | 60 ms
5,376 KB |
testcase_05 | AC | 11 ms
5,376 KB |
testcase_06 | AC | 86 ms
5,376 KB |
testcase_07 | AC | 35 ms
5,376 KB |
testcase_08 | AC | 73 ms
5,376 KB |
testcase_09 | AC | 110 ms
5,376 KB |
testcase_10 | AC | 69 ms
5,376 KB |
testcase_11 | AC | 10 ms
5,376 KB |
testcase_12 | AC | 54 ms
5,376 KB |
testcase_13 | AC | 1,801 ms
15,724 KB |
testcase_14 | AC | 4,097 ms
27,724 KB |
testcase_15 | AC | 4,265 ms
28,224 KB |
testcase_16 | AC | 2,344 ms
16,680 KB |
testcase_17 | AC | 2,878 ms
18,140 KB |
testcase_18 | AC | 3,988 ms
27,548 KB |
testcase_19 | AC | 5,613 ms
30,048 KB |
testcase_20 | AC | 1,937 ms
15,924 KB |
testcase_21 | AC | 4,222 ms
28,124 KB |
testcase_22 | AC | 4,246 ms
27,976 KB |
testcase_23 | AC | 5,615 ms
29,944 KB |
testcase_24 | AC | 5,559 ms
30,068 KB |
testcase_25 | AC | 5,608 ms
30,076 KB |
testcase_26 | AC | 5,625 ms
30,072 KB |
testcase_27 | AC | 5,621 ms
30,076 KB |
testcase_28 | AC | 5,606 ms
30,072 KB |
testcase_29 | AC | 5,606 ms
30,072 KB |
testcase_30 | AC | 5,631 ms
30,072 KB |
testcase_31 | AC | 5,712 ms
30,072 KB |
testcase_32 | AC | 5,707 ms
30,072 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 5,704 ms
30,072 KB |
testcase_36 | AC | 5,716 ms
30,204 KB |
7_evil_case_1.txt | TLE | - |
7_evil_case_2.txt | TLE | - |
7_evil_case_3.txt | TLE | - |
7_evil_case_4.txt | TLE | - |
7_evil_case_5.txt | TLE | - |
ソースコード
#include <bits/stdc++.h> #include <atcoder/convolution> 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> diff(vector<long long> A){ int N = A.size(); vector<long long> B(N - 1); for (int i = 1; i < N; i++){ B[i - 1] = A[i] * i % MOD; } return B; } vector<long long> polynomial_inverse(vector<long long> f){ int N = f.size(); vector<long long> ans(1); ans[0] = modinv(f[0]); for (int i = 1; i < N * 2; i *= 2){ vector<long long> ans2 = ans; ans2.resize(i * 4); int N2 = min(N, i * 2); vector<long long> f2(i * 4, 0); for (int j = 0; j < N2; j++){ f2[j] = f[j]; } ans2 = atcoder::convolution(ans2, ans2); ans2.resize(i * 2); ans2 = atcoder::convolution(ans2, f2); ans2.resize(i * 2); for (int j = 0; j < i; j++){ ans2[j] = MOD - ans2[j] + ans[j] * 2; ans2[j] %= MOD; } swap(ans, ans2); } ans.resize(N); return ans; } vector<long long> polynomial_quotient(vector<long long> f, vector<long long> g){ int N = f.size(), M = g.size(); if (N < M){ return {0}; } reverse(g.begin(), g.end()); g.resize(N - M + 1); vector<long long> t = polynomial_inverse(g); reverse(f.begin(), f.end()); vector<long long> q = atcoder::convolution(f, t); q.resize(N - M + 1); reverse(q.begin(), q.end()); return q; } vector<long long> polynomial_remainder(vector<long long> f, vector<long long> g){ int N = f.size(); int M = g.size(); if (M <= 100){ for (int i = N - M; i >= 0; i--){ long long q = f[i + M - 1] * modinv(g[M - 1]) % MOD; for (int j = 0; j < M; j++){ f[i + j] += MOD - q * g[j] % MOD; f[i + j] %= MOD; } f.pop_back(); } return f; } else { vector<long long> q = polynomial_quotient(f, g); vector<long long> b = atcoder::convolution(g, q); for (int i = 0; i < N; i++){ f[i] += MOD - b[i]; f[i] %= MOD; } f.resize(M - 1); return f; } } vector<long long> multipoint_evaluation(vector<long long> &f, vector<long long> x){ int M = x.size(); int M2 = 1; while (M2 < M){ M2 *= 2; } vector<vector<long long>> g(M2 * 2 - 1, {1}); for (int i = 0; i < M; i++){ g[M2 - 1 + i] = vector<long long>{MOD - x[i], 1}; } for (int i = M2 - 2; i >= 0; i--){ g[i] = atcoder::convolution(g[i * 2 + 1], g[i * 2 + 2]); } g[0] = polynomial_remainder(f, g[0]); for (int i = 1; i < M2 * 2 - 1; i++){ g[i] = polynomial_remainder(g[(i - 1) / 2], g[i]); } vector<long long> ans(M); for (int i = 0; i < M; i++){ ans[i] = g[M2 - 1 + i][0]; } return ans; } int main(){ int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } long long ans = 1; auto dfs = [&](auto dfs, int L, int R){ if (R - L == 1){ return; } int m = (L + R) / 2; vector<vector<long long>> P(m - L); for (int i = 0; i < m - L; i++){ P[i] = {MOD - A[L + i], 1}; } for (int i = m - L - 1; i >= 1; i--){ P[i / 2] = atcoder::convolution(P[i / 2], P[i]); P.pop_back(); } vector<long long> f = P[0]; vector<long long> x(R - m); for (int i = 0; i < R - m; i++){ x[i] = A[m + i]; } vector<long long> y = multipoint_evaluation(f, x); for (int i = 0; i < R - m; i++){ ans *= y[i]; ans %= MOD; } dfs(dfs, L, m); dfs(dfs, m, R); }; dfs(dfs, 0, N); if ((long long) N * (N - 1) / 2 % 2 == 1){ ans = (MOD - ans) % MOD; } cout << ans << endl; }