This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* @authors bubu
* @date 2022-02-27 21:34:58
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), k(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> k[i];
}
vector<int> d(n, 1); // len of the longest beautiful sequence ends at i
vector<int> p(n, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (__builtin_popcount(a[i] & a[j]) == k[i]) {
if (d[j] + 1 > d[i]) {
d[i] = d[j] + 1;
p[i] = j;
}
}
}
}
vector<int> ans;
int it = max_element(d.begin(), d.end()) - d.begin();
while (it >= 0) {
ans.push_back(it);
it = p[it];
}
cout << ans.size() << '\n';
reverse(ans.begin(), ans.end());
for (int i : ans) cout << i + 1 << ' ';
cout << '\n';
}
# | 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... |