제출 #100815

#제출 시각아이디문제언어결과실행 시간메모리
1008151KhanK개의 묶음 (IZhO14_blocks)C++14
0 / 100
1077 ms896 KiB
// In the name of GOD #include <bits/stdc++.h> using namespace std; #define BeGood ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); #define nl '\n' #define ff first #define ss second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() typedef long long ll; typedef double db; const int N = 1e5 + 101; const int M = 1e9 + 7; const int d = 20; int n, k, a[N]; vector<int> ans; int dp[d][N]; int ANS = M; void man(int id, int sum, int len){ if(sum > n){ return; } if(id > k){ if(sum == n){ int answer = 0; int l = 1; int r = 0; for(int i = 0; i < sz(ans); ++i){ int res = 0; r += ans[i]; int L = l; int R = r; L--; R--; for(int j = d; j >= 0; --j){ if(L + (1 << j) - 1 <= R){ res = max(res, dp[j][L]); L += 1 << j; } } answer += res; l = r + 1; } ANS = min(ANS, answer); } return; } for(int i = 1; i <= len; ++i){ ans.pb(i); sum += i; int newlen = n - sum - id + 1; man(id + 1, sum, newlen); sum -= i; ans.pop_back(); } } int main(){ BeGood cin >> n >> k; for(int i = 0; i < n; ++i){ cin >> a[i]; dp[0][i] = a[i]; } for(int i = 1; i <= d; ++i){ for(int j = 0; j <= n - (1 << i); ++j){ dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + (1 << (i - 1))]); } } man(1, 0, n - k + 1); cout << ANS; 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...