#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(), v.end()
const int N = 1 << 10;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a)
cin >> i;
vector<int> k(n);
for (auto &i : k)
cin >> i;
vector<int> A(n), B(n);
for (int i = 0; i < n; i++) {
A[i] = a[i] >> 10;
B[i] = a[i] & (N - 1);
}
vector<int> res(n), p(n, -1);
vector<vector<vector<int>>> dp(N, vector<vector<int>>(N, vector<int>(11, -1)));
for (int i = 0; i < n; i++) {
res[i] = 1;
for (int Aj = 0; Aj < N; Aj++) {
int x = k[i] - __builtin_popcount(A[i] & Aj);
if (0 <= x && x < 11 && ~dp[Aj][B[i]][x] && res[i] < res[dp[Aj][B[i]][x]] + 1) {
p[i] = dp[Aj][B[i]][x];
res[i] = res[dp[Aj][B[i]][x]] + 1;
}
}
for (int Bx = 0; Bx < N; Bx++) {
if (!~dp[A[i]][Bx][__builtin_popcount(B[i] & Bx)] || res[dp[A[i]][Bx][__builtin_popcount(B[i] & Bx)]] < res[i])
dp[A[i]][Bx][__builtin_popcount(B[i] & Bx)] = i;
}
}
int mx = max_element(all(res)) - res.begin();
cout << res[mx] << '\n';
vector<int> v = {mx};
while (~p[mx]) {
mx = p[mx];
v.push_back(mx);
}
reverse(all(v));
for (auto i : v)
cout << i + 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... |