제출 #1103576

#제출 시각아이디문제언어결과실행 시간메모리
1103576stdfloatLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms456 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; 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); for (int i = 0; i < n; i++) { dp[i] = 1; pr[i] = i; for (int j = 0; j < i; j++) { if (__builtin_popcount(a[j] & a[i]) == k[i] && dp[j + 1] + 1 > dp[i]) { dp[i] = dp[j] + 1; pr[i] = j; } } } int mx = max_element(dp.begin(), dp.end()) - dp.begin(); cout << dp[mx] << '\n'; vector<int> v = {mx}; while (mx != pr[mx]) 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...