結果

問題 No.2171 OR Assignment
ユーザー suisensuisen
提出日時 2022-12-23 01:09:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 3,500 ms
コード長 1,264 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 88,876 KB
実行使用メモリ 36,972 KB
最終ジャッジ日時 2024-04-29 05:50:43
合計ジャッジ時間 5,238 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 164 ms
27,776 KB
testcase_13 AC 160 ms
27,880 KB
testcase_14 AC 164 ms
27,904 KB
testcase_15 AC 38 ms
14,836 KB
testcase_16 AC 43 ms
14,836 KB
testcase_17 AC 48 ms
14,976 KB
testcase_18 AC 109 ms
29,208 KB
testcase_19 AC 94 ms
29,184 KB
testcase_20 AC 126 ms
34,908 KB
testcase_21 AC 125 ms
35,840 KB
testcase_22 AC 140 ms
36,692 KB
testcase_23 AC 235 ms
36,864 KB
testcase_24 AC 221 ms
36,780 KB
testcase_25 AC 216 ms
36,816 KB
testcase_26 AC 189 ms
36,804 KB
testcase_27 AC 169 ms
36,864 KB
testcase_28 AC 169 ms
36,736 KB
testcase_29 AC 199 ms
36,972 KB
testcase_30 AC 249 ms
36,796 KB
testcase_31 AC 138 ms
36,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

constexpr int L = 30;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (auto &&e : a) std::cin >> e;

    std::array<int, L> last;
    last.fill(-1);

    std::vector<std::vector<int>> pos(n);

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < L; ++j) {
            if ((a[i] >> j) & 1) {
                last[j] = i;
            } else if (last[j] >= 0) {
                pos[i].push_back(last[j]);
            }
        }
        std::sort(pos[i].begin(), pos[i].end());
        pos[i].erase(std::unique(pos[i].begin(), pos[i].end()), pos[i].end());
        pos[i].push_back(i);
    }

    std::vector<mint> pd { 0, 1 };
    for (int i = 1; i < n; ++i) {
        const int psiz = pos[i - 1].size(), siz = pos[i].size();
        std::vector<mint> dp(siz + 1);
        for (int k = 0, j = 0; k < siz; ++k) {
            while (j < psiz and pos[i - 1][j] <= pos[i][k]) ++j;
            dp[k + 1] = dp[k] + pd[j];
        }
        pd.swap(dp);
    }
    std::cout << pd.back().val() << std::endl;
    return 0;
}
0