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

#TimeUsernameProblemLanguageResultExecution timeMemory
692525biabeogo147Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, sub1 = 5e3 + 5, sub2 = 1e3 + 5; int n, A[N], K[N], dp[sub1], dp2[sub2]; void Sub1() { int ans = 0; for (int i = 1; i <= n; ++i) { dp[i] = 1; for (int j = i - 1; j >= 1; --j) if (__builtin_popcount(A[i] & A[j]) == K[i]) dp[i] = max(dp[i], dp[j] + 1); ans = max(ans, dp[i]); } cout << ans; } void Sub2() { int ans = 0; for (int i = 1; i <= n; ++i) { int maxDp = dp2[A[i]]; if (__builtin_popcount(A[i]) == K[i]) maxDp = dp2[A[i]] + 1; for (int j = 0; j < sub2; ++j) if (j != A[i] && __builtin_popcount(A[i] & j) == K[i]) maxDp = max(maxDp, dp2[j] + 1); ans = max(ans, dp2[A[i]] = maxDp); } cout << ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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) Sub1(); else Sub2(); 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...