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;
using ll = long long;
const int N = (int)1e4;
#define sz(v) (int)(v).size()
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a)
cin >> i;
vector<int> k(n);
for (auto &i : k)
cin >> i;
vector<int> dp(n), pr(n), ps(N, -1);
for (int i = 0; i < n; i++) {
dp[i] = 1; pr[i] = i;
for (int j = 0; j < N; j++) {
if (ps[j] != -1 && dp[ps[j]] + 1 > dp[i] && __builtin_popcount(j & a[i]) == k[i]) {
dp[i] = dp[ps[j]] + 1; pr[i] = ps[j];
}
}
if (a[i] < N) ps[a[i]] = i;
}
int mx = max_element(dp.begin(), dp.end()) - dp.begin();
cout << dp[mx] << '\n';
vector<int> v = {mx};
while (mx != pr[mx]) v.push_back(mx = pr[mx]);
reverse(v.begin(), v.end());
for (auto i : v)
cout << i + 1 << ' ';
}
# | 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... |