제출 #202157

#제출 시각아이디문제언어결과실행 시간메모리
202157mdn2002Longest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
127 ms12024 KiB
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int n,a[1900005],k[1900005],dp[1900005],dp1[1900005],pth[1900005],mx,in; vector<int>ans; bool t=false; string to(int x) { string s; while(x) { s.push_back('0'+(x%2)); x/=2; } while(s.size()!=9)s.push_back('0'); reverse(s.begin(),s.end()); return s; } void fp(int x) { if(x==0)return; fp(pth[x]); ans.push_back(x); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("empty.in","r",stdin); //freopen("empty.out","w",stdout); cin>>n; for(int i=1; i<=n; i++) { cin>>a[i]; dp[a[i]]=1; if(dp1[a[i]]==0)dp1[a[i]]=i; } for(int i=1; i<=n; i++)cin>>k[i]; if(n<=5000) { memset(dp,0,sizeof dp); for(int i=1; i<=n; i++) { dp[i]=1; for(int j=1; j<i; j++) { if(__builtin_popcount((a[i]&a[j]))==k[i]) { if(dp[i]<dp[j]+1) { dp[i]=dp[j]+1; pth[i]=j; } } } mx=max(mx,dp[i]); } for(int i=1;i<=n;i++) { if(dp[i]==mx)in=i; } fp(in); cout<<mx<<endl; for(int i=0; i<mx; i++)cout<<ans[i]<<' '; return 0; } for(int i=1; i<=n; i++) { int mxd=1,fom=0; for(int j=0;j<=(1<<8);j++) { if(mxd<dp[j]+1&&__builtin_popcount((a[i]&j))==k[i]) { fom=dp1[j]; mxd=dp[j]+1; } } if(mxd>dp[a[i]]) { dp[a[i]]=mxd; pth[i]=fom; } if(mx<dp[a[i]]) { mx=dp[a[i]]; in=i; } } fp(in); cout<<mx<<endl; for(int i=0; i<mx; i++)cout<<ans[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...