Submission #924199

# Submission time Handle Problem Language Result Execution time Memory
924199 2024-02-08T16:10:05 Z bananade Raisins (IOI09_raisins) C++17
100 / 100
156 ms 129508 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[55][55][55][55];
int n, m;
int arr[55][55];
int ARR[55][55][55][55];
int pref[55][55];

int DP(int a, int b, int c, int d) {
	if(dp[a][b][c][d] != -1) {
		return dp[a][b][c][d];
	}
	int mini = 1e9;
	for(int i = a; i < b; i++) {
		mini = min(mini, DP(a, i, c, d) + DP(i + 1, b, c, d));
	}
	for(int i = c; i < d; i++) {
		mini = min(mini, DP(a, b, c, i) + DP(a, b, i + 1, d));
	}
	mini += pref[b][d] + pref[a - 1][c - 1] - pref[b][c - 1] - pref[a - 1][d];
	//cout << mini << " " << a << " " << b << " " << c << " " << d << "\n";
	return dp[a][b][c][d] = mini;
}

signed main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	memset(dp, -1, sizeof(dp));
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> arr[i][j];
			dp[i][i][j][j] = 0;
			ARR[i][i][j][j] = arr[i][j];
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + arr[i][j];
		}
	}
	
	cout << DP(1, n, 1, m) << "\n";
	
}

# Verdict Execution time Memory Grader output
1 Correct 15 ms 75608 KB Output is correct
2 Correct 10 ms 77916 KB Output is correct
3 Correct 11 ms 81896 KB Output is correct
4 Correct 10 ms 77916 KB Output is correct
5 Correct 12 ms 84060 KB Output is correct
6 Correct 12 ms 88156 KB Output is correct
7 Correct 14 ms 94300 KB Output is correct
8 Correct 13 ms 98392 KB Output is correct
9 Correct 16 ms 106584 KB Output is correct
10 Correct 17 ms 108628 KB Output is correct
11 Correct 15 ms 100440 KB Output is correct
12 Correct 26 ms 116820 KB Output is correct
13 Correct 35 ms 120920 KB Output is correct
14 Correct 17 ms 102492 KB Output is correct
15 Correct 35 ms 122968 KB Output is correct
16 Correct 17 ms 127068 KB Output is correct
17 Correct 25 ms 129116 KB Output is correct
18 Correct 85 ms 129508 KB Output is correct
19 Correct 113 ms 129368 KB Output is correct
20 Correct 156 ms 129480 KB Output is correct