제출 #523885

#제출 시각아이디문제언어결과실행 시간메모리
523885boykutLongest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
6090 ms2324 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int k[n]; for (int i = 0; i < n; i++) { cin >> k[i]; } int dp[n], p[n], mx = -1; fill(p, p + n, -1); for (int i = 0; i < n; i++) { dp[i] = 1; for (int j = 0; j < i; j++) { if (__builtin_popcount(a[i] & a[j]) == k[i] && dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; p[i] = j; } } if (mx == -1 || dp[i] > dp[mx]) { mx = i; } } vector<int> ans; int v = mx; while (v != -1) { ans.push_back(1 + v); v = p[v]; } cout << ans.size() << '\n'; reverse(ans.begin(), ans.end()); for (int v : ans) cout << v << ' '; 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...