제출 #1126603

#제출 시각아이디문제언어결과실행 시간메모리
1126603brover29Longest beautiful sequence (IZhO17_subsequence)C++20
23 / 100
6082 ms2864 KiB
#include <bits/stdc++.h> //qwerty47924692 using namespace std; using ll = long long; const ll N=2e5+29; const string br="617283"; ll dp[N],a[N],k[N],n,opt[N],op; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(ll i=1;i<=n;i++){ cin>>a[i]; }for(ll i=1;i<=n;i++){ cin>>k[i]; } ll ans=0; for(ll i=1;i<=n;i++){ dp[i]=1; for(ll j=i-1;j>=0;j--){ if(__builtin_popcountll(a[i]&a[j])==k[i]){ dp[i]=max(dp[i],dp[j]+1); if(dp[i]==dp[j]+1)opt[i]=j; } } ans=max(ans,dp[i]); if(ans==dp[i])op=i; } cout<<ans<<'\n'; vector<ll>v; ll i=op; while(i){ v.push_back(i); i=opt[i]; } reverse(v.begin(),v.end()); for(ll i:v){ cout<<i<<' '; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...