結果

問題 No.1239 Multiplication -2
ユーザー りあんりあん
提出日時 2020-09-05 10:41:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 202,248 KB
実行使用メモリ 5,624 KB
最終ジャッジ日時 2023-08-18 15:53:17
合計ジャッジ時間 4,361 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 15 ms
5,416 KB
testcase_18 AC 16 ms
5,384 KB
testcase_19 AC 15 ms
5,624 KB
testcase_20 AC 17 ms
5,444 KB
testcase_21 AC 18 ms
5,336 KB
testcase_22 AC 17 ms
5,080 KB
testcase_23 AC 14 ms
4,528 KB
testcase_24 AC 14 ms
4,576 KB
testcase_25 AC 8 ms
4,376 KB
testcase_26 AC 13 ms
4,620 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 18 ms
5,048 KB
testcase_29 AC 20 ms
5,068 KB
testcase_30 AC 9 ms
4,376 KB
testcase_31 AC 13 ms
4,376 KB
testcase_32 AC 20 ms
5,392 KB
testcase_33 AC 14 ms
4,544 KB
testcase_34 AC 14 ms
4,592 KB
testcase_35 AC 7 ms
4,380 KB
testcase_36 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int M = 998244353;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<long long> pw(n + 1);
    pw[0] = 1;
    int inv = (M + 1) / 2;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pw[i + 1] = pw[i] * inv % M;
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        if (abs(a[i]) < 2) continue;
        vector<long long> c = { pw[min(i, 1)], 0 };
        int s = 1;
        for (int j = i - 1; j >= 0; --j) {
            s *= a[j];
            if (s == 1) {
                c[0] = (c[0] + pw[min(i, i - j + 1)]) % M;
            }
            else if (s == -1) {
                c[1] = (c[1] + pw[min(i, i - j + 1)]) % M;
            }
            else break;
        }
        int b = 1;
        for (int j = i; j < n; ++j) {
            b *= a[j];
            if (b == -2) {
                ans = (ans + c[0] * pw[min(n - i - 1, j - i + 1)]) % M;
            }
            else if (b == 2) {
                ans = (ans + c[1] * pw[min(n - i - 1, j - i + 1)]) % M;
            }
            else break;
        }
    }
    cout << ans << '\n';
    return 0;
}
0