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 n,a[100005],b[100005],f[100005],Trace[100005];
vector<int> rs;
void Sub1()
{
int res=0,id;
for(int i=1; i<=n; i++)
{
f[i]=1;
for(int j=1; j<i; j++)
if(__builtin_popcount(a[i]&a[j])==b[i]&&f[i]<f[j]+1)
{
f[i]=f[j]+1;
Trace[i]=j;
}
if(res<f[i])
{
res=f[i];
id=i;
}
}
while(id>0)
{
rs.push_back(id);
id=Trace[id];
}
cout<<rs.size()<<"\n";
for(int i=rs.size()-1;i>=0;i--)
cout<<rs[i]<<' ';
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
cin>>n;
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=n; i++)
cin>>b[i];
if(n<=5000)
Sub1();
}
# | 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... |