QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#611924 | #7932. AND-OR closure | ATM12345 | WA | 60ms | 12648kb | C++17 | 1.5kb | 2024-10-05 00:21:08 | 2024-10-05 00:21:08 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define Ma 1000005
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(x) x.begin(),x.end()
#define N 40
#define Ne 20
using namespace std;
ll n;
ll a[Ma];
ll col[N],nocol[N];
ll ans=0;
ll cnt[1<<Ne];
ll lowbit(ll x)
{
return x&(-x);
}
void sol()
{
cin>>n;
vector <ll> v;
ll all=(1ll<<N)-1;
ll mi=all,ma=0;
for (ll i=1;i<=n;i++){
ll x;
cin>>x;
for (ll j=0;j<N;j++)
for (ll k=0;k<N;k++)
if ((x>>j&1)&&!(x>>k&1))
col[j]|=(1ll<<k),nocol[k]|=(1ll<<j);
mi&=x,ma|=x;
}
/*for (ll i=0;i<N;i++)// ok size
col[i]^=all,nocol[i]^=all;*/
//for (ll i=0;i<N;i++)
// printf("i=%lld col=%lld nocol=%lld\n",i,col[i]&ma,nocol[i]&ma);
for (ll i=0;i<(1ll<<Ne);i++)// pre
{
if ((ma|i)!=ma)
continue;
cnt[i]=1;
//printf("i=%lld\n",i);
for (ll j=i,x=0;x<N;x++)
{
if (!(j>>x&1))
continue;
ll ne=j&col[x];
cnt[i]+=cnt[ne];
j&=nocol[x];
}
}
for (ll i=0;i<(1ll<<Ne);i++)
{
if ((ma|i)!=ma)
continue;
ll ne=all,be=(i<<Ne)+(ma%(1ll<<Ne));
for (ll j=Ne;j<N;j++)
if ((i<<Ne)>>j&1)
continue;
else
be&=nocol[j];
//if (be>(1ll<<Ne))
// printf("i=%lld be=%lld\n",i,be);
if ((be&(i<<Ne))==(i<<Ne))
{
//printf("i=%lld add=%lld\n",i,cnt[be]);
ans+=cnt[be%(1ll<<Ne)];
}
}
printf("%lld\n",ans);
}
int main()
{
IOS
ll tt=1;
//cin>>tt;
while (tt--)
sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5796kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5876kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 60ms
memory: 12648kb
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:
11
result:
wrong answer 1st numbers differ - expected: '52', found: '11'