This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
//#define int long long
template<typename T>
void mxx(T &a, T b){if(b>a) a=b;}
template<typename T>
void mnn(T &a, T b){if(b<a) a=b;}
const int mxn=11,mxxa=1e5+10;
pair<int,int> dp[1<<mxn][1<<mxn][mxn];
int par[mxxa],dd[mxxa];
int bb[1<<mxn][1<<mxn];
int a[mxxa],k[mxxa];
void build(){
for(int i=0; i<(1<<10); i++){
for(int j=0; j<(1<<10); j++){
bb[i][j]=__builtin_popcount(i&j);
}
}
}
signed main(){
fast;
int n;
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=1; i<=n; i++) cin>>k[i];
pair<int,int> ans=make_pair(0,0);
for(int i=1; i<=n; i++){
int l=(a[i]>>10);
int r=(a[i]^(l<<10));
auto mx=make_pair(0,0);
for(int j=0; j<(1<<10); j++){
int cnt=k[i] - __builtin_popcount(j&l);
if(cnt<0 || cnt>10) continue;
mxx(mx,dp[j][r][cnt]);
}
par[i]=mx.ss;
mx.ff++;
mx.ss=i;
mxx(ans,mx);
for(int j=0; j<(1<<10); j++){
int cnt=__builtin_popcount(j&r);
mxx(dp[l][j][cnt],mx);
}
}
cout<<ans.ff<<'\n';
vector<int> tmp;
for(int i=0; i<ans.ff; i++){
tmp.pb(ans.ss);
ans.ss=par[ans.ss];
}
sort(all(tmp));
for(int x : tmp){
cout<<x<<' ';
}
cout<<'\n';
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... |