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;
#define int long long
#define f first
#define s second
const int N = 1e5 + 69;
const int K = 11;
const int M = (1 << 10);
int n, a[N], k[N], par[N], sk[N];
pair<int, int> dp[M][M][K];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
for (int i = 1;i <= n;i++)
cin >> k[i];
for (int i = 1;i <= n;i++) {
int bst = 0, pr = 0;
for (int j = 0;j < M;j++) {
int t = (a[i] & j);
int x = __builtin_popcount(t);
if (k[i] < x || k[i] - x > 10)
continue;
if (dp[j][a[i] >> 10][k[i] - x].f >= bst) {
bst = dp[j][a[i] >> 10][k[i] - x].f;
pr = dp[j][a[i] >> 10][k[i] - x].s;
}
}
par[i] = pr;
sk[i] = bst + 1;
for (int j = 0;j < M;j++) {
int s = a[i] & (M - 1);
int nj = __builtin_popcount(j & (a[i] >> 10));
if (sk[i] > dp[s][j][nj].f) {
dp[s][j][nj].f = sk[i];
dp[s][j][nj].s = i;
}
}
}
int mx = 1;
for (int i = 2;i <= n;i++) {
if (sk[i] > sk[mx])
mx = i;
}
int t = mx;
vector<int> ans;
while (t != 0) {
ans.push_back(t);
t = par[t];
}
reverse(ans.begin(), ans.end());
cout << ans.size() << '\n';
for (auto i : ans)
cout << i << " ";
}
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... |