#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXA = (1 << 8);
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (auto& el : a)
cin >> el;
vector<int> k(n);
for (auto& el : k)
cin >> el;
vector<pair<int, int>> dp(MAXA);
vector<int> par(n);
for (int i = 0; i < n; ++i) {
int bst = 1, bstpa = -1;
for (int j = 0; j < MAXA; ++j) {
if (__builtin_popcount((a[i]) & j) == k[i]) {
if (dp[j].first + 1 > bst) {
bst = dp[j].first + 1;
bstpa = dp[j].second;
}
}
}
par[i] = bstpa;
dp[a[i]] = max(dp[a[i]], pair<int, int>{bst, i});
}
int mx = 0, mxi = 0;
for (int i = 0; i < MAXA; ++i) {
if (dp[i].first > mx) {
mx = dp[i].first;
mxi = dp[i].second;
}
}
cout << mx << '\n';
int cur = mxi;
vector<int> ans;
while (cur != -1) {
ans.push_back(cur);
cur = par[cur];
}
reverse(ans.begin(), ans.end());
for (auto el : ans)
cout << el + 1 << ' ';
}
# | 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... |