# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
753525 |
2023-06-05T12:34:09 Z |
Fidan |
K blocks (IZhO14_blocks) |
C++17 |
|
1 ms |
468 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define repn(i, a, b) for(ll i=ll(b)-1; i>=ll(a); i--)
#define ff first
#define ss second
#define si size()
#define pb push_back
#define be begin()
#define en end()
const ll N=110;
const ll K=110;
const ll inf=(1e9);
vector<vector<ll>> dp(N, vector<ll> (K, -1));
vector<vector<ll>> mx(N, vector<ll> (N));
vector<ll> pre(N);
vector<ll> a(N);
ll sol(ll n, ll k){
if(n<k) return -1;
if(k==1) return mx[1][n];
if(k==n) return pre[n];
if(n==0 && k==0)
if(dp[n][k]!=-1){
return dp[n][k];
}
rep(i, 0, n){
if(dp[i][k-1]==-1) sol(i, k-1);
if(dp[i][k-1]!=-1){
if(dp[n][k]==-1) dp[n][k]=dp[i][k-1]+mx[i+1][n];
else dp[n][k]=min(dp[n][k], dp[i][k-1]+mx[i+1][n]);
}
}
return dp[n][k];
}
void solve(){
ll n, k;
cin>>n>>k;
rep(i, 1, n+1){
cin>>a[i];
}
rep(i, 1, n+1){
mx[i][i]=a[i];
rep(j, i+1, n+1){
mx[i][j]=max(a[j], mx[i][j-1]);
}
}
rep(i, 1, n+1){
pre[i]=pre[i-1]+a[i];
}
cout<<sol(n, k);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t=1;
//~ cin>>t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |