답안 #645347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645347 2022-09-26T20:28:59 Z Richem K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 232 KB
#include <iostream>
#include <stack>
#define int long long

using namespace std;

const int MAX_NOMBRE = 1e5+42, INF = 1e12, MAX_BLOC = 101;

struct Elem{
    int taille, pos, prefixMin;
};

int nbNombre, blocRequis;
int nombre[MAX_NOMBRE];

int dp[MAX_NOMBRE][MAX_BLOC];

stack<Elem> s;

signed main() {
    cin >> nbNombre >> blocRequis;

    for(int cur = 0; cur < nbNombre; cur++) {
        cin >> nombre[cur];

        dp[cur][0] = nombre[cur];
        if(cur > 0)
            dp[cur][0] = max(dp[cur][0], dp[cur-1][0]);
    }

    for(int nbBloc = 1; nbBloc < blocRequis; nbBloc++) {
        while(!s.empty()) s.pop();

        s.push({INF, nbBloc-1, INF});

        for(int cur = nbBloc; cur < nbNombre; cur++) {
            int rep = INF;
            while(s.top().taille <= nombre[cur]) {
                rep = min(rep, s.top().prefixMin + nombre[cur]);
                s.pop();
            }

            rep = min(min(s.top().prefixMin, dp[s.top().pos][nbBloc-1] + nombre[cur]), rep);
            dp[cur][nbBloc] = rep;

            s.push({nombre[cur], cur, rep});
        }
    }

    cout << dp[nbNombre-1][blocRequis-1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 232 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -