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;
const int N = 1e5 + 5, half = (1 << 10) + 5, K = 21;
int n, a[N], k[N], f[half][half][K], dp[N], trace[N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("IZhO17_subsequence.INP", "r", stdin);
// freopen("IZhO17_subsequence.OUT", "w", stdout);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i)
cin >> k[i];
int halve = (1 << 10) - 1, res = 0;
for (int i = 1; i <= n; ++i) {
int s = (a[i] & halve);
dp[i] = 1;
for (int fd = 0; fd < halve; ++fd) {
int fbc = __builtin_popcount((a[i] >> 10) & fd);
if (fbc > k[i]) continue;
int val = dp[f[fd][s][k[i] - fbc]] + 1;
if (dp[i] < val) {
dp[i] = val;
trace[i] = f[fd][s][k[i] - fbc];
}
}
for (int sc = 0; sc < halve; ++sc) {
int pre = dp[f[a[i] >> 10][sc][__builtin_popcount(s & sc)]];
if (pre < dp[i]) {
f[a[i] >> 10][sc][__builtin_popcount(s & sc)] = i;
}
}
res = max(res, dp[i]);
}
cout << res << endl;
int i;
for (i = 1; i <= n; ++i) if (dp[i] == res)
break;
vector <int> ans; ans.clear();
while (i) {
ans.push_back(i);
i = trace[i];
}
reverse(ans.begin(), ans.end());
for (int j : ans) cout << j << ' ';
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... |