QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#514213 | #7932. AND-OR closure | Swarthmore# | WA | 1ms | 3748kb | C++20 | 2.0kb | 2024-08-10 23:05:54 | 2024-08-10 23:05:54 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
const char nl = '\n';
void solve() {
int N; cin >> N;
ll A[N]; F0R(i, N) cin >> A[i];
ll an = A[0];
F0R(i, N) an &= A[i];
F0R(i, N) A[i] ^= an;
const int B = 40;
ll req[B];
F0R(i, B) {
req[i] = (1ll<<B)-1;
F0R(j, N) {
if (A[j]&(1ll<<i)) {
req[i] = req[i] & A[j];
}
}
}
ll rel = 0;
F0R(i, N) rel |= A[i];
F0R(i, B) {
FOR(j, i+1, B) {
if ((req[i] & (1ll<<j)) && (req[j] & (1ll<<i))) {
if (rel&(1ll<<j)) {
rel ^= 1ll<<j;
}
}
}
}
vpi bits;
bool proc[B]; F0R(i, B) proc[i] = false;
ll ans[B];
F0R(i, B) {
if ((rel & (1ll<<i)) == 0) continue;
bits.pb({__builtin_popcountll(req[i]), i});
}
sort(all(bits)); reverse(all(bits));
trav(a, bits) {
int b = a.s;
ans[b] = 1;
F0R(i, B) {
if ((req[i] & (1ll<<b)) && (rel & (1ll<<i)) && !proc[i] && b != i) {
proc[i] = true;
ans[b] *= ans[i];
}
}
ans[b]++;
}
ll res = 1;
F0R(i, B) {
if ((rel & (1ll<<i)) && !proc[i]) {
res *= ans[i];
}
}
cout << res << nl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3748kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3604kb
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:
208
result:
wrong answer 1st numbers differ - expected: '52', found: '208'