Submission #952922

#TimeUsernameProblemLanguageResultExecution timeMemory
952922NeroZeinLongest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
2836 ms183712 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 ppcnt[M]; int a[N], k[N]; int dp[N], pre[N]; int best[M][M][22], id[M][M][22]; 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 < M; ++i) { ppcnt[i] = ppcnt[i / 2] + (i & 1); } 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] - ppcnt[a[i] & x]; if (t < 0 || t > 10) continue; 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 = ppcnt[(a[i] >> 10) & suf]; 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...