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 lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#define test(x...) abc("[" + string(#x) + "]", x);
const int N = 200000;
int bucket[1 << 10][10][1 << 10];
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector <int> a(n), k(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> k[i];
vector <int> dp(n, 1), bck(n, -1);
auto upd = [&](int &i, int j) {
if (i == -1)
i = j;
else if (dp[i] < dp[j])
i = j;
};
for (int s = 0; s < 1 << 10; ++s) for (int i = 0; i < 10; ++i) for (int t = 0; t < 1 << 10; ++t)
bucket[s][i][t] = -1;
for (int i = 0; i < n; ++i) {
for (int s = 0; s < 1 << 10; ++s) for (int j = 0; j < 10; ++j) {
int rem = k[i] - j;
if (__builtin_popcount(s) != rem)
continue;
if (rem >= 0) {
int x = bucket[a[i] & ((1 << 10) - 1)][j][s];
if (x != -1 && dp[i] < dp[x] + 1)
dp[i] = dp[x] + 1, bck[i] = x;
}
}
for (int s = 0; s < 1 << 10; ++s) {
upd(bucket[s][__builtin_popcount(s & a[i])][a[i] >> 10], i);
}
}
int mx = max_element(all(dp)) - dp.begin();
cout << dp[mx] << endl;
vector <int> ans;
while (mx != -1) {
ans.pb(mx + 1);
mx = bck[mx];
}
reverse(all(ans));
printv(all(ans));
}
/*
5
5 3 5 3 5
10 1 20 1 20
4
1 2 3 4
10 0 1 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... |