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;
int last[1<<10][1<<10][21];
int main(){
int n;
cin>>n;
vector<int> len(n+1), pr(n+1), a(n+1), k(n+1);
for(int i=1;i<=n;++i) cin>>a[i];
for(int i=1;i<=n;++i) cin>>k[i];
for(int i=1;i<=n;++i){
int lef=a[i]&((1<<10)-1), rig=a[i]>>10;
for(int mask=0;mask<(1<<10);++mask){
int tar=k[i]-__builtin_popcount(mask&lef);
if(0<=tar&&tar<=n&&(len[i]<len[last[mask][rig][tar]])){
len[i]=len[last[mask][rig][tar]];
pr[i]=last[mask][rig][tar];
}
}
len[i]++;
for(int mask=0;mask<(1<<10);++mask){
if(len[last[lef][mask][__builtin_popcount(mask&rig)]]<len[i]){
last[lef][mask][__builtin_popcount(mask&rig)]=i;
}
}
}
int poz=0;
len[0]=-1;
for(int i=1;i<=n;++i){
if(len[i]>len[poz]) poz=i;
}
stack<int> ans;
cout<<len[poz]<<"\n";
while(poz){
ans.push(poz);
poz=pr[poz];
}
while(!ans.empty()) cout<<ans.top()<<" ", ans.pop();
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... |