제출 #1171112

#제출 시각아이디문제언어결과실행 시간메모리
1171112arkanefuryK개의 묶음 (IZhO14_blocks)C++20
100 / 100
900 ms166416 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define in insert #define lb lower_bound #define F first #define S second #define sz size() #define int long long #define all(v) v.begin(),v.end() #define FOR1(x, n) for(int j = x; j <= n; j ++) #define FOR(x, n, m, d) for(int x = n; x <= m; x += d) #define FORR(x, n, m, d) for(int x = n; x >= m; x -= d) #define nikita ios_base::sync_with_stdio(0), cin.tie(0); const int N = 3e5+5; int a[N], b[N][105], pref[N], dp[N][105], c[N]; int n,m,k,sum=0,x,y, ans, r, cnt, l, mod = 1e9+7; string s, str; void solve(){ cin >> n >> m; FOR(i, 1, n, 1)cin >> a[i]; x = 0; FOR(i, 1, n, 1){ x = max(x, a[i]); dp[i][1] = x; } FOR(i, 1, n, 1){ FORR(j, i-1, 1, 1){ if(a[i] <= a[j]){c[i] = j;break;} } } FOR(i, 1, n,1){ FOR(j, 2, m, 1)dp[i][j] = 1e18, b[i][j] = 1e18; b[i][1] = b[i][0] = b[i][2]; } b[0][1] = 1e18; FOR(i, 1, n, 1)b[i][1] = min(b[i-1][1], dp[i][1]); FOR(i, 2, m, 1){ FOR(j, i, n, 1){ x = 0; if(!c[j]){ dp[j][i] = b[j-1][i-1] + a[j]; } else{ FORR(ok, j, max(c[j], i), 1){ x = max(x, a[ok]); dp[j][i] = min(dp[j][i], dp[ok-1][i-1] + x); } dp[j][i] = min(dp[j][i], dp[c[j]][i]); } b[j][i] = min(b[j-1][i], dp[j][i]); } } cout << dp[n][m]; } signed main(){ nikita int tt = 1; if(!tt)cin >> tt; FOR(i, 1, tt, 1)solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...