제출 #531178

#제출 시각아이디문제언어결과실행 시간메모리
531178clamsLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6062 ms2380 KiB
/** * @authors bubu * @date 2022-02-27 21:34:58 */ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(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> d(n, 1); // len of the longest beautiful sequence ends at i vector<int> p(n, -1); for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (__builtin_popcount(a[i] & a[j]) == k[i]) { if (d[j] + 1 > d[i]) { d[i] = d[j] + 1; p[i] = j; } } } } vector<int> ans; int it = max_element(d.begin(), d.end()) - d.begin(); while (it >= 0) { ans.push_back(it); it = p[it]; } cout << ans.size() << '\n'; reverse(ans.begin(), ans.end()); for (int i : ans) cout << i + 1 << ' '; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...