QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378132 | #7932. AND-OR closure | tylerm390# | WA | 30ms | 19576kb | C++20 | 1.5kb | 2024-04-06 06:09:39 | 2024-04-06 06:09:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using pii = pair<int, int>;
using vvi = vector<vi>;
using vll = vector<ll>;
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define bitat(x, i) (((x)>>(i))&(1))
void solve() {
int n;
cin >> n;
vector<ll> arr(40, 0);
ll tot = (1ll<<40)-1;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
tot &= x;
for (int j = 0; j < 40; j++) {
if (bitat(x, j)) arr[j] = (arr[j] == 0 ? x : arr[j]&x);
}
}
vll ways(1<<20);
for (int i = 1; i < (1<<20); i++) {
ways[i] = ways[i&(i-1)] | (arr[__builtin_ctz(i)]-(i&-i)) | ((!arr[__builtin_ctz(i)])*((1ll<<20)-1));
}
for (int i = 0; i < (1<<20); i++) {
if (i&ways[i]) ways[i] = 0;
else ways[i] = 1;
}
for (int bit = 1; bit < (1<<20); bit *= 2) {
for (int i = 0; i < (1<<20); i++) {
if ((i^bit) < i) ways[i] += ways[i^bit];
}
}
vll ways2(1<<20);
for (int i = 1; i < (1<<20); i++) {
ways2[i] = ways2[i&(i-1)] | (arr[__builtin_ctz(i)+20]);
}
sort(all(ways2));
ways2.erase(unique(all(ways2)), ways2.end());
ll res = 0;
for (int i : ways2) res += ways[(1ll<<20)-1-(i&&((1<<20)-1))];
cout << res - (tot != 0) << "\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 23ms
memory: 19496kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 22ms
memory: 19528kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 30ms
memory: 19576kb
input:
49 1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...
output:
6214
result:
wrong answer 1st numbers differ - expected: '52', found: '6214'