#include<bits/stdc++.h>
using namespace std;
#ifndef BADGNU
#pragma GCC target("sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
// #define int ll
#define ld long double
#define y1 cheza
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=1e5+100;
const int M=5001;
const int B=447;
const int mod=998244353;
const ll INF=1e18;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const double eps=1e-6;
int n;
int a[N];
int b[N];
int p[N];
pair<int,int> dp[(1<<10)][(1<<10)][11];
int cnt[(1<<10)][(1<<10)];
void test(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
p[i]=i;
}
int ans=0;
int pos=0;
for(int i=1;i<=n;i++){
int l=(a[i]>>10ll);
int r=a[i]-(l<<10ll);
int res=1;
for(int j=0;j<(1<<10);j++){
int cur=b[i]-cnt[j][l];
if(cur<0||cur>10){
continue;
}
if(dp[j][r][cur].second+1>res){
res=dp[j][r][cur].second+1;
p[i]=dp[j][r][cur].first;
}
}
if(ans<res){
ans=res;
pos=i;
}
for(int j=0;j<(1<<10);j++){
if(dp[l][j][cnt[j][r]].second<res){
dp[l][j][cnt[j][r]].second=res;
dp[l][j][cnt[j][r]].first=i;
}
}
}
cout<<ans<<'\n';
vector<int>v;
v.push_back(pos);
while(pos!=p[pos]){
pos=p[pos];
v.push_back(pos);
}
reverse(v.begin(),v.end());
for(auto i:v){
cout<<i<<' ';
}
cout<<'\n';
}
/*
*/
signed main(){
for(int i=0;i<(1<<10);i++){
for(int j=0;j<(1<<10);j++){
cnt[i][j]=(__builtin_popcount(i&j));
}
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// cout.tie(nullptr);
int t2=1;
// cin>>t2;
for(int i=1;i<=t2;i++){
test();
}
}
# | 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... |