Submission #901552

#TimeUsernameProblemLanguageResultExecution timeMemory
901552OAleksaLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
3 ms2648 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define f first #define s second const int N = 1e5 + 69; int n, a[N], b[N], dp[N], par[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1;i <= n;i++) cin >> a[i]; for (int i = 1;i <= n;i++) cin >> b[i]; dp[1] = 1; for (int i = 2;i <= n;i++) { for (int j = i - 1;j >= 1;j--) { int x = __builtin_popcount((a[i] & a[j])); if (x == b[i]) { if (dp[j] + 1 > dp[i]) { par[i] = j; dp[i] = dp[j] + 1; } } } } int mx = 1; for (int i = 2;i <= n;i++) { if (dp[i] > dp[mx]) mx = i; } int t = mx; vector<int> ans; while (t != 0) { ans.push_back(t); t = par[t]; } reverse(ans.begin(), ans.end()); cout << ans.size() << '\n'; for (auto i : ans) cout << i << " "; 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...