This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int P = 10;
int dp[1 << P][1 << P][P + 1] = {}, prv[1 << P][1 << P][P + 1];
int path[MAX_N];
int A[MAX_N], K[MAX_N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i];
}
for (int i = 0; i < n; i++) {
cin >> K[i];
}
pair<int, int> best = {-1, -1};
for (int i = 0; i < n; i++) {
int answer = 1;
path[i] = -1;
int left = A[i] >> P, right = A[i] & ((1 << P) - 1);
for (int lhs = 0; lhs < (1 << P); lhs++) {
int bits = K[i] - __builtin_popcount(lhs & left);
if (bits >= 0 && bits <= P && answer < dp[lhs][right][bits] + 1) {
answer = dp[lhs][right][bits] + 1;
path[i] = prv[lhs][right][bits];
}
}
for (int rhs = 0; rhs < (1 << P); rhs++) {
int bits = __builtin_popcount(rhs & right);
if (dp[left][rhs][bits] < answer) {
dp[left][rhs][bits] = answer;
prv[left][rhs][bits] = i;
}
}
best = max(best, {answer, i});
}
vector<int> answer;
for (int i = best.second; i >= 0; answer.push_back(i), i = path[i]);
reverse(answer.begin(), answer.end());
int k = (int)answer.size();
cout << k << "\n";
for (int i = 0; i < k; i++) {
cout << 1 + answer[i] << " \n"[i + 1 == k];
}
}
# | 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... |