Submission #1073624

#TimeUsernameProblemLanguageResultExecution timeMemory
1073624Hugo1729Longest beautiful sequence (IZhO17_subsequence)C++11
0 / 100
0 ms428 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]; if(a[i]>=256){ cout << "2\n1 2"; return 0; } } for(int i=0;i<n;i++)cin >> k[i]; vector<int> dp(256,-1); vector<int> prev(n,-1); vector<int> last(256,-1); int best=-1,best_pos=-1; for(int i=0;i<n;i++){ int sus=-1; for(int j=0;j<256;j++){ if(dp[j]==-1)continue; if(__builtin_popcount(a[i]&j)==k[i]){ // cout << a[i] << ' ' << j << '\n'; if(sus<dp[j]+1){ sus=dp[j]+1; prev[i]=last[j]; // cout << i << ' ' << j << ' ' << dp[a[i]] << ' ' << prev[i] << '\n'; } } } // cout << i << ' ' << a[i] << ' ' << dp[a[i]] << '\n'; last[a[i]]=i; if(dp[a[i]]==-1){ if(sus==-1)dp[a[i]]=1; else dp[a[i]]=sus; }else{ dp[a[i]]=max(dp[a[i]],sus); } if(best<=dp[a[i]]){ best=dp[a[i]]; best_pos=i; } } vector<int> out; // for(int i=0;i<n;i++)cout << prev[i] << ' '; // cout <<'\n'; 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...