Submission #936012

#TimeUsernameProblemLanguageResultExecution timeMemory
936012atomLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
0 ms360 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, -1e9), opt(n + 5, -1); dp[0] = 0; for (int i = 1; i <= n; ++i) { for (int j = 0; j < i; ++j) { int p = dp[j]; // debug(i, j, p); if ((p > 0 && (__builtin_popcount(a[i] & a[j]) == k[p + 1])) || (p == 0)) { if (dp[i] < dp[j] + 1) { opt[i] = j; dp[i] = dp[j] + 1; } } } } int p = 0, ans = 0; for (int i = 1; i <= n; ++i) { if (ans < dp[i]) { p = i; ans = dp[i]; } } vector <int> ids; while (p) { 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...