제출 #1126611

#제출 시각아이디문제언어결과실행 시간메모리
1126611brover29Longest beautiful sequence (IZhO17_subsequence)C++20
23 / 100
158 ms4696 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; vector<ll>pos[257]; 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; if(n<=5000){ 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; } }else{ for(ll i=1;i<=n;i++){ pos[a[i]].push_back(i); for(ll j=1;j<=256;j++){ if((j&a[i])==k[i]){ for(ll ii:pos[j]){ if(dp[ii]+1>dp[i]){ dp[i]=dp[ii]+1; opt[i]=ii; } } } } } } 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...