#include <bits/stdc++.h>
#pragma optimize("g", on)
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
void Freopen () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 1e6 + 7, M = 1e5 + 1, mod = 1e9 + 7;
int n, a[N], b[N], dp[N], pr[N];
void solve() {
cin>>n;
for(int i = 1; i <= n; i++)cin>>a[i];
for(int j = 1; j <= n; j++)cin>>b[j];
if(n <= 5000) {
int mx = 0, cur = -1;
for(int i = 2; i <= n; i++) {
for(int j = i - 1; j >= 1; j--) {
if(__builtin_popcount(a[i] & a[j]) == b[i]) {
if(dp[i] < (dp[j] + 1)) {
dp[i] = dp[j] + 1, pr[i] = j;
}
}
}
if(mx < dp[i])mx = dp[i], cur = i;
}
cout << mx + 1 << '\n';
vector<int> vec;
while(cur != 0) {
vec.push_back(cur);
cur = pr[cur];
}
reverse(vec.begin(), vec.end());
for(auto j : vec)cout << j << ' ';
cout << '\n';
return;
}
}
signed main() {
// freopen("duty.in", "r", stdin);
// freopen("duty.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//Freopen();
int T = 1;
// cin>>T;
while(T --)solve();
}
Compilation message (stderr)
subsequence.cpp: In function 'void Freopen()':
subsequence.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |