(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 #340115

#TimeUsernameProblemLanguageResultExecution timeMemory
340115SprdaloLongest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
5526 ms89324 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; typedef vector<pi> vp; typedef vector<pl> vpl; int pos[1024][1024][21]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); for (auto& i : pos) for (auto& j : i) for (auto& k : j) k = -1; int n; cin >> n; vi a(n); for (auto& i : a) cin >> i; vi k(n); for (auto& i : k) cin >> i; vi dp(n), last(n, -1); for (int i = 0; i < n; ++i){ dp[i] = 1; int x = 0, y = 0; for (int j = 0; j < 10; ++j){ if ((1 << j) & a[i]) x ^= (1 << j); if ((1024 << j) & a[i]) y ^= (1 << j); } for (int mask = 0; mask < 1024; ++mask){ int d = k[i] - __builtin_popcount(mask&x); if (d < 0) continue; if (pos[mask][y][d] != -1 && dp[pos[mask][y][d]] + 1 > dp[i]){ dp[i] = dp[pos[mask][y][d]] + 1; last[i] = pos[mask][y][d]; } } for (int mask = 0; mask < 1024; ++mask){ int d = __builtin_popcount(mask&y); if (pos[x][mask][d] == -1 || dp[i] > dp[pos[x][mask][d]]){ pos[x][mask][d] = i; } } } int ind = max_element(dp.begin(), dp.end()) - dp.begin(); cout << dp[ind] << '\n'; vi sol; while(ind != -1){ sol.push_back(ind); ind = last[ind]; } reverse(sol.begin(), sol.end()); for (int x : sol) cout << x+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...