Submission #1124367

#TimeUsernameProblemLanguageResultExecution timeMemory
1124367votranngocvyLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N],k[N],n; namespace sub2 { int dp[N],trace[N]; void solve() { int ans = 0,cur = 0; for (int i = 1; i <= n; i++) { dp[i] = 1; for (int j = 1; j < i; j++) if (__builtin_popcount(a[i] & a[j]) == k[dp[j] + 1]) { dp[i] = max(dp[i],dp[j] + 1); trace[i] = j; } if (dp[i] > ans) ans = dp[i],cur = i; } vector<int>vec; for (int i = cur; i > 0; i = trace[i]) vec.push_back(i); reverse(vec.begin(),vec.end()); cout << ans << "\n"; for (auto x: vec) cout << x << " "; cout << "\n"; } } signed main() { ios_base::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) sub2::solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...