제출 #1092432

#제출 시각아이디문제언어결과실행 시간메모리
1092432juicyLongest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
2590 ms92568 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 1e5 + 5; int n; int a[N], pr[N], cnt[1024]; array<int, 2> f[1024][1024][11]; array<int, 2> qry(int x, int y) { int i = x & 1023; array<int, 2> res{}; for (int m = 0; m < 1024; ++m) { int r = y - cnt[x >> 10 & m]; if (0 <= r && r <= 10) { res = max(res, f[m][i][r]); } } return res; } void upd(int x, array<int, 2> y) { for (int m = 0; m < 1024; ++m) { f[x >> 10][m][cnt[m & x]] = max(f[x >> 10][m][cnt[m & x]], y); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for (int i = 0; i < 1024; ++i) { cnt[i] = __builtin_popcount(i); } cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } array<int, 2> res{}; for (int i = 1; i <= n; ++i) { int k; cin >> k; auto x = qry(a[i], k); pr[i] = x[1]; ++x[0], x[1] = i; res = max(res, x); upd(a[i], x); } cout << res[0] << "\n"; vector<int> ans; for (int i = res[1]; i; i = pr[i]) { ans.push_back(i); } reverse(ans.begin(), ans.end()); for (int x : ans) { cout << x << " "; } 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...