Submission #1083686

#TimeUsernameProblemLanguageResultExecution timeMemory
1083686xnqsK blocks (IZhO14_blocks)C++17
0 / 100
1 ms1372 KiB
#include <iostream> #include <fstream> #include <vector> #include <queue> #include <utility> #include <algorithm> #include <cstring> int x, k; int arr[100005]; int dp[2][100005]; void divide(int l, int r, int optl, int optr, int idx) { //std::cerr << " " << l << " " << r << " " << optl << " " << optr << " " << idx << "\n"; if (l>r) { return; } int m = (l+r)>>1; int max = 0; int opt = -1; for (int i = std::min(m, optr+100); i >= std::max(1, optl-60); i--) { max = std::max(max, arr[i]); if (dp[idx][m] > dp[idx^1][i-1]+max) { dp[idx][m] = dp[idx^1][i-1]+max; opt = i; } } divide(l,m-1,optl,opt,idx); divide(m+1,r,opt,optr,idx); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> x >> k; for (int i = 1; i <= x; i++) { std::cin >> arr[i]; } dp[1][0] = 0; for (int i = 1; i <= x; i++) { dp[1][i] = std::max(dp[1][i-1], arr[i]); } for (int i = 2; i <= k; i++) { memset(dp[i],0x3f,sizeof(dp)); divide(1,x,1,x,i&1); } std::cout << dp[k&1][x] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...