QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357819 | #7932. AND-OR closure | ec1117 | WA | 0ms | 3684kb | C++14 | 2.5kb | 2024-03-19 13:04:20 | 2024-03-19 13:04:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define f first
#define s second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define For(i,a) FOR(i,0,a)
#define trav(a,b) for(auto& a:b)
#define pi pair<int,int>
#define vi vector<int>
#define vl vector<ll>
const int MX = 2e5+5;
const int MOD = 1e9+7;
const ll INF = 1e18;
ll a[MX];
set<int> reps[40];
bool done[40];
vi todo[42];
ll ans[44];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
int n;cin>>n;
bool hasZero = false;
For(i,n) {
cin>>a[i];
if(!a[i]) {
hasZero = true;
}
}
if (n==1 && hasZero) {
cout << 1 << endl;
return 0;
}
ll t2 = a[0]==0?a[1]:a[0];
For(i,n) {
if(a[i]!=0)
t2 &= a[i];
}
int zz = 42;
if(t2) {
int mx = -1;
For(k,40) if(t2 & (1LL<<k)) {
mx = k;
}
ans[mx] = 1;
zz= mx;
} else {
ans[42] = 1;
}
For(i,40) {
ll tmp = -1;
For(j,n) if(a[j] & (1LL<<i)) {
if(tmp==-1) {
tmp=a[j];
} else {
tmp &= a[j];
}
}
if(tmp!=-1) {
// cout << "A " << tmp << endl;
For(k,40) if(tmp & (1LL<<k)) {
// cout << "B " << i << " " << k << endl;
reps[i].insert(k);
}
// cout << "ADD: " << i << endl;
todo[reps[i].size()].pb(i);
ans[i] = 1;
}
}
// ans[42] = 1;
// ll ans = 1;
// For(i,44)ans[i] = 1;
for(int i=41;i>=0;i--) {
vector<bool> done(42);
sort(all(todo[i]));
reverse(all(todo[i]));
trav(x,todo[i]) if(!done[x]) {
pi tmp = {0,42};
trav(y,reps[x]) if(reps[y].size() < reps[x].size()){
tmp = max(tmp, {reps[y].size(),y});
}
trav(z,reps[x]) {
done[z] = true;
}
int PAR = tmp.s;
ans[PAR] *= (1+ans[x]);
// cout << "C " << i << " " << tmp.f << " " << tmp.f2 << " " << tmp.s << endl;
// cout << "D " << x << " " << ans[x] << endl;
}
}
int add = 0;
if(zz!=42 && hasZero)
add = 1;
cout << ans[zz] + add << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3684kb
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'