結果
問題 | No.1239 Multiplication -2 |
ユーザー | SSRS |
提出日時 | 2020-09-25 23:05:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,999 bytes |
コンパイル時間 | 2,392 ms |
コンパイル使用メモリ | 213,272 KB |
実行使用メモリ | 21,172 KB |
最終ジャッジ日時 | 2024-06-28 07:17:29 |
合計ジャッジ時間 | 6,979 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 140 ms
21,044 KB |
testcase_18 | AC | 177 ms
14,716 KB |
testcase_19 | AC | 140 ms
20,004 KB |
testcase_20 | WA | - |
testcase_21 | AC | 303 ms
6,940 KB |
testcase_22 | AC | 209 ms
6,944 KB |
testcase_23 | AC | 225 ms
6,940 KB |
testcase_24 | AC | 157 ms
6,940 KB |
testcase_25 | AC | 21 ms
6,940 KB |
testcase_26 | AC | 174 ms
6,940 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const long long INV = 499122177; 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> 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; cin >> N; vector<int> a(N + 2, 0); for (int i = 1; i <= N; i++){ cin >> a[i]; } N += 2; vector<long long> pow(N); pow[0] = 1; for (int i = 1; i < N; i++){ pow[i] = pow[i - 1] * INV % MOD; } long long ans = 0; for (int i = 0; i < N; i++){ if (abs(a[i]) == 2){ vector<long long> L1, L2; L1.push_back(0); L2.push_back(0); int p = 1; for (int j = i - 1; j >= 0; j--){ if (abs(a[j]) == 1){ p *= a[j]; if (p == 1){ L1.push_back(1); L2.push_back(0); } else { L1.push_back(0); L2.push_back(1); } } else { break; } } vector<long long> R1, R2; R1.push_back(0); R2.push_back(0); p = 1; for (int j = i + 1; j < N; j++){ if (abs(a[j]) == 1){ p *= a[j]; if (p == 1){ R1.push_back(1); R2.push_back(0); } else { R1.push_back(0); R2.push_back(1); } } else { break; } } if (a[i] == 2){ vector<long long> C1 = convolution(L1, R2); int sz1 = C1.size(); for (int j = 0; j < sz1; j++){ ans += C1[j] * pow[j + 2] % MOD; ans %= MOD; } vector<long long> C2 = convolution(L2, R1); int sz2 = C2.size(); for (int j = 0; j < sz2; j++){ ans += C2[j] * pow[j + 2] % MOD; ans %= MOD; } } else { L1[0] = 1; R1[0] = 1; vector<long long> C1 = convolution(L1, R1); int sz1 = C1.size(); for (int j = 0; j < sz1; j++){ ans += C1[j] * pow[j + 2] % MOD; ans %= MOD; } vector<long long> C2 = convolution(L2, R2); int sz2 = C2.size(); for (int j = 0; j < sz2; j++){ ans += C2[j] * pow[j + 2] % MOD; ans %= MOD; } ans %= MOD; } } } int prod = 1; for (int i = 1; i < N - 2; i++){ prod *= a[i]; if (prod == -2){ ans += MOD - pow[i + 1]; ans += pow[i]; } else if (abs(prod) > 2 || prod == 0){ break; } } prod = 1; for (int i = N - 2; i >= 1; i--){ prod *= a[i]; if (prod == -2){ if (i > 1){ ans += MOD - pow[N - i]; ans += pow[N - 1 - i]; } else { ans += MOD - pow[N - i]; ans += pow[N - 2 - i]; } } else if (abs(prod) > 2 || prod == 0){ break; } } ans %= MOD; cout << ans << endl; }