#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define int long long
#define mod 1000000007
#define base 7001
#define base2 757
#define F first
#define S second
// #define pi acos(-1)
#define double long double
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,sse3,sse4,avx")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
constexpr int maxn = 1000005;
const int N = 1 << (int)(ceil(log2(maxn)));
int n, a[maxn], k[maxn], ans[maxn], par[maxn], dp[maxn];
// pair<int, int> q(int take, int bit, int i, int x) {
// if (!take) return dp[x];
// if (bit == 8) return 0;
// pair<int, int> ret = {0, -1};
// if (a[i] & (1ll << bit)) ret = max(q(take - 1, bit + 1, i, x ^ (1ll << bit)), ret);
// else ret = max(ret, q(take, bit + 1, i, x));
// return;
// }
// void u(int take, int bit, int i, int x) {
// if (!take) dp[x] = max(dp[x], make_pair(ans[i], i));
// if (bit == 8) return;
// if (a[i] & (1ll << bit)) u(take - 1, bit + 1, i, x ^ (1ll << bit));
// else u(take, bit + 1, i, x);
// return;
// }
signed main()
{
cin.tie(0) -> sync_with_stdio(0);
cin >> n;
// for (int i = 0; i < maxn; i++) dp[i] = {0, -1};
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++) {
pair<int, int> mx = {0, -1};
if (n <= 5e3) {
for (int j = 0; j < i; j++) {
if (__builtin_popcount(a[i] & a[j]) == k[i]) mx = max(make_pair(ans[j], j), mx);
}
ans[i] = mx.F + 1;
par[i] = mx.S;
}
// else {
// auto x = q(k[i])
// }
}
pair<int, int> mx = {0, -1};
for (int i = 0; i < n; i++) mx = max(mx, make_pair(ans[i], i));
vector<int> v;
cout << mx.F << '\n';
int cur = mx.S;
while (cur != -1) {
v.push_back(cur);
cur = par[cur];
}
reverse(v.begin(), v.end());
for (int 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... |