제출 #1126616

#제출 시각아이디문제언어결과실행 시간메모리
1126616brover29Longest beautiful sequence (IZhO17_subsequence)C++20
40 / 100
112 ms1956 KiB
#include <bits/stdc++.h> //qwerty47924692 using namespace std; using ll = int; const ll N=1e5+29; const string br="617283"; ll dp[N],a[N],k[N],n,opt[N],op,pos[256]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("subsequence.in","r",stdin); // freopen("subsequence.out","w",stdout); 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++){ dp[i]=1; for(ll j=0;j<256;j++){ if(__builtin_popcountll(j&a[i])==k[i]){ if(dp[pos[j]]+1>dp[i]){ dp[i]=dp[pos[j]]+1; opt[i]=pos[j]; } } } if(dp[i]>dp[pos[a[i]]]){ pos[a[i]]=i; } 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...