// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
#include <numeric>
#include <stack>
#include <chrono>
using namespace std;
void fast_io(){
// freopen("", "r", stdin);
// freopen("", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(); cout.tie();
cout << setprecision(9);
}
#define int long long
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
void solve() {
int n; cin >> n;
int a[n + 1] = {}, k[n + 1] = {};
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> k[i];
if (n > 5000){
return;
}
int dp[n + 1] = {};
for (int i = 1; i <= n; i++){
dp[i] = 1;
for (int j = i - 1; j >= 1; j--){
if (__builtin_popcount(a[i] & a[j]) == k[i]) dp[i] = max(dp[i], dp[j] + 1);
}
}
int ma = 0;
vector<int> ans;
for (int i = 1; i <= n; i++) if (dp[ma] < dp[i]) ma = i;
ans.push_back(ma);
while (dp[ma] != 1){
for (int j = ma - 1; j >= 1; j--){
if (__builtin_popcount(a[ma] & a[j]) == k[ma] && dp[j] + 1 == dp[ma]){
ans.push_back(j);
ma = j;
break;
}
}
}
reverse(all(ans));
cout << ans.size() << endl;
for (auto i : ans) cout << i << ' ';
cout << endl;
return;
}
signed main() {
fast_io();
srand(chrono::steady_clock::now().time_since_epoch().count());
int tc = 1;
// cin >> tc
while (tc--) solve();
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... |