#include <bits/stdc++.h>
using namespace std;
const int B = 10;
const int maxn = 1e5 + 5;
int bc[1 << B][1 << B];
struct State {
int len = 0, index = 0;
};
int a[maxn], k[maxn], prv[maxn], res[maxn];
State dp[1 << B][1 << B][B + 1];
int main() {
for (int i = 0; i < (1 << B); i++)
for (int j = 0; j < (1 << B); j++)
bc[i][j] = __builtin_popcount(i & j);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> k[i];
for (int i = 0; i < n; i++) prv[i] = i;
int ans = 1, best = 0;
for (int i = 0; i < n; i++) {
int l = a[i] >> B, r = a[i] & ((1 << B) - 1);
int len = 1;
for (int j = 0; j < (1 << B); j++) {
int need = k[i] - bc[j][l];
if (need >= 0 && need <= B && dp[j][r][need].len + 1 > len) {
len = dp[j][r][need].len + 1;
prv[i] = dp[j][r][need].index;
}
}
if (len > ans) {
ans = len;
best = i;
}
for (int j = 0; j < (1 << B); j++) {
State &cur = dp[l][j][bc[r][j]];
if (len > cur.len) {
cur.len = len;
cur.index = i;
}
}
}
int pos = 0;
while (prv[best] != best) {
res[pos++] = best;
best = prv[best];
}
res[pos++] = best;
cout << ans << "\n";
while (pos--) cout << res[pos] + 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... |