(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #486690

#TimeUsernameProblemLanguageResultExecution timeMemory
486690ez_ioiLongest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
4591 ms184724 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 3e6 + 5, mod = 1e9 + 7, LOG = 20; int n, a[mxN], k[mxN], dp[mxN], p[mxN]; pair <int, int> d[mxN]; pair <int, int> st[2005][2005][21]; int mask1[mxN], mask2[mxN]; int bruh[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; } vector <int> f, s; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 10; ++j) { if ((a[i] >> j) & 1) mask1[i] += (1 << j); } for (int j = 10; j < 20; ++j) { if ((a[i] >> j) & 1) mask2[i] += (1 << (j - 10)); } f.push_back(mask1[i]); s.push_back(mask2[i]); } sort(f.begin(), f.end()); f.erase(unique(f.begin(), f.end()), f.end()); sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); assert(min((int)f.size(), (int)s.size()) <= (1 << 10)); pair <int, int> ans = {0, 0}; for (int i = 0; i < (1 << 20); ++i) bruh[i] = __builtin_popcount(i); for (int i = 1; i <= n; ++i) { dp[i] = 1; { // get for (auto mask : f) { int x = bruh[mask1[i] & mask]; if (x > k[i]) continue; pair <int, int> y = st[mask][mask2[i]][k[i] - x]; if (y.first + 1 > dp[i]) { p[i] = y.second; dp[i] = y.first + 1; } } } { // upd for (auto mask : s) { int x = bruh[mask & mask2[i]]; st[mask1[i]][mask][x] = max(st[mask1[i]][mask][x], {dp[i], i}); } } ans = max(ans, {dp[i], i}); } int now = ans.second; vector <int> seq; while (now > 0) { seq.push_back(now); now = p[now]; } reverse(seq.begin(), seq.end()); cout << (int)seq.size() << '\n'; for (auto x : seq) cout << x << ' '; 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...