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"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n; cin >> n;
vector <int> a(n + 5), k(n + 5);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> k[i];
vector <int> dp(n + 5, 1), opt(n + 5, -1);
int p = 0, ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j < i; ++j) {
int cur = (__builtin_popcount(a[i] & a[j]) == k[i])? dp[j] : 0;
if (dp[i] < cur + 1) {
opt[i] = j;
dp[i] = cur + 1;
}
}
if (ans < dp[i]) {
p = i;
ans = dp[i];
}
}
// debug(dp);
vector <int> ids;
while (p != -1) {
ids.push_back(p);
p = opt[p];
}
reverse(ids.begin(), ids.end());
cout << ans << "\n";
for (int x : ids) cout << x << " ";
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... |