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;
const int M = 1024;
const int K = 11;
int a[N];
int k[N];
int nr[M][M];
pair<int, int> dp[M][M][K], from[N];
vector <int> v;
int main()
{
// freopen("g.in", "r", stdin);
// freopen("g.out", "w", stdout);
int n;
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 = 0; i < M; i++)
for (int j = 0; j < M; j++)
nr[i][j] = __builtin_popcount(i & j);
for (int i = 1; i <= n; i++)
{
pair <int, int> ans = {0, 0};
int f = (a[i] >> 10);
int s = a[i] % M;
for (int j = 0; j < M; j++)
if (nr[s][j] <= k[i] && k[i] - nr[s][j] <= 10)
ans = max(ans, dp[j][f][k[i] - nr[j][s]]);
ans.first++;
from[i] = ans;
for (int j = 0; j < M; j++)
dp[a[i] & (M - 1)][j][nr[f][j]] = max(dp[a[i] & (M - 1)][j][nr[f][j]], {ans.first, i});
}
int idx = 0;
for (int i = 1; i <= n; i++)
if (from[idx].first < from[i].first)
idx = i;
cout << from[idx].first;
while(idx)
{
v.push_back(idx);
idx = from[idx].second;
}
cout << endl;
reverse(v.begin(), v.end());
for (auto x : v)
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... |