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;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n),k(n);
for(int i=0;i<n;i++)cin >> a[i];
for(int i=0;i<n;i++)cin >> k[i];
vector<int> dp(n,1);
vector<int> prev(n,-1);
int best=-1,best_pos=-1;
for(int i=0;i<n;i++){
if(a[i]>=256){
cout << "1\n1";
return 0;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(__builtin_popcount(a[i]&a[j])==k[i]){
if(dp[i]<dp[j]+1){
dp[i]=dp[j]+1;
prev[i]=j;
}
}
}
if(best<=dp[i]){
best=dp[i];
best_pos=i;
}
}
vector<int> out;
cout << best << '\n';
for(int i=0;i<best;i++){
out.push_back(best_pos);
best_pos = prev[best_pos];
}
for(int i=best-1;i>=0;i--)cout << out[i]-10 <<' ';
cout << '\n';
return 0;
}
# | 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... |