#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;
const ll N = (1 << 10);
int dp[N][N][11], ind[N][N][11], bc[N][N];
void solve() {
memset(dp, 0, sizeof(dp)), memset(ind, -1, sizeof(ind));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
bc[i][j] = __builtin_popcount(i & j);
}
}
int n;
cin >> n;
vector<int> a(n), k(n), p(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> k[i];
}
iota(p.begin(), p.end(), 0);
int ans = 0, ai, len, extra;
for (int i = 0; i < n; i++) {
int l = a[i] >> (10), r = a[i] % (N);
len = 1;
for (int j = 0; j < N; j++) {
extra = k[i] - bc[j][r];
if (extra < 0 || extra > 10) continue;
if (len < (dp[j][l][extra] + 1)) {
len = dp[j][l][extra] + 1;
p[i] = ind[j][l][extra];
}
}
for (int j = 0; j < N; j++) {
if (len > dp[r][j][bc[j][l]]) {
dp[r][j][bc[j][l]] = len;
ind[r][j][bc[j][l]] = i;
}
}
if (len > ans) ans = len, ai = i;
}
cout << ans << "\n";
vector<int> temp;
while (p[ai] != ai) {
temp.push_back(ai);
ai = p[ai];
}
temp.push_back(ai);
for (int i = ans - 1; i >= 0; i--) {
cout << temp[i] + 1 << " \n"[i == 0];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
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... |