#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const ll LOG = 31;
#define db(x) cerr << #x << " = " << x << " | "
#define dbg(x) cerr << #x << " = " << x << "\n"
#define Algerian ios::sync_with_stdio(0);
#define OI cin.tie(NULL);
int main() {
Algerian OI
ll n;
cin >> n;
vector<ll> a(n), k(n);
ll P = 0;
for (ll i = 0; i < n; i++) {
cin >> a[i];
if (a[i]) P = max(P, 63LL - __builtin_clzll(a[i]) + 1);
}
for (ll i = 0; i < n; i++) cin >> k[i];
vector<ll> dp(1 << P);
ll res = 0, v = -1;
vector<ll> par(n + 1, -1);
map<ll, ll> idx;
for (ll i = 0; i < n; i++) {
ll val = 1, x = -1;
for (ll mask = 0; mask < (1 << P); mask++) {
if (__builtin_popcount(mask & a[i]) != k[i]) continue;
if (dp[mask] + 1 > val) {
x = idx[mask];
val = dp[mask] + 1;
}
}
par[i] = x;
dp[a[i]] = val;
idx[a[i]] = i;
if (dp[a[i]] > res) {
v = i;
res = dp[a[i]];
}
}
vector<ll> ans;
for (ll u = v; u != -1; u = par[u]) {
ans.push_back(u);
}
reverse(ans.begin(), ans.end());
res = ans.size();
cout << res << "\n";
for (ll i = 0; i < res; i++) cout << ans[i] + 1 << " \n"[i == res - 1];
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... |