Submission #486626

#TimeUsernameProblemLanguageResultExecution timeMemory
486626ez_ioiLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
47 ms1596 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 2e5 + 5, mod = 1e9 + 7, LOG = 20; int n, a[mxN], k[mxN], dp[mxN], p[mxN]; int main() { ios :: sync_with_stdio(false), cin.tie(nullptr); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> k[i]; if (n <= 5000) { pair <int, int> ans = {0, 0}; for (int i = 1; i <= n; ++i) { dp[i] = 1; for (int j = i - 1; j > 0; j--) { if (__builtin_popcount((a[i] & a[j])) == k[i]) { if (dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; p[i] = j; } } } ans = max(ans, {dp[i], i}); } cout << ans.first << '\n'; int now = ans.second; vector <int> seq; while (now) { seq.push_back(now); now = p[now]; } reverse(seq.begin(), seq.end()); for (auto x : seq) cout << x << ' '; 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...