Submission #1040891

# Submission time Handle Problem Language Result Execution time Memory
1040891 2024-08-01T11:28:13 Z lovrot Raisins (IOI09_raisins) C++17
100 / 100
1783 ms 85588 KB
#include <cstdio>
#include <cstring> 
#include <algorithm> 

#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#endif

using namespace std;

typedef long long ll;

const int N = 51;
const ll OO = 0x7FFFFFFFFFFFFFFF;

int n, m;
ll sum[N][N];
ll 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("%lld", &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) { 
					ll &d = dp[i][j][k][l];
					d = 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][j] + sum[k - 1][l - 1];
					debug("%d %d %d %d : %lld\n", i, j, k, l, dp[i][j][k][l]);
				}
			}
		}
	}

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

Compilation message

raisins.cpp: In function 'int main()':
raisins.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
raisins.cpp:26:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |    scanf("%lld", &sum[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 6 ms 16920 KB Output is correct
8 Correct 56 ms 19552 KB Output is correct
9 Correct 79 ms 26452 KB Output is correct
10 Correct 111 ms 29012 KB Output is correct
11 Correct 101 ms 22612 KB Output is correct
12 Correct 272 ms 38356 KB Output is correct
13 Correct 442 ms 45140 KB Output is correct
14 Correct 142 ms 25424 KB Output is correct
15 Correct 502 ms 48836 KB Output is correct
16 Correct 59 ms 42292 KB Output is correct
17 Correct 246 ms 47440 KB Output is correct
18 Correct 1051 ms 69376 KB Output is correct
19 Correct 1574 ms 81680 KB Output is correct
20 Correct 1783 ms 85588 KB Output is correct