This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=998244353;
const int N=(1<<20);
int bitcount[N],best[N],id[N];
signed main()
{
// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n; cin>>n;
int a[n],k[n],sol[n],par[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<(1<<20);i++){
int x=i;
while(x>0){
if(x%2==1)bitcount[i]++;
x/=2;
}
best[i]=0;
id[i]=0;
}
int ans=0,idx=0;
for(int i=0;i<n;i++){
cin>>k[i];
sol[i]=1;
par[i]=i;
for(int j=0;j<(1<<8);j++){
// if(i==3 && j==3)cout<<(a[i]&j)<<' '<<k[i]<<' '<<best[j]+1<<endl;
if(bitcount[(a[i]&j)]==k[i] && best[j]+1>sol[i]){
sol[i]=best[j]+1;
par[i]=id[j];
}
}
if(sol[i]>best[a[i]]){
best[a[i]]=sol[i];
id[a[i]]=i;
}
if(ans<sol[i]){
ans=sol[i]; idx=i;
}
}
cout<<ans<<endl;
vector<int> v;
while(1){
int x=idx;
v.pb(x+1);
idx=par[idx];
if(idx==x)break;
}
for(int i=v.size()-1;i>=0;i--)cout<<v[i]<<" ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |