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 maxn 200000
#define maxv 2000000
using namespace std;
int n;
int a[maxn];
int k[maxn];
int len[maxn];
int prv[maxn];
int msk=(1<<10)-1;
int lmsk=msk<<10;
int bst[maxv][12];
int query(int a,int k) {
int u,l;
u=a&lmsk;
l=a&msk;
int ret=0;
for(int j=0;j<=msk;j++) {
int v=__builtin_popcount(l&j);
if(v<=k && k-v<=10 && len[bst[u|j][k-v]]>len[ret]) {
ret=bst[u|j][k-v];
}
}
return ret;
}
void update(int a,int v) {
int u,l;
u=a&lmsk;
l=a&msk;
for(int j=0;j<=msk;j++) {
int d=j<<10;
int c=__builtin_popcount(u&d);
if(len[v]>len[bst[d|l][c]]) {
bst[d|l][c]=v;
}
}
}
vector<int> c;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++) {
cin>>a[i];
}
for(int i=1;i<=n;i++) {
cin>>k[i];
}
int ans=0;
for(int i=1;i<=n;i++) {
int v=query(a[i],k[i]);
prv[i]=v;
len[i]=len[v]+1;
update(a[i],i);
if(len[i]>len[ans]) ans=i;
}
while(ans!=0) {
c.push_back(ans);
ans=prv[ans];
}
reverse(c.begin(),c.end());
cout<<c.size()<<endl;
for(auto x:c) {
cout<<x<<" ";
}
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... |