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;
const int N = 1e5+3;
const int bits=21;
int dp[1<<bits], prv[1<<bits], from[1<<bits], a[N], b[N];
int main()
{
int n;
cin >> n;
for(int i=1; i<= n; i++)cin >> a[i];
for(int i=1; i<= n; i++)cin >> b[i];
set<int> st;
vector<int> occ;
for(int i=1; i<=n; i++){
int val=1;
int mxind=0;
for(int j : occ){
if(__builtin_popcount(j&a[i])==b[i]){
if(dp[j]+1>val){
val=dp[j]+1;
mxind=j;
}
}
}
if(val>dp[a[i]]){
from[a[i]]=i;
dp[a[i]]=val;
prv[a[i]]=mxind;
}
if(st.find(a[i])==st.end()){
st.insert(a[i]);
occ.push_back(a[i]);
}
}
int ans=0, cur=0;
for(int i : occ){
if(dp[i]>ans){
ans=dp[i];
cur=from[i];
}
}
cout << ans << '\n';
vector<int> cons;
while(cur!=0){
cons.push_back(cur);
cur=from[prv[a[cur]]];
}
reverse(cons.begin(), cons.end());
for(int e : cons)cout << e << " ";
cout << '\n';
}
# | 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... |