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 int long long
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
for (auto x: a) cout << x << " ";
cout << endl;
}
void solve(){
int n; cin >> n;
vector<int> a(n);
FOR(i,0,n) cin >> a[i];
vector<int> k(n);
FOR(i,0,n) cin >> k[i];
vector<int> dp(n, 1);
vector<int> prev(n);
int best = 0;
int c = 0;
FOR(i,0,n){
prev[i] = i;
FOR(j,0,i){
if (__builtin_popcount(a[i]&a[j]) == k[i]){
if (dp[j]+1 > dp[i]){
dp[i] = dp[j]+1;
prev[i] = j;
}
}
}
if (dp[i] > best){
best = dp[i];
c = i;
}
}
cout << best << endl;
vector<int> ans = {};
while (prev[c] != c){
ans.pb(c+1);
c = prev[c];
}
ans.pb(c+1);
reverse(all(ans));
printVector(ans);
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
solve();
}
# | 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... |