#include <bits/stdc++.h>
using namespace std;
ifstream fin("subsequence.in");
ofstream fout("subsequence.out");
const int Nmax=1e5+5;
int a[Nmax],k[Nmax];
int dp[Nmax],prv[Nmax];
void reconst(int x)
{
if(x==-1) return;
reconst(prv[x]);
fout<<x<<' ';
return;
}
int main()
{
int n;
fin>>n;
for(int i=1;i<=n;i++) fin>>a[i];
for(int i=1;i<=n;i++) fin>>k[i];
if(n<=5000)
{
int sol=0,besti=-1;
for(int i=1;i<=n;i++)
{
dp[i]=1;
prv[i]=-1;
for(int j=i-1;j>=1;j--)
{
int nr=(a[i]&a[j]);
nr=__builtin_popcount(nr);
if(nr==k[i] && dp[j]+1>dp[i])
{
dp[i]=dp[j]+1;
prv[i]=j;
}
}
if(dp[i]>sol)
{
sol=dp[i];
besti=i;
}
}
fout<<sol<<'\n';
reconst(besti);
}
else
{
return 0;
}
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... |