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"
#define F first
#define S second
#define ll long long
#define pii pair<ll,ll>
const ll mxN = 5e5 + 5;
const ll mod = 1e9 + 7;
using namespace std;
int a[mxN],b[mxN];
int dp[mxN];
int prv[mxN];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i = 1;i <= n;i++){
cin >>a[i];
}
for(int i = 1;i <= n;i++){
cin >>b[i];
}
int ans = 1;
int mxid = 1;
dp[1] = 1;
for(int i = 2;i <= n;i++){
dp[i] = 1;
for(int j = 1;j < i;j++){
if(__builtin_popcount(a[i] & a[j]) == b[i]) {
if(dp[j] + 1 > dp[i]){
dp[i] = dp[j] + 1;
prv[i] = j;
}
}
}
if(dp[i] > ans){
ans = dp[i];
mxid = i;
}
}
cout<< ans<<'\n';
vector<int>v;
while(mxid){
v.push_back(mxid);
mxid = prv[mxid];
}
reverse(v.begin(),v.end());
for(auto x : v) cout<<x<<' ';
}
# | 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... |