이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |