QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378133 | #7932. AND-OR closure | tylerm390# | WA | 44ms | 19616kb | C++20 | 1.6kb | 2024-04-06 06:26:47 | 2024-04-06 06:26:48 |
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);
}
}
for (int i = 0; i < 20; i++) {
for (int j = 20; j < 40; j++) if (bitat(arr[i], j)) arr[j] |= (1<<i);
}
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: 26ms
memory: 19328kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 18ms
memory: 19616kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 44ms
memory: 19420kb
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:
779
result:
wrong answer 1st numbers differ - expected: '52', found: '779'