#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int a[n],k[n],maxai=0,ans=1,ind=0;
	for(int i=0; i<n; i++)cin>>a[i];
	for(int i=0; i<n; i++)maxai=max(a[i],maxai);
	for(int i=0; i<n; i++)cin>>k[i];
	vector<int> dp(maxai),curr(maxai),last(n,-1);
	dp[0]=1;
	curr[0]=0;
	for(int i=1; i<n; i++){
		dp[a[i]]=max(dp[a[i]],1);
		for(int j=0; j<=maxai; j++){
			if(__builtin_popcount(a[i]&j)==k[i]){
				if(dp[a[i]]<dp[j]+1){
					last[i]=curr[j];
					curr[a[i]]=i;
					dp[a[i]]=dp[j]+1;
					
					if(dp[a[i]]>ans)ind=i;
				}
			}
		}
		ans=max(ans,dp[a[i]]);
	}
		vector<int> the;
		while(last[ind]!=-1){
			the.push_back(ind+1);
			ind=last[ind];
		}
			the.push_back(ind+1);
	cout<<ans<<endl;
	for(int i=the.size()-1; i>=0; i--)cout<<the[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... |