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<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int MAX_N = 1e5;
const int BAR = 10;
const int MAX_X = 20;
int n;
pii dp[(1<<BAR)][(1<<BAR)][BAR+1], back[MAX_N];
int a[MAX_N], k[MAX_N];
int popcount(int i){
if(i==0){
return 0;
}
return popcount(i & (i-1)) +1;
}
void display(pii u){
//cout<<u.first<<" "<<u.second<<endl;
if(u.second!=-1){
cout<<u.second+1<<" ";
display(back[u.second]);
}
}
signed main(){
cin>>n;
for(int i = 0; i<n; i++){
cin>>a[i];
}
for(int i = 0; i<n; i++){
cin>>k[i];
}
pii ans = pii(0, n-1);
for(int i = n-1; i>=0; i--){
pii res =pii(0, -1);
int right = a[i]%(1<<BAR);
int left = a[i]>>BAR;
//cout<<bitset<BAR>(left)<<" "<<bitset<BAR>(right)<<" "<<k[i]<<endl;
for(int mright = 0; mright<(1<<BAR); mright++){
int exp_right =popcount(mright&right);
//cout<<bitset<BAR>(left)<<" "<<bitset<BAR>(mright)<<" "<<exp_right<<"is ok"<<endl;
if(dp[left][mright][exp_right].first>res.first){
res= dp[left][mright][exp_right];
}
}
back[i] = res;
res.first+=1;
res.second = i;
if(res.first>ans.first){
ans =res;
}
for(int mleft = 0; mleft<(1<<BAR); mleft++){
int exp_right = k[i]-popcount(mleft&left);
if(exp_right>=0 && exp_right<=popcount(right)){
//cout<<"setting "<<bitset<BAR>(mleft)<<" "<<bitset<BAR>(right)<<" "<<exp_right<<endl;
if(dp[mleft][right][exp_right].first< res.first){
dp[mleft][right][exp_right] = res;
}
}
}
}
cout<<ans.first<<endl;
display(ans);
cout<<endl;
}
# | 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... |