結果

問題 No.2171 OR Assignment
ユーザー lddlinanlddlinan
提出日時 2023-03-28 13:41:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,517 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 92,596 KB
実行使用メモリ 121,208 KB
最終ジャッジ日時 2023-10-20 08:21:42
合計ジャッジ時間 15,189 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,436 KB
testcase_01 AC 3 ms
11,436 KB
testcase_02 AC 3 ms
11,436 KB
testcase_03 AC 4 ms
11,436 KB
testcase_04 AC 3 ms
11,436 KB
testcase_05 AC 4 ms
11,436 KB
testcase_06 AC 4 ms
11,436 KB
testcase_07 AC 2 ms
9,388 KB
testcase_08 AC 3 ms
9,388 KB
testcase_09 AC 3 ms
11,436 KB
testcase_10 AC 3 ms
11,436 KB
testcase_11 AC 4 ms
11,440 KB
testcase_12 AC 301 ms
121,208 KB
testcase_13 AC 301 ms
121,208 KB
testcase_14 AC 303 ms
121,208 KB
testcase_15 AC 88 ms
121,204 KB
testcase_16 AC 112 ms
121,204 KB
testcase_17 AC 102 ms
121,204 KB
testcase_18 AC 2,640 ms
121,208 KB
testcase_19 AC 2,573 ms
121,208 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 dpc[200004];
int dpk[200000][32];
int dpv[200000][32];
int can[200000][32];
int cc[200000];
#define MOD 998244353
int gn;
set<int> ss;
int dfs(int p, int i) {
    if (i>=gn) return 1;
    int k; for (k=0; k<dpc[i]; k++) if (dpk[i][k]==p) return dpv[i][k];
    dpc[i]++;
    dpk[i][k]=p;
    ss.clear();
    int zz[32];
    int j; for (j=0; j<cc[i]; j++) if ((can[i][j]&p)==can[i][j]) {
        ss.insert(can[i][j]|as[i]);
    }
    j=0; for (auto x: ss) zz[j++]=x;
    LL r=dfs(as[i], i+1);
    while(j) {
        j--;
        if (zz[j]==as[i]) continue;
        r+=dfs(zz[j], i+1); r%=MOD;
    }
    dpv[i][k]=r;
    return r;
}
int xx[32];
int main() {
    int n, i, j, c;
    c=0; 
    scanf("%d", &n); gn=n;
    for (i=0; i<n; i++) scanf("%d", &as[i]);
    for (i=0; i<n; i++) {
        dpc[i]=0;
        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;
    }
    printf("%d\n", dfs(0, 0));
    return 0;
}
0