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>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int k[n];
for (int i = 0; i < n; i++) {
cin >> k[i];
}
int dp[n], p[n], mx = -1;
fill(p, p + n, -1);
for (int i = 0; i < n; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
if (__builtin_popcount(a[i] & a[j]) == k[i] && dp[j] + 1 > dp[i]) {
dp[i] = dp[j] + 1;
p[i] = j;
}
}
if (mx == -1 || dp[i] > dp[mx]) {
mx = i;
}
}
vector<int> ans;
int v = mx;
while (v != -1) {
ans.push_back(1 + v);
v = p[v];
}
cout << ans.size() << '\n';
reverse(ans.begin(), ans.end());
for (int v : ans)
cout << v << ' ';
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... |