제출 #502251

#제출 시각아이디문제언어결과실행 시간메모리
502251luka1234Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
1 ms332 KiB
#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 d[257]; vector<int> ans[257]; int main(){ cin>>n; for(int k=1;k<=n;k++) cin>>a[k]; for(int k=1;k<=n;k++) cin>>b[k]; d[a[1]]=1; ans[a[1]].push_back(1); for(int k=2;k<=n;k++){ int cnt=0; int ind=0; for(int i=0;i<256;i++){ int f=a[k]&i; f=__builtin_popcount(f); if(f==b[k]){ if(d[i]+1>cnt){ cnt=d[i]+1; ind=i; } } } if(d[a[k]]<cnt){ d[a[k]]=cnt; ans[a[k]]=ans[ind]; ans[a[k]].push_back(k); } } int mx=0; int ind=0; for(int k=0;k<256;k++){ if(d[k]>mx){ mx=d[k]; ind=k; } } cout<<mx<<"\n"; int sz=ans[ind].size(); for(int k=0;k<sz;k++) cout<<ans[ind][k]<<' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...