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;
#define endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=998244353;
const int N=(1<<20)+1;
int bitcount[N];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n; cin>>n;
int a[n],k[n],sol[n],par[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<=(1<<20);i++){
int x=i;
while(x>0){
if(x%2==1)bitcount[i]++;
x/=2;
}
}
int ans=0,idx=0;
for(int i=0;i<n;i++){
cin>>k[i];
sol[i]=1;
par[i]=i;
for(int j=i-1;j>=0;j--){
if(bitcount[(a[i]&a[j])]==bitcount[k[i]]){
// cout<<a[i]<<" "<<a[j]<<" "<<k[i]<<" "<<(a[i]&a[j])<<endl;
if(sol[j]+1>sol[i]){
sol[i]=sol[j]+1;
par[i]=j;
}
}
}
if(ans<sol[i]){
ans=sol[i]; idx=i;
}
}
cout<<ans<<endl;
vector<int> v;
while(1){
int x=idx;
v.pb(x+1);
idx=par[idx];
if(idx==x)break;
}
for(int i=v.size()-1;i>=0;i--)cout<<v[i]<<" ";
}
# | 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... |