Submission #523884

#TimeUsernameProblemLanguageResultExecution timeMemory
523884boykutLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
1 ms332 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[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...