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 ll long long
#define fi first
#define sec second
#define pb push_back
#define pqueue priority_queue
#define int long long
#define pii pair<int,int>
#define supercepat ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
//GA AC GA LAKI
using namespace std;
int tc,n,tp;
vector<int> vec,ans;
int a[100005],k[100005];
int biton(int x,int y){
int temp=x&y;
int sum=0;
for(int i=25;i>=0;i--){
if(pow(2,i)<=temp){
temp-=pow(2,i);
sum++;
}
}
return sum;
}
void dp(int x,int subl){
// cout<<x<<" "<<subl<<endl;
vec.pb(x);
for(int i=x+1;i<=n;i++){
if(biton(a[i],a[x])==k[i]){
dp(i,subl+1);
}
}
if(subl>tp){
ans.clear();
for(auto i : vec){
ans.pb(i);
}
tp=max(tp,subl);
}
vec.pop_back();
}
main(){
supercepat;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>k[i];
for(int i=1;i<=n;i++) dp(i,1);
cout<<ans.size()<<endl;
for(auto i : ans) cout<<i<<" ";
cout<<endl;
}
/*
vector vec;
for(i=1;i<=n;i++) dp(i,1) vec.pb(i);
dp(x,subl)
untuk suatu index x, cek i dari x+1 sampai n apabila biton(a[i]&a[x])==k[i] -> dp(i,subl+1)
vec.pop()
if(subl>tp) kita copy arraynya
*/
Compilation message (stderr)
subsequence.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
43 | main(){
| ^~~~
# | 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... |