Submission #1040872

# Submission time Handle Problem Language Result Execution time Memory
1040872 2024-08-01T11:14:44 Z lovrot Raisins (IOI09_raisins) C++17
30 / 100
53 ms 25920 KB
#include <cstdio>
#include <cstring> 
#include <algorithm> 

#define debug(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long ll;

const int N = 51;
const int OO = 0x7FFFFFFF;

int n, m;
int sum[N][N];
int dp[N][N][N][N];

int main() { 
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) { 
		for(int j = 1; j <= m; ++j) { 
			scanf("%d", &sum[i][j]);
			sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	}

	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) { 
			dp[i][j][i][j] = 0;
			for(int k = i; k > 0; --k) { 
				for(int l = j - (k == i); l > 0; --l) { 
					int &d = dp[i][j][k][l] = OO;

					for(int x = k; x < i; ++x) { 
						d = min(d, dp[i][j][x + 1][l] + dp[x][j][k][l]);	
					}

					for(int y = l; y < j; ++y) { 
						d = min(d, dp[i][j][k][y + 1] + dp[i][y][k][l]);	
					}

					d += sum[i][j] - sum[i][l - 1] - sum[k - 1][l] + sum[k - 1][l - 1];
//					printf("%d %d %d %d : %d\n", i, j, k, l, dp[i][j][k][l]);
				}
			}
		}
	}

	printf("%d\n", dp[n][m][1][1]);
	return 0;
}

Compilation message

raisins.cpp: In function 'int main()':
raisins.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
raisins.cpp:22:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |    scanf("%d", &sum[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Incorrect 0 ms 4444 KB Output isn't correct
6 Correct 1 ms 6492 KB Output is correct
7 Incorrect 1 ms 8540 KB Output isn't correct
8 Incorrect 1 ms 10588 KB Output isn't correct
9 Incorrect 2 ms 12892 KB Output isn't correct
10 Incorrect 2 ms 12892 KB Output isn't correct
11 Incorrect 2 ms 10848 KB Output isn't correct
12 Incorrect 5 ms 17028 KB Output isn't correct
13 Incorrect 11 ms 18868 KB Output isn't correct
14 Incorrect 4 ms 10880 KB Output isn't correct
15 Correct 10 ms 19096 KB Output is correct
16 Incorrect 3 ms 20828 KB Output isn't correct
17 Incorrect 8 ms 23132 KB Output isn't correct
18 Incorrect 25 ms 25172 KB Output isn't correct
19 Correct 41 ms 25168 KB Output is correct
20 Incorrect 53 ms 25920 KB Output isn't correct