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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;
int pos[1024][1024][21];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
for (auto& i : pos)
for (auto& j : i)
for (auto& k : j)
k = -1;
int n;
cin >> n;
vi a(n);
for (auto& i : a)
cin >> i;
vi k(n);
for (auto& i : k)
cin >> i;
vi dp(n), last(n, -1);
for (int i = 0; i < n; ++i){
dp[i] = 1;
int x = 0, y = 0;
for (int j = 0; j < 10; ++j){
if ((1 << j) & a[i])
x ^= (1 << j);
if ((1024 << j) & a[i])
y ^= (1 << j);
}
for (int mask = 0; mask < 1024; ++mask){
int d = k[i] - __builtin_popcount(mask&x);
if (d < 0) continue;
if (pos[mask][y][d] != -1 && dp[pos[mask][y][d]] + 1 > dp[i]){
dp[i] = dp[pos[mask][y][d]] + 1;
last[i] = pos[mask][y][d];
}
}
for (int mask = 0; mask < 1024; ++mask){
int d = __builtin_popcount(mask&y);
if (pos[x][mask][d] == -1 || dp[i] > dp[pos[x][mask][d]]){
pos[x][mask][d] = i;
}
}
}
int ind = max_element(dp.begin(), dp.end()) - dp.begin();
cout << dp[ind] << '\n';
vi sol;
while(ind != -1){
sol.push_back(ind);
ind = last[ind];
}
reverse(sol.begin(), sol.end());
for (int x : sol)
cout << x+1 << ' ';
}
# | 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... |