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>
#define ll long long
#define ff first
#define ss second
using namespace std;
int n;
int a[100001];
int b[100001];
int dp1[100001];
int dp2[1024][1024][11];
int bits[1024];
int p[100001];
int main(){
cin>>n;
for(int k=1;k<=n;k++)
cin>>a[k];
for(int k=1;k<=n;k++)
cin>>b[k];
for(int k=0;k<1024;k++){
bits[k]=__builtin_popcount(k);
}
for(int i=1;i<=n;i++){
int left=(a[i]>>10);
int right=(a[i]&1023);
int ind=0;
for(int k=0;k<1024;k++){
int sxv=b[i]-bits[(right&k)];
if(sxv<0||sxv>10)
continue;
if(dp1[dp2[left][k][sxv]]>dp1[ind]){
ind=dp2[left][k][sxv];
}
}
dp1[i]=dp1[ind]+1;
p[i]=ind;
for(int k=0;k<1024;k++){
int sxv=bits[(left&k)];
if(sxv<0||sxv>10)
continue;
if(dp1[dp2[k][right][sxv]]<dp1[i]){
dp2[k][right][sxv]=i;
}
}
}
int mx=0;
int ind=0;
for(int k=1;k<=n;k++){
if(dp1[k]>mx){
mx=dp1[k];
ind=k;
}
}
cout<<mx<<"\n";
vector<int> ans;
while(ind!=0){
ans.push_back(ind);
ind=p[ind];
}
reverse(ans.begin(),ans.end());
for(int i:ans)
cout<<i<<' ';
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... |