Submission #952916

#TimeUsernameProblemLanguageResultExecution timeMemory
952916NeroZeinLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
11 ms4956 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define debug(...) #endif const int M = 1 << 10; const int N = 1e5 + 5; int a[N], k[N]; int dp[N], pre[N]; int best[M][M][22], id[M][M][22]; int count(int x) { return (x == 0 ? 0 : __builtin_popcount(x)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; 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) { dp[i] = 1; for (int x = 0; x < M; ++x) {//fix first 10 bits. int t = k[i] - count(a[i] & x); int suf = a[i] >> 10; if (best[x][suf][t] >= dp[i]) { dp[i] = best[x][suf][t] + 1; pre[i] = id[x][suf][t]; } } for (int suf = 0; suf < M; ++suf) { int pref = a[i] & (M - 1); int cnt = count((a[i] >> 10) & suf); assert(cnt == 0); if (dp[i] > best[pref][suf][cnt]) { id[pref][suf][cnt] = i; best[pref][suf][cnt] = dp[i]; } } } int ind = max_element(dp + 1, dp + 1 + n) - dp; vector<int> seq; while (ind) { seq.push_back(ind); ind = pre[ind]; } reverse(seq.begin(), seq.end()); cout << seq.size() << '\n'; for (int i : seq) { cout << i << ' '; } 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...