結果
| 問題 |
No.1239 Multiplication -2
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-09-25 22:48:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 864 bytes |
| コンパイル時間 | 1,772 ms |
| コンパイル使用メモリ | 198,792 KB |
| 最終ジャッジ日時 | 2025-01-14 21:20:04 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
constexpr int64_t mod = 998244353;
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int64_t>> dp(n + 1, vector<int64_t>(5)); // dp[i][j] = i-th, j - 2
int64_t ans = 0, d = 1, r = 1;
for (int i = 0; i < n; i++) {
dp[i][3] += d;
for (int j = 0; j <= 4; j++) {
int j_next = 2 + (j - 2) * a[i];
if (0 <= j_next and j_next <= 4) {
dp[i + 1][j_next] += dp[i][j];
dp[i + 1][j_next] %= mod;
}
}
if (i) d *= 2;
d %= mod;
ans *= 2;
ans += dp[i + 1][0];
ans %= mod;
r *= (mod + 1) / 2;
r %= mod;
}
ans += dp[n][0];
ans %= mod;
cout << ans * r % mod << endl;
}
trineutron