# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502246 | luka1234 | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 6074 ms | 160636 KiB |
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 ff first
#define ss second
using namespace std;
int n;
int a[100001],b[100001];
int dp[100001];
vector<int> ans[100001];
int main(){
cin>>n;
for(int k=1;k<=n;k++)
cin>>a[k];
for(int k=1;k<=n;k++)
cin>>b[k];
dp[1]=1;
ans[1].push_back(1);
for(int k=2;k<=n;k++){
int cnt=1;
int indexi=k;
for(int i=k-1;i>=1;i--){
int f=a[k]&a[i];
f=__builtin_popcount(f);
if(f==b[k]){
if(dp[i]+1>cnt){
cnt=dp[i]+1;
indexi=i;
}
}
}
dp[k]=cnt;
if(indexi==k)
ans[k].push_back(k);
else{
ans[k]=ans[indexi];
ans[k].push_back(k);
}
}
int mx=0;
int ind=0;
for(int k=1;k<=n;k++){
if(dp[k]>mx){
mx=dp[k];
ind=k;
}
}
cout<<mx<<"\n";
for(int k=0;k<ans[ind].size();k++)
cout<<ans[ind][k]<<' ';
return 0;
}
Compilation message (stderr)
# | 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... |