QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309427 | #7932. AND-OR closure | nvujica | WA | 0ms | 3772kb | C++14 | 1.6kb | 2024-01-20 17:17:18 | 2024-01-20 17:17:19 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int maxn = 2e5 + 10, LOG = 3;
int n, m;
ll ost;
ll a[maxn];
ll b[LOG];
ll b2[LOG];
int ima[LOG];
vector <int> v;
void ispis(ll x){
for(int i = 0; i < LOG; i++){
if(x & (1LL << i)) cout << 1;
else cout << 0;
}
cout << endl;
}
ll rek(){
ll sol = 0;
int naj = 0, cnt = 0;
for(int i = 0; i < LOG; i++){
// ispis(b[i]);
if(__builtin_popcount(b[i]) > __builtin_popcount(b[naj])) naj = i;
if(b[i]) cnt++;
}
// cout << endl;
// cout << naj << ' ' << cnt << endl;
if(__builtin_popcount(b[naj]) <= 1) return (1LL << cnt);
// ispis(b[naj]);
// ispis(ost);
ost ^= b[naj];
// cout << "ost:" << endl;
// ispis(ost);
// cout << endl;
for(int i = 0; i < LOG; i++){
b2[i] = b[i];
b[i] &= ost;
}
sol += rek();
for(int i = 0; i < LOG; i++){
b[i] = b2[i];
}
ost ^= b[naj];
ost ^= (1LL << naj);
for(int i = 0; i < LOG; i++){
b2[i] = b[i];
b[i] &= ost;
}
b[naj] = 0;
sol += rek();
ost ^= (1LL << naj);
for(int i = 0; i < LOG; i++){
b[i] = b2[i];
}
return sol;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < LOG; i++){
b[i] = (1LL << 41) - 1;
for(int j = 0; j < n; j++){
if(a[j] & (1 << i)) b[i] &= a[j];
}
if(b[i] == (1LL << 41) - 1) b[i] = 0;
else{
ost ^= (1LL << i);
}
}
cout << rek();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3772kb
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:
10
result:
wrong answer 1st numbers differ - expected: '52', found: '10'