QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378134 | #7932. AND-OR closure | tylerm390# | WA | 12ms | 19652kb | C++20 | 1.9kb | 2024-04-06 06:43:24 | 2024-04-06 06:43:24 |
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 < 40; i++) {
for (int j = 0; j < 40; j++) if (bitat(arr[i], j)) arr[j] |= (1ll<<i);
}
for (int i = 0; i < 40; i++) {
if (arr[i]) arr[i] -= (1ll<<i);
else arr[i] = -1;
}
// for (int i = 0; i < 40; i++) cout << (1ll<<i) << ": " << arr[i] << endl;
vll ways(1<<20);
ways[0] = 1;
for (int i = 1; i < (1<<20); i++) {
int low = __builtin_ctz(i);
ways[i] = ways[i&(i-1)]*((arr[low]&i) == 0);
}
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];
}
}
ll res = ways[(1<<20)-1];
vll ways2(1<<20);
// cout << res << "\n";
for (ll i = 1; i < (1<<20); i++) {
int low = __builtin_ctz(i);
ways2[i] = ways2[i&(i-1)] | arr[low+20];
if ((ways2[i]&(i<<20)) == 0) {
// cout << i << " " << ways2[i] << " " << (1ll<<20)-1-(ways2[i]&((1<<20)-1)) << endl;
res += ways[(1ll<<20)-1-(ways2[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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 12ms
memory: 19516kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 7ms
memory: 19516kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 8ms
memory: 19652kb
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:
1184
result:
wrong answer 1st numbers differ - expected: '52', found: '1184'