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;
#define ll long long
const int N = 2e5 + 5;
#define pb push_back
#define sz size()
#define ff first
#define ss second
int a[N], k[N], dp[N], jogap, n, par[N], idx;
vector <int> cykar;
int main () {
// freopen("subsequence.in", "r", stdin);
// freopen("subsequence.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
cin >> k[i];
}
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
par[i] = i;
for (int j = i - 1; j > 0; j--) {
int x = a[j] & a[i];
if (__builtin_popcount(x) == k[i]) {
if (dp[i] < dp[j] + 1) {
dp[i] = dp[j] + 1;
par[i] = j;
break;
}
}
}
if (jogap < dp[i]) {
jogap = dp[i];
idx = i;
}
}
cout << jogap << "\n";
while (1) {
cykar.pb (idx);
if (idx == par[idx]) break;
idx = par[idx];
}
reverse(cykar.begin(), cykar.end());
for (int i : cykar) {
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... |