Submission #1073552

#TimeUsernameProblemLanguageResultExecution timeMemory
1073552Hugo1729Longest beautiful sequence (IZhO17_subsequence)C++11
0 / 100
0 ms600 KiB
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0)->sync_with_stdio(0); int n; cin >> n; vector<int> a(n),k(n); for(int i=0;i<n;i++)cin >> a[i]; for(int i=0;i<n;i++)cin >> k[i]; vector<int> dp(n,1); vector<int> prev(n,-1); vector<int> dp2(256,-1); vector<int> prev2(256,-1); int best=-1,best_pos=-1; for(int i=0;i<n;i++){ for(int j=0;j<256;j++){ if(__builtin_popcount(a[i]&j)==k[i]){ if(dp[i]<dp2[j]+1){ dp[i]=dp2[j]+1; prev[i]=prev2[j]; } } } if(dp2[a[i]]<dp[i]){ dp2[a[i]]=dp[i]; prev2[a[i]]=i; } if(best<=dp[i]){ best=dp[i]; best_pos=i; } } vector<int> out; cout << best << '\n'; for(int i=0;i<best;i++){ out.push_back(best_pos); best_pos = prev[best_pos]; } for(int i=best-1;i>=0;i--)cout << out[i]+1 <<' '; cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...