# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333551 | juggernaut | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 127 ms | 1900 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>
using namespace std;
int n,a[100005],b[100005],i,dp[1<<21],mx,c[100005],path[100005],x,mask[256];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)scanf("%d",&b[i]);
for(int i=1;i<=n;i++){
c[i]=1;
if(n<5001){
for(int j=1;j<i;j++){
if(__builtin_popcount(a[j]&a[i])==b[i]&&c[i]<c[j]+1){
c[i]=c[j]+1;
path[i]=j;
}
}
}else{
for(int j=0;j<256;j++){
int tmp=mask[j];
if(__builtin_popcount(a[tmp]&a[i])==b[i]&&c[i]<c[tmp]+1){
c[i]=c[tmp]+1;
path[i]=tmp;
}
}
mask[a[i]]=i;
}
if(c[i]>mx){
mx=c[i];
x=i;
}
}
printf("%d\n",mx);
stack<int>st;
while(x){
st.push(x);
x=path[x];
}
while(!st.empty()){
printf("%d ",st.top());
st.pop();
}
}
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... |