제출 #1073630

#제출 시각아이디문제언어결과실행 시간메모리
1073630Hugo1729Longest beautiful sequence (IZhO17_subsequence)C++11
0 / 100
0 ms348 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); int best=-1,best_pos=-1; for(int i=0;i<n;i++){ if(a[i]>=256){ cout << "1\n1"; return 0; } } for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ if(__builtin_popcount(a[i]&a[j])==k[i]){ if(dp[i]<dp[j]+1){ dp[i]=dp[j]+1; prev[i]=j; } } } 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...