Submission #754146

# Submission time Handle Problem Language Result Execution time Memory
754146 2023-06-07T02:26:55 Z Olympia K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 328 KB
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <map>
#include <set>
using namespace std;
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    int64_t arr[N];
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    int64_t INF = 1e17;
    vector<int64_t> prev(N + 1), cur(N + 1);
    prev.assign(N + 1, INF), cur.assign(N + 1, INF);
    for (int j = 1; j <= N; j++) {
        prev[j] = ((j == 1) ? arr[0] : max(prev[j - 1], arr[j - 1]));
    }
    for (int i = 2; i <= K; i++) {
        vector<int64_t> val;
        val.assign(N + 1, INF);
        for (int j = 1; j <= N; j++) {
            if (j == 1) {
            	val[0] = prev[0] + arr[0];
            	cur[1] = prev[0] + arr[0];
            } else {
                cur[j] = INF;
                int64_t myMax = 0;
                for (int l = j - 1; l >= 0; l--) {
                    myMax = max(myMax, arr[l]);
                    if (arr[l] != myMax) {
                    	continue;
                    }
                    if (myMax == arr[j - 1]) {
                        cur[j] = min(cur[j], prev[l] + myMax);
                        val[l] = prev[l] + myMax;
                    } else {
                        assert(prev[l] + myMax == val[l]);
                        cur[j] = min(cur[j], val[l]);
                        //assert(cur[j] == prev[j]);
                    }
                }
            }
        }
        swap(cur, prev);
    }
    cout << prev[N];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 320 KB Output is correct
8 Correct 1 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 1 ms 320 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Incorrect 1 ms 324 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 320 KB Output is correct
8 Correct 1 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 1 ms 320 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 320 KB Output is correct
8 Correct 1 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 1 ms 320 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -