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;
using ll = long long;
using ld = long double;
int n;
vector<int> a;
vector<int> k;
void solution12() {
vector<int> dp(n);
vector<int> prev(n);
int globans = 0;
for (int i = 0; i < n; i++) {
dp[i] = 1;
prev[i] = i;
for (int j = 0; j < i; j++) {
if (__builtin_popcount(a[i] & a[j]) == k[i]) {
if (dp[j]+1 > dp[i]) {
dp[i] = dp[j]+1;
prev[i] = j;
}
}
}
if (dp[i] > dp[globans]) globans = i;
}
cout << dp[globans] << endl;
int x = globans;
vector<int> ans;
while (true) {
ans.push_back(x+1);
if (x == prev[x]) break;
x = prev[x];
}
reverse(ans.begin(), ans.end());
for (int x : ans) cout << x << " ";
cout << endl;
}
void solution3() {
vector<int> dp(n);
vector<int> prev(n);
int globans = 0;
vector<int> maxfor(1<<8, -1);
for (int i = 0; i < n; i++) {
dp[i] = 1;
prev[i] = i;
for (int s = 0; s < a[i]; s++) {
if (maxfor[s] == -1) continue;
if (__builtin_popcount(a[i] & s) == k[i]) {
int j = maxfor[s];
if (dp[j]+1 > dp[i]) {
dp[i] = dp[j]+1;
prev[i] = j;
}
}
}
if (maxfor[a[i]] == -1 || dp[i] > dp[maxfor[a[i]]]) {
maxfor[a[i]] = i;
}
if (dp[i] > dp[globans]) globans = i;
}
cout << dp[globans] << endl;
int x = globans;
vector<int> ans;
while (true) {
ans.push_back(x+1);
if (x == prev[x]) break;
x = prev[x];
}
reverse(ans.begin(), ans.end());
for (int x : ans) cout << x << " ";
cout << endl;
}
void solve() {
cin >> n;
a = k = vector<int>(n);
for (int& x : a) cin >> x;
for (int& x : k) cin >> x;
if (n <= 5000) solution12();
else solution3();
}
int main() {
int t = 1;
//cin >> t;
while (t--) solve();
}
# | 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... |