#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 100, M = 500 + 10, len = 315, inf = 1e18;
const ll mod = 998244353;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll bp(ll x, ll step){
ll res = 1;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
ll inv(ll x){
return bp(x, mod - 2);
}
bool was[5010][5010];
int check(int a, int b){
int res = 0;
while(true){
if(a == 0 || b == 0) break;
if(a%2 + b%2 == 2) res++;
a /= 2;
b /= 2;
}
return res;
}
int a[N], k[N], n, p[N];
pii dp[N];
vector <int> qr[300][20];
void subtask3(){
int mx = 0, start;
for(int i = 1; i <= 256; i++){
dp[i].F = 0;
dp[i].S = -1;
for(int j = 1; j <= 256; j++){
qr[i][check(i, j)].pb(j);
}
}
for(int i = 0; i < n; i++){
int local = 0, pred = -1;
for(auto j : qr[a[i]][k[i]]){
if(dp[j].F > local){
local = dp[j].F;
pred = dp[j].S;
}
}
if(local + 1 > dp[a[i]].F){
dp[a[i]].F = local + 1;
dp[a[i]].S = i;
p[i] = pred;
if(dp[a[i]].F > mx){
mx = dp[a[i]].F;
start = i;
}
}
}
cout << mx << endl;
vector <int> vv;
while(start != -1){
//cout << start << endl;
vv.pb(start);
start = p[start];
}
for(int i = (int)vv.size() -1; i >= 0; i--){
cout << vv[i] + 1 << " ";
}
}
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//cout.tie(nullptr);
int cnt = 1, num = 0, mx = 0;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
mx = max(mx, a[i]);
}
for(int i = 0; i < n; i++){
cin >> k[i];
}
if(mx <= 256){
subtask3();
return 0;
}
for(int i = 0; i < n; i++){
for(int j = i - 1; j >= 0; j--){
if(check(a[i], a[j]) != k[i]) continue;
for(int nw = 1; nw < n; nw++){
was[i][nw + 1] |= was[j][nw];
if(was[i][nw + 1] && nw + 1 > cnt){
cnt = nw + 1;
num = i;
}
}
}
was[i][1] = true;
}
cout << cnt << endl;
vector <int> vec;
while(cnt > 1){
vec.pb(num);
cnt--;
for(int j = num - 1; j >= 0; j--){
if(check(a[num], a[j]) != k[num]) continue;
if(was[j][cnt]){
num = j;
break;
}
}
}
cout << num + 1 << " ";
for(int i = (int)vec.size() - 1; i >= 0; i--){
cout << vec[i] + 1 << " ";
}
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... |