結果
| 問題 | No.2171 OR Assignment |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-23 01:09:48 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 298 ms / 3,500 ms |
| コード長 | 1,264 bytes |
| 記録 | |
| コンパイル時間 | 1,106 ms |
| コンパイル使用メモリ | 86,704 KB |
| 最終ジャッジ日時 | 2025-02-09 18:47:51 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#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;
}