Submission #1133530

#TimeUsernameProblemLanguageResultExecution timeMemory
1133530stdfloatLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1 << 8; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (auto &i : a) cin >> i; vector<int> k(n); for (auto &i : k) cin >> i; vector<int> dp(n), pr(n); for (int i = 0; i < n; i++) { dp[i] = 1; pr[i] = i; for (int j = i - 1; j >= 0; j--) { if (__builtin_popcount(a[j] & a[i]) == k[i]) { dp[i] = dp[j] + 1; pr[i] = j; break; } } dp[i] = max(dp[i], dp[i - 1]); } int mx = max_element(dp.begin(), dp.end()) - dp.begin(); cout << dp[mx] << '\n'; vector<int> v = {mx}; while (mx != pr[mx]) v.push_back(mx = pr[mx]); reverse(v.begin(), v.end()); for (auto i : v) 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...