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

#TimeUsernameProblemLanguageResultExecution timeMemory
1115237_callmelucianLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
2448 ms48828 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tpl; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const int SEP = 10, BIT = 20, mn = 1e5 + 5; int bestMask[1 << SEP][1 << SEP][SEP + 1], dp[mn], a[mn], k[mn]; void trace (int i) { for (int j = i - 1; j >= 0; j--) { if (__builtin_popcount(a[j] & a[i]) == k[i] && dp[j] + 1 == dp[i]) { trace(j); break; } } cout << i + 1 << " "; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> k[i]; int full = (1 << SEP) - 1, ans = 0, optPos = -1; for (int i = 0; i < n; i++) { // query part dp[i] = 1; for (int halfMask = 0; halfMask < (1 << SEP); halfMask++) { int curCount = __builtin_popcount(halfMask & a[i]), need = k[i] - curCount; if (0 <= need && need <= SEP) dp[i] = max(dp[i], bestMask[halfMask][a[i] >> SEP][need] + 1); } // update part for (int halfMask = 0; halfMask < (1 << SEP); halfMask++) { int curCount = __builtin_popcount((halfMask << SEP) & a[i]); bestMask[a[i] & full][halfMask][curCount] = max(bestMask[a[i] & full][halfMask][curCount], dp[i]); } if (dp[i] > ans) ans = dp[i], optPos = i; } cout << ans << "\n"; trace(optPos); 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...