Submission #344477

# Submission time Handle Problem Language Result Execution time Memory
344477 2021-01-05T23:25:44 Z limabeans Holding (COCI20_holding) C++17
110 / 110
154 ms 4716 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl










const int maxn = 102;

const int inf = 2e9;

int dp[2][maxn][maxn*maxn]; //dp[i][j][k]: first i elems, jth elem in range, k moves: min sum

int n,l,r,ops;
int a[maxn];


void upd(int &x, int y) {
    x = min(x, y);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n>>l>>r>>ops;
    --l; --r;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }

    int len = r-l+1;

    for (int i=0; i<=len; i++) {
	for (int k=0; k<=ops; k++) {
	    dp[1][i][k] = inf;
	}
    }

    dp[1][0][0] = 0;

    for (int i=0; i<n; i++) {
	for (int j=0; j<=len; j++) {
	    for (int k=0; k<=ops; k++) {
		dp[0][j][k] = dp[1][j][k];
		dp[1][j][k] = inf;
	    }
	}

	for (int j=0; j<=len; j++) {
	    for (int k=0; k<=ops; k++) {
		// move ith elem
		int mvs = abs(i-(l+j));
		if (k+mvs<=ops) {
		    upd(dp[1][j+1][k+mvs], a[i]+dp[0][j][k]);
		}
		// do nothing
		upd(dp[1][j][k], dp[0][j][k]);
	    }
	}
    }

    int res = inf;
    for (int k=0; k<=ops; k++) {
	upd(res, dp[1][len][k]);
    }

    cout<<res<<endl;
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 4 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 4 ms 1004 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 40 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 4 ms 1004 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 40 ms 2540 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 44 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 4 ms 1004 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 40 ms 2540 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 44 ms 2652 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 4 ms 492 KB Output is correct
24 Correct 7 ms 1004 KB Output is correct
25 Correct 154 ms 4716 KB Output is correct