# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
856143 |
2023-10-02T17:36:31 Z |
Irate |
Raisins (IOI09_raisins) |
C++14 |
|
434 ms |
29272 KB |
#include<cstdio>
using namespace std;
const int mxN = 52;
int min(int a, int b){
if(a > b)return b;
return a;
}
int grid[mxN][mxN], pref[mxN][mxN], dp[mxN][mxN][mxN][mxN];
int rec(int x1, int y1, int x2, int y2){
int sum = pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1], res = 1e9;
if(x1 == x2 && y1 == y2)return 0;
if(dp[x1][y1][x2][y2] != -1)return dp[x1][y1][x2][y2];
for(int i = x1 + 1;i <= x2;++i){
res = min(res, sum + rec(i, y1, x2, y2) + rec(x1, y1, i - 1, y2));
}
for(int i = y1 + 1;i <= y2;++i){
res = min(res, sum + rec(x1, y1, x2, i - 1) + rec(x1, i, x2, y2));
}
return dp[x1][y1][x2][y2] = res;
}
int main(){
int n, m;
scanf("%d %d", &n, &m);
for(int i = 0;i < mxN;++i){
for(int j = 0;j < mxN;++j){
for(int k = 0;k < mxN;++k){
for(int l = 0;l < mxN;++l){
dp[i][j][k][l] = -1;
}
}
}
}
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
scanf("%d", &grid[i][j]);
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] + grid[i][j] - pref[i - 1][j - 1];
}
}
printf("%d", rec(1, 1, n, m));
}
Compilation message
raisins.cpp: In function 'int main()':
raisins.cpp:23:10: 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:35:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%d", &grid[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Correct |
4 ms |
29020 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
4 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
28984 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
4 ms |
29020 KB |
Output is correct |
8 |
Correct |
9 ms |
29020 KB |
Output is correct |
9 |
Correct |
13 ms |
29052 KB |
Output is correct |
10 |
Correct |
19 ms |
29020 KB |
Output is correct |
11 |
Correct |
16 ms |
29048 KB |
Output is correct |
12 |
Correct |
47 ms |
29020 KB |
Output is correct |
13 |
Correct |
82 ms |
29264 KB |
Output is correct |
14 |
Correct |
24 ms |
29016 KB |
Output is correct |
15 |
Correct |
95 ms |
29020 KB |
Output is correct |
16 |
Correct |
11 ms |
29016 KB |
Output is correct |
17 |
Correct |
40 ms |
29020 KB |
Output is correct |
18 |
Correct |
225 ms |
29020 KB |
Output is correct |
19 |
Correct |
373 ms |
29272 KB |
Output is correct |
20 |
Correct |
434 ms |
29020 KB |
Output is correct |