QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#705940 | #7932. AND-OR closure | ohiostatescarlet# | WA | 0ms | 3648kb | C++17 | 2.0kb | 2024-11-03 04:30:34 | 2024-11-03 04:30:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll BIT = 41;
vector<int> component;
int find(int x) {
return (component[x] < 0) ? x : (component[x] = find(component[x]));
}
bool join(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return false;
if (component[x] > component[y]) swap(x,y);
component[x] += component[y];
component[y] = x;
return true;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n; cin >> n;
if (n == 1) {
cout << 1 << "\n";
return 0;
}
bool hasZero = false;
vector<ll> vals(n, 0);
vector<bool> inDeg(BIT, false);
component.assign(BIT, -1);
vector<vector<bool>> edges(BIT, vector<bool>(BIT, false));
int totComp = BIT;
ll vand = -1;
for (int i = 0; i < n; i++) {
ll v; cin >> v;
vand = vand & v;
vals[i] = v;
if (v == 0) hasZero = true;
vector<int> unset;
vector<int> set;
for (int j = 0; j < BIT; j++) {
if ((v>>j)&1) {
set.push_back(j);
} else {
unset.push_back(j);
}
}
for (int a : set) for (int b : unset) {
edges[a][b] = true;
if (edges[b][a]) {
if (join(a,b)) {
totComp--;
}
}
}
}
for (int i = 1; i < BIT; i++) {
for (int j = 0; j < i; j++) {
if (!edges[i][j] && !edges[j][i]) {
join(i, j);
component[find(i)]++;
totComp--;
break;
}
}
}
ll res = -1 + (vand == 0);
for (int i = 0; i < BIT; i++) {
if (find(i) == i) {
// cout << i << " " << component[i] << "\n";
res += (1ll << (-component[i])) - 1;
}
}
cout << res << "\n";
}
/*
4
2 1 7 11
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
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:
2048
result:
wrong answer 1st numbers differ - expected: '52', found: '2048'