#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define siz(v) (int)(v).size()
#define cntb(x) __builtin_popcount(x)
using namespace std;
const int MAXN = 1e5 + 5, MAXB = 10, infINT = 1e9 + 1273;
const long long inf = 1e18 + 34;
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}
struct Trace{
int bl, br, bk, bi, bp;
Trace(int _bl = 0, int _br = 0, int _bk = 0, int _bi = -1, int _bp = -1):
bl(_bl), br(_br), bk(_bk), bi(_bi), bp(_bp) {};
};
int numVal, val[MAXN], req[MAXN], dp[MASK(MAXB)][MASK(MAXB)][MAXB + 1];
vector<Trace> trace[MASK(MAXB)][MASK(MAXB)][MAXB + 1];
void input(){
cin >> numVal;
for(int i = 0; i < numVal; i++) cin >> val[i];
for(int i = 0; i < numVal; i++) cin >> req[i];
}
#define left(x) (x >> MAXB)
#define right(x) (x & (MASK(MAXB) - 1))
string binary(const int &mask){
string s = "";
for(int i = 0; i < 10; i++) s += (BIT(mask, i) + 48);
return s;
}
void solve(){
int res = 0;
for(int i = 0; i < numVal; i++){
int L = left(val[i]);
int R = right(val[i]);
int best = 0;
Trace cur;
cur.bi = i;
for(int l = 0; l < MASK(MAXB); l++) if (req[i] >= cntb(l & L) && req[i] <= MAXB) {
if (maximize(best, dp[l][R][req[i] - cntb(l & L)])){
cur = Trace(l, R, req[i] - cntb(l & L), i, siz(trace[l][R][req[i] - cntb(l & L)]) - 1);
}
}
for(int r = 0; r < MASK(MAXB); r++){
if (maximize(dp[L][r][cntb(r & R)], best + 1)){
trace[L][r][cntb(r & R)].push_back(cur);
}
}
}
Trace cur;
for(int l = 0; l < MASK(MAXB); l++)
for(int r = 0; r < MASK(MAXB); r++)
for(int k = 0; k <= MAXB; k++) if (maximize(res, dp[l][r][k])){
cur = trace[l][r][k].back();
}
vector<int> canPos;
while(cur.bp >= 0){
canPos.push_back(cur.bi);
if (cur.bp >= 0) cur = trace[cur.bl][cur.br][cur.bk][cur.bp];
}
canPos.push_back(cur.bi);
cout << res << '\n';
reverse(all(canPos));
for(int x: canPos) cout << x + 1 << ' '; 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();
cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | 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... |