Submission #993618

#TimeUsernameProblemLanguageResultExecution timeMemory
993618duckindogLongest beautiful sequence (IZhO17_subsequence)C++17
40 / 100
6004 ms3416 KiB
#include<bits/stdc++.h> using namespace std; const int N = 100'000 + 10; int n; int a[N], k[N]; int f[N], trace[N], d[N]; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> k[i]; for (int i = 1; i <= n; ++i){ auto& ret = f[i]; ret = 1; if (k[i] <= __builtin_popcount(a[i])) { for (int j = i - 1; j && d[j] + 1 > ret; --j) if (__builtin_popcount(a[i] & a[j]) == k[i] && f[j] + 1 > ret) ret = f[trace[i] = j] + 1; } d[i] = max(d[i - 1], ret); } int it = 0; for (int i = 1; i <= n; ++i) if (f[i] > f[it]) it = i; vector<int> answer; while (it) { answer.push_back(it); it = trace[it]; } reverse(answer.begin(), answer.end()); cout << answer.size() << "\n"; for (const auto& x : answer) cout << x << " \n"[x == answer.end()[-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...