Submission #202150

#TimeUsernameProblemLanguageResultExecution timeMemory
202150mdn2002Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
5 ms760 KiB
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int n,a[100005],k[100005],dp[100005],dp1[100005],pth[100005],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 bt(int x,int nm,string s,int ai,int aj,int i) { if(x==s.size()&&nm==0) { if(dp[ai]<dp[aj]+1) { pth[i]=dp1[aj]; dp1[ai]=i; dp[ai]=dp[aj]+1; } } if(x==s.size())return; if(s[x]=='0') { bt(x+1,nm,s,ai,aj*2,i); bt(x+1,nm,s,ai,aj*2+1,i); } else { bt(x+1,nm,s,ai,aj*2,i); bt(x+1,nm-1,s,ai,aj*2+1,i); } } 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++) { bt(0,k[i],to(a[i]),a[i],0,i); 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]<<' '; }

Compilation message (stderr)

subsequence.cpp: In function 'void bt(int, int, std::__cxx11::string, int, int, int)':
subsequence.cpp:21:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(x==s.size()&&nm==0)
        ~^~~~~~~~~~
subsequence.cpp:30:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(x==s.size())return;
        ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...