제출 #939745

#제출 시각아이디문제언어결과실행 시간메모리
939745ifateenLongest beautiful sequence (IZhO17_subsequence)C++14
7 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; bool ckmax(int& a, int b) { if (a < b) return a = b, true; return false; } const int MAXN = 2001; int dp[MAXN], prv[MAXN], a[MAXN], k[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; dp[i] = 1; prv[i] = i; } for (int i = 0; i < n; i++) { cin >> k[i]; } for (int i = 1; i < n; i++) for (int j = 0; j < i; j++) if (__builtin_popcount(a[i] & a[j]) == k[i] && ckmax(dp[i], 1 + dp[j])) prv[i] = j; int mx = max_element(dp, dp + n) - dp; vector<int> ans; ans.push_back(mx); while (mx != prv[mx]) { mx = prv[mx]; ans.push_back(mx); } reverse(ans.begin(), ans.end()); cout << ans.size() << '\n'; for (auto& i : ans) cout << i + 1 << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...