#include <bits/stdc++.h>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define all(v) begin(v), end(v)
#define siz(v) (int)(v).size()
using namespace std;
const int MAXN = 1e5 + 5, MAXB = 10;
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}
template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
int numVal, val[MAXN], req[MAXN], dp[MASK(MAXB)][MASK(MAXB)][MAXB + 1], pos[MASK(MAXB)][MASK(MAXB)][MAXB + 1], trace[MAXN];
void input(){
cin >> numVal;
for(int i = 1; i <= numVal; i++) cin >> val[i];
for(int i = 1; i <= numVal; i++) cin >> req[i];
}
#define left(x) (x >> MAXB)
#define right(x) (x & (MASK(MAXB) - 1))
#define cntb(x) (__builtin_popcount(x))
string binary(const int &mask, const int &len){
string s = "";
for(int i = 0; i < len; i++) s += (BIT(mask, i) + 48);
return s;
}
void solve(){
int res = 0, cur = 0;
int mx = 0;
for(int i = 1; i <= numVal; i++){
int L = left(val[i]);
int R = right(val[i]);
int best = 1, bestPos = 0;
for(int l = 0; l < MASK(MAXB); l++) if (req[i] >= cntb(l & L) && req[i] - cntb(l & L) <= MAXB) {
if (maximize(best, dp[l][R][req[i] - cntb(l & L)] + 1))
bestPos = pos[l][R][req[i] - cntb(l & L)];
}
trace[i] = bestPos;
if (maximize(res, best)) cur = i;
for(int r = 0; r < MASK(MAXB); r++){
maximize(mx, cntb(r & R));
if (maximize(dp[L][r][cntb(r & R)], best))
pos[L][r][cntb(r & R)] = i;
}
}
cout << res << '\n';
vector<int> canPos;
while(cur > 0){
canPos.push_back(cur);
cur = trace[cur];
}
reverse(all(canPos));
for(int x: canPos) cout << x << ' '; cout << '\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
input();
solve();
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen(task".out", "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... |