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>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1e5+5;
int n, a[N], k[N];
int dp[N];
int prv[N];
void sub1_2()
{
for (int i = 1; i <= n; i++) {
dp[i] = 1;
for (int j = 1; j < i; j++) {
if (__builtin_popcount(a[i]&a[j]) == k[i]) {
if (dp[j]+1 > dp[i]) {
dp[i] = dp[j]+1;
prv[i] = j;
}
}
}
}
int idx = max_element(dp, dp+n+1)-dp;
vector<int> lis;
while (idx) {
lis.push_back(idx);
idx = prv[idx];
}
reverse(lis.begin(), lis.end());
cout << lis.size() << '\n';
for (int i:lis) cout << i << ' ';
exit(0);
}
int lst[1<<8];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n;
for (int i = 1; i <= n; cin >> a[i++]);
for (int i = 1; i <= n; cin >> k[i++]);
if (n <= 5000) sub1_2();
for (int i = 1; i <= n; i++) {
dp[i] = 1;
for (int jj = 0; jj < (1<<8); jj++) {
if (!lst[jj]) continue;
const int j = lst[jj];
assert(jj == a[j]);
if (__builtin_popcount(a[i]&a[j]) == k[i]) {
if (dp[j]+1 > dp[i]) {
dp[i] = dp[j]+1;
prv[i] = j;
}
}
}
lst[a[i]] = i;
}
int idx = max_element(dp, dp+n+1)-dp;
vector<int> lis;
while (idx) {
lis.push_back(idx);
idx = prv[idx];
}
reverse(lis.begin(), lis.end());
cout << lis.size() << '\n';
for (int i:lis) cout << i << ' ';
}
# | 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... |