Submission #1135416

#TimeUsernameProblemLanguageResultExecution timeMemory
1135416lopkusLongest beautiful sequence (IZhO17_subsequence)C++20
23 / 100
6091 ms3400 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n + 1); vector<int> b(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int i = 1; i <= n; i++) { cin >> b[i]; } vector<int> dp(n + 1, 1); vector<int> p(n + 1, - 1); for(int i = 1; i <= n; i++) { for(int j = i - 1; j >= 1; j--) { if(__builtin_popcount((a[i] & a[j])) == b[i]) { if(dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; p[i] = j; } } } } int ans = 0; for(int i = 1; i <= n; i++) { ans = max(ans, dp[i]); } vector<int> s; for(int i = n; i >= 1; i--) { if(ans == dp[i]) { int x = i; while(x != - 1) { s.push_back(x); x = p[x]; } break; } } reverse(s.begin(), s.end()); cout << ans; cout << endl; for(auto it : s) { cout << it << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...