Submission #936026

#TimeUsernameProblemLanguageResultExecution timeMemory
936026atomLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6011 ms2312 KiB
#include "bits/stdc++.h" // @JASPER'S BOILERPLATE using namespace std; using ll = long long; #ifdef JASPER #include "debug.h" #else #define debug(...) 166 #endif signed main() { cin.tie(0) -> sync_with_stdio(0); int n; cin >> n; vector <int> a(n + 5), k(n + 5); for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> k[i]; vector <int> dp(n + 5, 1), opt(n + 5, -1); int p = 0, ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j < i; ++j) { int cur = (__builtin_popcount(a[i] & a[j]) == k[i])? dp[j] : 0; if (dp[i] < cur + 1) { opt[i] = j; dp[i] = cur + 1; } } if (ans < dp[i]) { p = i; ans = dp[i]; } } // debug(dp); vector <int> ids; while (p != -1) { ids.push_back(p); p = opt[p]; } reverse(ids.begin(), ids.end()); cout << ans << "\n"; for (int x : ids) cout << x << " "; 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...