Submission #1103639

#TimeUsernameProblemLanguageResultExecution timeMemory
1103639stdfloatLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms592 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1 << 9; #define sz(v) (int)(v).size() int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (auto &i : a) cin >> i; vector<int> k(n); for (auto &i : k) cin >> i; vector<int> dp(n), pr(n), ps(N, -1); for (int i = 0; i < n; i++) { assert(0 <= i && i < sz(dp)); assert(0 <= i && i < sz(pr)); assert(0 <= i && i < sz(k)); dp[i] = 1; pr[i] = i; for (int j = 0; j < N; j++) { assert(0 <= j && j < sz(ps)); assert(ps[j] == -1 || (0 <= ps[j] && ps[j] < sz(dp))); if (ps[j] != -1 && dp[ps[j]] + 1 > dp[i] && __builtin_popcount(j & a[i]) == k[i]) { dp[i] = dp[ps[j]] + 1; pr[i] = ps[j]; } } ps[a[i]] = i; } int mx = max_element(dp.begin(), dp.end()) - dp.begin(); assert(0 <= mx && mx < sz(dp)); cout << dp[mx] << '\n'; vector<int> v = {mx}; while (true) { assert(0 <= mx && mx < sz(pr)); if (mx == pr[mx]) break; v.push_back(mx = pr[mx]); } reverse(v.begin(), v.end()); for (auto i : v) cout << i + 1 << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...