Submission #156218

#TimeUsernameProblemLanguageResultExecution timeMemory
156218theboatmanLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6071 ms1884 KiB
#include <bits/stdc++.h> #define y1 theboatman #define make_struct(args...) {args} using namespace std; int main() { cin.tie(0); ios :: sync_with_stdio(0); int n; cin >> n; vector <int> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } vector <int> k(n); for(int i = 0; i < n; i++) { cin >> k[i]; } vector <int> dp(n, 1), from(n, -1); for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { if (__builtin_popcount(a[i] & a[j]) == k[j]) { if (dp[j] < dp[i] + 1) { dp[j] = dp[i] + 1; from[j] = i; } } } } int ans = 0; for(int i = 0; i < n; i++) { ans = max(ans, dp[i]); } for(int i = 0; i < n; i++) { if (dp[i] == ans) { vector <int> way; int now = i; while(now != -1) { way.push_back(now + 1); now = from[now]; } reverse(way.begin(), way.end()); cout << way.size() << "\n"; for(auto i : way) { cout << i << " "; } return 0; } } 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...