QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591563 | #7932. AND-OR closure | ucup-team3519# | WA | 22ms | 7360kb | C++17 | 2.4kb | 2024-09-26 16:28:54 | 2024-09-26 16:28:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define all1(x) (x).begin() + 1, (x).end()
#define all0(x) (x).begin(), (x).end()
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pi;
typedef long long LL;
void solve() {
int n; cin >> n;
V<LL> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
V<LL> final;
for(int i = 0; i < 40; i++) {
LL cur = (1LL << 40) - 1;
bool hav = 0;
for(int j = 1; j <= n; j++) {
if(a[j] >> i & 1) {
cur &= a[j];
hav = 1;
}
}
if(hav) final.pb(cur);
}
sort(all0(final));
final.erase(unique(all0(final)), final.end());
sort(all0(final), [&](LL a, LL b){
return __popcount(a) > __popcount(b);
});
n = final.size();
V<V<int>> e(n);
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if((final[i] | final[j]) == final[i]) {
e[i].pb(j);
}
}
}
auto fine = [&](int shift, int bit) -> bool {
for(int i = 0; i < 20; i++) {
if(bit >> i & 1) {
if(i + shift >= n) {
return 0;
}
for(auto y : e[i + shift]) {
y -= shift;
if(y >= 20) continue;
if(!(bit >> y & 1)) {
return 0;
}
}
}
}
return 1;
};
V<int> tab(1 << 20);
for(int i = 0; i < (1 << 20); i++) {
if(fine(20, i)) {
tab[i]++;
}
}
for(int i = 0; i < 20; i++) {
for(int j = 0; j < (1 << 20); j++) {
if(!(j >> i & 1)) {
tab[j] += tab[j + (1 << i)];
}
}
}
LL ans = 0;
for(int i = 0; i < (1 << 20); i++) {
if(fine(0, i)) {
int need = 0;
for(int j = 0; j < 20; j++) {
if(i >> j & 1) {
for(auto y : e[j]) {
if(y >= 20) {
need |= (1 << y - 20);
}
}
}
}
ans += tab[need];
}
}
cout << ans << endl;
}
int main() {
// int t; cin >> t;
int t = 1;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 22ms
memory: 7360kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 19ms
memory: 7328kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 18ms
memory: 7176kb
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:
53
result:
wrong answer 1st numbers differ - expected: '52', found: '53'