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 y1 theboatman
#define make_struct(args...) {args}
using namespace std;
int main() {
cin.tie(0);
ios :: sync_with_stdio(0);
int n;
cin >> n;
vector <int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector <int> k(n);
for(int i = 0; i < n; i++) {
cin >> k[i];
}
vector <int> dp(n, 1), from(n, -1);
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if (__builtin_popcount(a[i] & a[j]) == k[j]) {
if (dp[j] < dp[i] + 1) {
dp[j] = dp[i] + 1;
from[j] = i;
}
}
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
ans = max(ans, dp[i]);
}
for(int i = 0; i < n; i++) {
if (dp[i] == ans) {
vector <int> way;
int now = i;
while(now != -1) {
way.push_back(now + 1);
now = from[now];
}
reverse(way.begin(), way.end());
cout << way.size() << "\n";
for(auto i : way) {
cout << i << " ";
}
return 0;
}
}
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... |