제출 #877148

#제출 시각아이디문제언어결과실행 시간메모리
877148__Davit__Longest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms500 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define vr(v) v.begin(),v.end() #define rv(v) v.rbegin(),v.rend() #define Code ios_base::sync_with_stdio(false); #define By cin.tie(NULL); #define Davit cout.tie(NULL); const int B = 8; using namespace std; //#include "algo/debug.h" struct State { int len, end; }; int main() { int n; cin >> n; vector<int> a(n); vector<int> k(n); for (int i = 0; i < n; i++)cin >> a[i]; for (int i = 0; i < n; i++)cin >> k[i]; vector<vector<State>> dp1(n, vector<State>(1 << B)); for (int i = 0; i < n; i++) { dp1[i][a[i]] = {1, i}; } int ans = 1; int last = 0; vector<int> prev(n); for (int i = 0; i < n; i++)prev[i] = i; for (int i = 1; i < n; i++) { for (int j = 0; j < (1 << B); j++) { if (__builtin_popcount(a[i] & j) == k[i]) { if (dp1[i - 1][j].len + 1 > dp1[i][a[i]].len) { dp1[i][a[i]] = {dp1[i - 1][j].len + 1, i}; prev[i] = dp1[i - 1][j].end; } } } if (dp1[i][a[i]].len > ans) { ans = dp1[i][a[i]].len; last = i; } } cout << ans << endl; vector<int> res; while (prev[last] != last) { res.pb(last); last = prev[last]; } res.pb(last); reverse(vr(res)); for (int i = 0; i < (int) res.size(); i++) { cout << res[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...