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;
typedef pair<int,int> ii;
ii maxd[300];
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]<<' ';
}
void Sub2()
{
int res=0,id;
for(int i=1;i<=n;i++)
{
f[i]=1;
for(int j=0;j<=255;j++)
if(__builtin_popcount(a[i]&j)==b[i]&&f[i]<maxd[j].first+1)
{
f[i]=maxd[j].first+1;
Trace[i]=maxd[j].second;
}
if(maxd[a[i]].first<f[i])
maxd[a[i]]=ii(f[i],i);
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();
else*/
Sub2();
}
Compilation message (stderr)
subsequence.cpp: In function 'void Sub2()':
subsequence.cpp:39:15: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
int res=0,id;
^
# | 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... |