QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#355777 | #7932. AND-OR closure | ngpin04# | WA | 1ms | 5852kb | C++14 | 4.2kb | 2024-03-17 08:08:05 | 2024-03-17 08:08:06 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
};
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
};
int n;
int sz;
long long A[200003];
long long B[200003];
vector<long long> mem[40];
//
vector<int> vec[45];
//
vector<int> bck[45];
int cnt[45];
long long dp[45];
// is_reachable[i][j] -> j is reachable from i
bool is_reachable[45][45];
bool visited[45];
void dfs(int u, int p)
{
is_reachable[p][u] = true;
for(int v : vec[u])
{
if(is_reachable[p][v]) continue;
dfs(v, p);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
long long SAND = 1LL<<40-1;
for(int i = 1; i <= n; i++)
{
cin >> A[i];
SAND &= A[i];
for(int j = 0; j < 40; j++)
{
long long bit = (1LL<<j);
if(bit&A[i])
mem[j].push_back(A[i]);
}
}
set<long long> st;
for(int j = 0; j < 40; j++)
{
long long sand = (1LL<<40)-1;
if(mem[j].size() == 0) continue;
for(long long x : mem[j])
{
sand &= x;
// cout << j << " " << x << "\n";
}
st.insert(sand);
}
for(long long x : st)
{
B[++sz] = x;
}
for(int i = 1; i <= sz; i++)
{
set<int> idxes = {0};
for(int j = 1; j < i; j++)
{
// cout << i << " " << j << " " << (B[i]&B[j]) << '\n';
if((B[i]&B[j]) == B[j])
{
for(int x : idxes)
{
// cout << B[x] << " " << (B[x]&B[j]) << "\n";
if((B[x]&B[j]) == B[x])
idxes.erase(x);
idxes.insert(j);
}
}
}
for(int idx : idxes)
{
// cout << "EDJ : " << i << " " << idx << "\n";
vec[i].push_back(idx);
bck[idx].push_back(i);
cnt[idx]++;
}
}
for(int i = 0; i < 40; i++)
dfs(i, i);
auto solve = [&]() {
int n = sz + 1;
vector <long long> reach(n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j && is_reachable[i][j])
reach[i] |= bit(j), reach[j] |= bit(i);
if (n == 1) {
return 2LL;
}
int mid = (n >> 1);
vector <int> dp(bit(n - mid), 0);
for (int mask = 0; mask < bit(n - mid); mask++) {
bool ok = true;
for (int i = 0; i < n - mid; i++) if (getbit(mask, i)) {
long long x = ((long long) mask << mid) & reach[i + mid];
if (x > 0)
ok = false;
}
dp[mask] = ok;
}
for (int i = 0; i < n - mid; i++)
for (int mask = 0; mask < bit(n - mid); mask++) {
if (getbit(mask, i))
dp[mask] += dp[mask ^ bit(i)];
}
long long tot = 0;
for (int mask = 0; mask < bit(mid); mask++) {
bool ok = true;
for (int i = 0; i < mid; i++) if (getbit(mask, i)) {
long long x = (long long) mask & reach[i];
if (x > 0)
ok = false;
}
if (ok) {
long long sub = 0;
for (int i = 0; i < mid; i++) if (getbit(mask, i)) {
sub |= reach[i];
}
sub >>= mid;
sub ^= bit(n - mid) - 1;
// cerr << sub << "\n";
tot += dp[sub];
}
}
return tot;
};
long long res = solve()-1;
if(SAND != 0) res--;
cout << res << "\n";
// cerr << log2(17179869184) << " " << bit(34) << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5852kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5596kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5684kb
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'