This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
const int B = 10;
template<class T> using V = vector<T>;
struct T {
int x, i;
};
const int INF = 1e9+10;
int pct(int x) { return __builtin_popcount(x); }
T dp[1 << B][1 << B][B + 1];
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
V<int> A(N); for(auto& x : A) cin >> x;
V<int> K(N); for(auto& x : K) cin >> x;
for(int i = 0; i < 1 << B; i++) for(int j = 0; j < 1 << B; j++) {
for(int k = 0; k <= B; k++) {
dp[i][j][k] = {-INF, -1};
}
}
V<int> prv(N, -1), len(N, 1);
for(int i = 0; i < N; i++) {
int lx = A[i] / (1 << B);
int rx = A[i] % (1 << B);
for(int l = 0; l < 1 << B; l++) {
int need = K[i] - pct(l & lx);
if (need < 0 || need > B) continue;
if (len[i] < dp[l][rx][need].x + 1) {
len[i] = dp[l][rx][need].x + 1;
prv[i] = dp[l][rx][need].i;
}
}
for(int r = 0; r < 1 << B; r++) {
if (dp[lx][r][pct(rx & r)].x < len[i]) {
dp[lx][r][pct(rx & r)].x = len[i];
dp[lx][r][pct(rx & r)].i = i;
}
}
}
int best = -1, ans = -1;
for(int i = 0; i < N; i++) {
if (ans < len[i]) best = i, ans = len[i];
}
V<int> ANS;
while(best != -1) {
ANS.push_back(best + 1);
best = prv[best];
}
reverse(begin(ANS), end(ANS));
cout << size(ANS) << nl;
for(auto x : ANS) cout << x << " ";
return 0;
}
# | 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... |