QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376931 | #7932. AND-OR closure | vioalbert | WA | 53ms | 6292kb | C++14 | 3.9kb | 2024-04-04 19:15:42 | 2024-04-04 19:15:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n, N) for (int i = (n); i <= (N); i++)
#define For(i, n, N) for (int i = (n); i < (N); i++)
#define rap(i, n, N) for (int i = (n); i >= (N); i--)
#define rip(i, n, N, V) for (int i = (n); i <= (N); i += V)
using vi = vector<int>;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
// using lll = __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
// using plll = pair<lll, lll>;
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define endl '\n'
#define clz(x) (1 << (31 - __builtin_clz(x)))
#define all(x) x.begin(), x.end()
#define ari(x) array<int, x>
#define arll(x) array<ll, x>
#define mems(x, y) memset(x, y, sizeof x)
#define debug(x) cout << #x << " = " << (x) << endl
#define debugV(v, x) cout << #v << "[" << (x) << "] = " << v[x] << endl
#define out(x, y) cout << "]] " << (x) << " " << (y) << endl
#ifdef LOCAL
#define DEBUG(...) __VA_ARGS__;
#else
#define DEBUG(...)
#endif
template<class A, class B>
ostream& operator<<(ostream& os, const pair<A, B> &p) {
return os << "(" << p.fi << ", " << p.se << ")";
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &v) {
os << "{"; bool osu = 1;
for (auto i : v) {if (!osu) {os << ", ";} os << i; osu = 0;}
return os << "}";
}
template<class T, ull sz>
ostream& operator<<(ostream& os, const array<T, sz> &v) {
os << "{"; bool osu = 1;
for (auto i : v) {if (!osu) {os << ", ";} os << i; osu = 0;}
return os << "}";
}
void solve(int tt = 0) {
int n; cin >> n;
vector<ll> a(n);
for(ll &i : a) cin >> i;
vector<ll> b;
For(bit, 0, 40) {
int cnt = 0;
ll mask = ~0ll;
For(i, 0, n) if(a[i] >> bit & 1) {
cnt++;
mask &= a[i];
}
if(cnt > 0 && cnt < n)
b.pb(mask);
}
ll all_mask = ~0ll;
for(ll i : a) all_mask &= i;
// b.pb(all_mask);
sort(all(b));
DEBUG(cerr << b << '\n');
DEBUG({
set<ll> s;
int sz = b.size();
For(mask, 1, 1<<sz) {
ll cur = 0;
For(i, 0, sz) if(mask >> i & 1) cur |= b[i];
s.insert(cur);
cerr << mask << " -> " << cur << '\n';
}
cerr << s.size() + 1 << '\n';
});
int sz = b.size();
// int sz1 = 2, sz2 = sz-sz1;
int sz1 = sz/2, sz2 = sz-sz1;
ll ans = 0;
vector<ll> dp(1<<sz1, -1);
dp[0] = all_mask;
map<int, int> val;
val[all_mask] = 0;
For(mask, 1, 1<<sz1) {
ll cur = 0;
For(i, 0, sz1) if(mask >> i & 1) cur |= b[i];
bool ok = 1;
For(i, 0, sz1) if(mask >> i & 1) {
if(cur == dp[mask^(1<<i)]) {
ok = 0;
}
}
if(ok) val[cur] = max(val[cur], mask);
dp[mask] = cur;
}
// ans = val.size();
DEBUG(cerr << vector(all(val)) << '\n');
vector<int> F(1<<sz1);
for(auto &[v, i] : val)
F[i] = 1;
For(i, 0, sz1) For(mask, 0, 1<<sz1) {
if(mask >> i & 1)
F[mask] += F[mask^(1<<i)];
}
DEBUG(cerr << "F = " << F << '\n');
val.clear();
dp.clear();
dp.resize(1<<sz2);
dp[0] = all_mask;
val[all_mask] = 0;
For(mask, 1, 1<<sz2) {
ll cur = 0;
For(i, 0, sz2) if(mask >> i & 1) cur |= b[i+sz1];
bool ok = 1;
For(i, 0, sz2) if(mask >> i & 1) {
if(cur == dp[mask^(1<<i)]) {
ok = 0;
}
}
int msk = mask<<sz1;
if(ok) val[cur] = max(val[cur], msk);
dp[mask] = cur;
}
DEBUG(cerr << vector(all(val)) << '\n');
for(auto [v, i] : val) {
int fmask = (1<<sz1)-1;
DEBUG(cerr << v << ' ' << (fmask^(v&fmask)) << ' ' << F[fmask^(fmask&v)] << '\n');
ans += F[fmask ^ (v&fmask)];
}
cout << ans << '\n';
}
int main() {
int t = 1; //cin >> t;
rep(ct, 1, t) solve(ct);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3764kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 53ms
memory: 6292kb
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:
78
result:
wrong answer 1st numbers differ - expected: '52', found: '78'