This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
int N, a[MN], k[MN], dp[MN], last[MN], idx[256];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) cin >> a[i];
for (int i = 1; i <= N; i++) cin >> k[i];
int mx = 0, at = 0;
for (int i = 1; i <= N; i++) {
dp[i] = 1;
for (int msk = 0; msk < 256; msk++) {
if (__builtin_popcount(msk & a[i]) == k[i] && dp[i] < dp[idx[msk]] + 1) {
dp[i] = dp[idx[msk]] + 1;
last[i] = idx[msk];
}
}
if (dp[i] > dp[idx[a[i]]]) idx[a[i]] = i;
if (dp[i] > mx) mx = dp[i], at = i;
}
cout << mx << '\n';
vector<int> v;
while (at) {
v.push_back(at);
at = last[at];
}
reverse(all(v));
for (int i : v) cout << i << " ";
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... |