Submission #646452

# Submission time Handle Problem Language Result Execution time Memory
646452 2022-09-29T20:13:05 Z Richem K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 340 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;
};

int nbNombre, blocRequis;
int nombre[MAX_NOMBRE];

int dp[MAX_NOMBRE][MAX_BLOC];

stack<Elem> s;

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

    for(int i = 0; i < nbNombre; i++) {
        for(int j = 0; j < blocRequis; j++) dp[i][j] = INF;
    }

    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});

        for(int cur = nbBloc; cur < nbNombre; cur++) {
            int mini = INF;
            while(s.top().taille < nombre[cur]) {
                mini = min(mini, dp[s.top().pos][nbBloc-1] + nombre[cur]);
                s.pop();
            }

            dp[cur][nbBloc] = min(dp[s.top().pos][nbBloc-1] + nombre[cur], dp[s.top().pos][nbBloc]);
            dp[cur][nbBloc] = min(dp[cur][nbBloc], mini);
            s.push({nombre[cur], cur});
        }
    }

    /*
    for(int i = 0; i < nbNombre; i++) {
        for(int j = 0; j < blocRequis; j++)
            cout << dp[i][j] <<  " ";
        cout << endl;
    }
    */

    cout << dp[nbNombre-1][blocRequis-1];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 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 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 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 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 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 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -