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 ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1e5+1;
int n, a[N], k[N];
int dp[N];
int prv[N];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n;
for (int i = 1; i <= n; cin >> a[i++]);
for (int i = 1; i <= n; cin >> k[i++]);
for (int i = 1; i <= n; i++) {
dp[i] = 1;
for (int j = 1; j < i; j++) {
if (__builtin_popcount(a[i]&a[j]) == k[i]) {
if (dp[j]+1 > dp[i]) {
dp[i] = dp[j]+1;
prv[i] = j;
}
}
}
}
int idx = max_element(dp, dp+n+1)-dp;
vector<int> lis;
while (idx) {
lis.push_back(idx);
idx = prv[idx];
}
reverse(lis.begin(), lis.end());
cout << lis.size() << '\n';
for (int i:lis) cout << i << ' ';
}
# | 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... |