#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int B = 10, N = 1e5;
int bc[(1 << B)][(1 << B)];
struct State {
int len = 0;
int end = 0;
} dp[(1 << B)][(1 << B)][B];
int main()
{
// ifstream cin("input.txt");
// ofstream cout("output.txt");
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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, ans = 0, end = 0; cin >> n;
vector<int> a(n), b(n), prv(n, 0);
iota(prv.begin(), prv.end(), 0);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (int i = 0; i < n; i++) {
int k = b[i];
int l = a[i] % (1 << B);
int r = a[i] >> B;
int lbs = 1;
for (int mask = 0; mask < (1 << B); mask++) {
int needed = k - bc[l][mask];
if (needed < 0 || needed > k) continue;
if (dp[mask][r][needed].len + 1 > lbs) {
lbs = dp[mask][r][needed].len + 1;
prv[i] = dp[mask][r][needed].end;
}
}
if (lbs > ans) {
ans = lbs;
end = i;
}
for (int mask = 0; mask < (1 << B); mask++) {
State &new_state = dp[l][mask][bc[r][mask]];
if (lbs > new_state.len) {
new_state.len = lbs;
new_state.end = i;
}
}
}
cout << ans << endl;
vector<int> res;
while (prv[end] != end) {
res.push_back(end);
end = prv[end];
}
res.push_back(end);
reverse(res.begin(), res.end());
for (int x : res) { cout << x + 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... |