結果

問題 No.2171 OR Assignment
コンテスト
ユーザー lddlinan
提出日時 2023-03-28 15:37:46
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,339 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 719 ms
コンパイル使用メモリ 106,176 KB
実行使用メモリ 55,552 KB
最終ジャッジ日時 2026-06-30 02:26:34
合計ジャッジ時間 5,542 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};



int as[200004];
int dp[200000][32];
int can[200004][32];
int cc[200004];
#define MOD 998244353
int xx[32];
int main() {
    int n, i, j, c, s, k, v;
    set<int> ss;
    scanf("%d", &n);
    for (i=0; i<n; i++) scanf("%d", &as[i]);
    c=0;  xx[c++]=0;
    for (i=0; i<n; i++) {
        cc[i]=c; for (j=0; j<c; j++) can[i][j]=xx[j];
        ss.clear();
        for (j=0; j<c; j++) ss.insert(xx[j]|as[i]); ss.insert(as[i]);
        c=0; for (auto x: ss) xx[c++]=x;
    }
    cc[i]=c; for (j=0; j<c; j++) can[i][j]=xx[j];
    for (j=0; j<c; j++) dp[n][j]=1;
    for (i=n-1; i>=0; i--) {
        s=0;
        for (j=0, k=0; j<cc[i]; j++) {
            v=can[i][j]|as[i];
            while(k<cc[i+1]&&(can[i+1][k]&v)==can[i+1][k]) {
                s+=dp[i+1][k]; k++;
                s%=MOD;
            }
            dp[i][j]=s;
        }
    }
    printf("%d\n", dp[0][0]);
    return 0;
}
0