# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173017 | juggernaut | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 2 ms | 504 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.
//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,i,a[100001],k[100001],dp[100001],j,path[100001],mx,ind,m[(1ll<<20)],pos[(1ll<<20)];
vector<int>ans;
main(){
scanf("%lld",&n);
for(i=1;i<=n;i++)scanf("%lld",&a[i]);
for(i=1;i<=n;i++)scanf("%lld",&k[i]),dp[i]=1;
for(i=1;i<=n;i++){
for(j=0;j<(1ll<<8);j++)
if(__builtin_popcount(a[i]&j)==k[i]&&m[j]+1>dp[i]){
dp[i]=m[j]+1;
path[i]=pos[j];
}
if(dp[i]>m[a[i]]){
m[a[i]]=dp[i];
pos[a[i]]=i;
}
if(dp[i]>mx){
mx=dp[i];
ind=i;
}
}
do{
ans.push_back(ind);
ind=path[ind];
}while(ind!=0);
reverse(ans.begin(),ans.end());
printf("%lld\n",(int)(ans.size()));
for(int res:ans)printf("%lld ",res);
}
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... |