답안 #647691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647691 2022-10-03T15:54:30 Z sugartheanh K개의 묶음 (IZhO14_blocks) C++14
0 / 100
46 ms 83288 KB
#include <bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define fi first
#define se second
#define oo 1e18
#define bit(x,i) (((x)>>(i))&1)
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int K = 1e2 + 5;
int n,k,a[N];
ll dp[K][N],f[N],L[N];
int main()
{
  
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    fo(i,1,n)
        cin>>a[i];
    memset(dp,0x3f,sizeof(dp));
    memset(f,0x3f,sizeof(f));
    dp[0][0] = 0;
    fo(i,1,k)
    {
        int mx = 0;
        fo(j,1,n)
        {
            mx = max(mx, a[j]);
            if(i == 1)
                dp[i][j] = f[j] = mx;
            L[j] = j-1;
            while(L[j] > 0 && a[L[j]] <= a[j])
            {
                f[L[L[j]]] = min(f[L[L[j]]], f[L[j]]);
                L[j] = L[L[j]];
            }
//            if(i == 2 && j == 2)
//                cout<<L[j]<<' '<<f[L[j]]<<'\n';
            if(i <= j)
                dp[i][j] = min({dp[i][j], dp[i][L[j]], f[L[j]] + a[j]});
//            cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
        }
        fo(j,1,n)
            f[j] = dp[i][j];
    }
    cout<<dp[k][n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 83276 KB Output is correct
2 Correct 32 ms 83204 KB Output is correct
3 Correct 33 ms 83280 KB Output is correct
4 Correct 33 ms 83248 KB Output is correct
5 Correct 33 ms 83276 KB Output is correct
6 Correct 31 ms 83284 KB Output is correct
7 Correct 31 ms 83264 KB Output is correct
8 Correct 36 ms 83276 KB Output is correct
9 Correct 33 ms 83276 KB Output is correct
10 Incorrect 46 ms 83260 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 83272 KB Output is correct
2 Correct 34 ms 83256 KB Output is correct
3 Correct 37 ms 83276 KB Output is correct
4 Correct 39 ms 83288 KB Output is correct
5 Correct 35 ms 83204 KB Output is correct
6 Correct 35 ms 83224 KB Output is correct
7 Correct 35 ms 83228 KB Output is correct
8 Correct 32 ms 83288 KB Output is correct
9 Correct 35 ms 83196 KB Output is correct
10 Incorrect 34 ms 83192 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 83276 KB Output is correct
2 Correct 32 ms 83204 KB Output is correct
3 Correct 33 ms 83280 KB Output is correct
4 Correct 33 ms 83248 KB Output is correct
5 Correct 33 ms 83276 KB Output is correct
6 Correct 31 ms 83284 KB Output is correct
7 Correct 31 ms 83264 KB Output is correct
8 Correct 36 ms 83276 KB Output is correct
9 Correct 33 ms 83276 KB Output is correct
10 Incorrect 46 ms 83260 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 83276 KB Output is correct
2 Correct 32 ms 83204 KB Output is correct
3 Correct 33 ms 83280 KB Output is correct
4 Correct 33 ms 83248 KB Output is correct
5 Correct 33 ms 83276 KB Output is correct
6 Correct 31 ms 83284 KB Output is correct
7 Correct 31 ms 83264 KB Output is correct
8 Correct 36 ms 83276 KB Output is correct
9 Correct 33 ms 83276 KB Output is correct
10 Incorrect 46 ms 83260 KB Output isn't correct
11 Halted 0 ms 0 KB -