(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #331677

#TimeUsernameProblemLanguageResultExecution timeMemory
331677vitkishloh228Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5739 ms93548 KiB
#include<iostream> #include<vector> #include<algorithm> #include<bitset> using namespace std; const int maxc = 10000; const int logn = 10; int dp[(1 << logn) + 1][(1 << logn) + 1][logn + 1]; int back[(1 << logn) + 1][(1 << logn) + 1][logn + 1]; int cot(int x) { return __builtin_popcount(x); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int>k(n); for (int i = 0; i < n; ++i) { cin >> k[i]; } vector<int> dp2(n); vector<int> back2(n, -1); for (int i = 0; i < n; ++i) { dp2[i] = 1; int val = a[i] & 1023; int val2 = (a[i] - val) / 1024; for (int j = 0; j < 1024; j++) { if (cot(j & val) > k[i]) { continue; } if (k[i] - cot(j & val) > 10) { continue; } if (dp[j][val2][k[i] - cot(j & val)] + 1 > dp2[i]) { back2[i] = back[j][val2][k[i] - cot(j & val)]; } dp2[i] = max(dp2[i], dp[j][val2][k[i] - cot(j & val)] + 1); } for (int j = 0; j < 1024; j++) { if (dp2[i] > dp[val][j][cot(j & val2)]) { back[val][j][cot(j & val2)] = i; } dp[val][j][cot(j & val2)] = max(dp[val][j][cot(j & val2)], dp2[i]); } } int j = 0; for (int i = 0; i < n; ++i) { if (dp2[i] > dp2[j]) j = i; } vector<int> ans; for (int i = j; i != -1; i = back2[i]) { ans.push_back(i + 1); } reverse(ans.begin(), ans.end()); cout << ans.size() << endl; for (auto elem : ans) cout << elem << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...