# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
696576 |
2023-02-06T23:48:40 Z |
Hacv16 |
Raisins (IOI09_raisins) |
C++17 |
|
200 ms |
28988 KB |
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
const int MAX = 52;
const int INF = 0x3f3f3f3f;
int n, m, p[MAX][MAX], ps[MAX][MAX], dp[MAX][MAX][MAX][MAX];
int getCost(int x1, int y1, int x2, int y2){
return ps[x2][y2] - ps[x1 - 1][y2] - ps[x2][y1 - 1] + ps[x1 - 1][y1 - 1];
}
int solve(int x1, int y1, int x2, int y2){
if(x1 == x2 && y1 == y2) return 0;
if(dp[x1][y1][x2][y2] != -1) return dp[x1][y1][x2][y2];
int resp = INF;
for(int i = x1; i < x2; i++)
resp = min(resp, solve(x1, y1, i, y2) + solve(i + 1, y1, x2, y2));
for(int i = y1; i < y2; i++)
resp = min(resp, solve(x1, y1, x2, i) + solve(x1, i + 1, x2, y2));
return dp[x1][y1][x2][y2] = resp + getCost(x1, y1, x2, y2);
}
int32_t main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> p[i][j];
ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + p[i][j];
}
}
memset(dp, -1, sizeof(dp));
cout << solve(1, 1, n, m) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
28824 KB |
Output is correct |
2 |
Correct |
12 ms |
28916 KB |
Output is correct |
3 |
Correct |
15 ms |
28884 KB |
Output is correct |
4 |
Correct |
12 ms |
28952 KB |
Output is correct |
5 |
Correct |
12 ms |
28876 KB |
Output is correct |
6 |
Correct |
12 ms |
28884 KB |
Output is correct |
7 |
Correct |
12 ms |
28944 KB |
Output is correct |
8 |
Correct |
15 ms |
28848 KB |
Output is correct |
9 |
Correct |
17 ms |
28860 KB |
Output is correct |
10 |
Correct |
19 ms |
28880 KB |
Output is correct |
11 |
Correct |
18 ms |
28908 KB |
Output is correct |
12 |
Correct |
32 ms |
28884 KB |
Output is correct |
13 |
Correct |
46 ms |
28960 KB |
Output is correct |
14 |
Correct |
21 ms |
28884 KB |
Output is correct |
15 |
Correct |
54 ms |
28956 KB |
Output is correct |
16 |
Correct |
15 ms |
28880 KB |
Output is correct |
17 |
Correct |
27 ms |
28924 KB |
Output is correct |
18 |
Correct |
114 ms |
28988 KB |
Output is correct |
19 |
Correct |
179 ms |
28964 KB |
Output is correct |
20 |
Correct |
200 ms |
28956 KB |
Output is correct |