# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
231929 | 2020-05-15T11:05:31 Z | T0p_ | Raisins (IOI09_raisins) | C++14 | 402 ms | 37240 KB |
#include<bits/stdc++.h> using namespace std; long long arr[55][55], dp[55][55][55][55]; long long cost(int a, int b, int c, int d) { return arr[c][d] - arr[a-1][d] - arr[c][b-1] + arr[a-1][b-1]; } int main() { int n, m; scanf(" %d %d",&n,&m); for(int i=1 ; i<=n ; i++) { for(int j=1 ; j<=m ; j++) { scanf(" %lld",&arr[i][j]); arr[i][j] += arr[i-1][j] + arr[i][j-1] - arr[i-1][j-1]; } } for(int size_i=1 ; size_i<=n ; size_i++) { for(int size_j=1 ; size_j<=m ; size_j++) { for(int si=1 ; si<=n ; si++) { for(int sj=1 ; sj<=m ; sj++) { int ei = si + size_i - 1, ej = sj + size_j - 1; if(ei > n || ej > m || (si == ei && sj == ej)) continue ; long long opt = 1e15; for(int k=si ; k<ei ; k++) { opt = min(opt, dp[si][sj][k][ej] + dp[k+1][sj][ei][ej] + cost(si, sj, ei, ej)); } for(int k=sj ; k<ej ; k++) { opt = min(opt, dp[si][sj][ei][k] + dp[si][k+1][ei][ej] + cost(si, sj, ei, ej)); } dp[si][sj][ei][ej] = opt; } } } } printf("%lld\n",dp[1][1][n][m]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 640 KB | Output is correct |
6 | Correct | 5 ms | 1024 KB | Output is correct |
7 | Correct | 5 ms | 1280 KB | Output is correct |
8 | Correct | 8 ms | 3584 KB | Output is correct |
9 | Correct | 10 ms | 5120 KB | Output is correct |
10 | Correct | 13 ms | 6144 KB | Output is correct |
11 | Correct | 11 ms | 5120 KB | Output is correct |
12 | Correct | 33 ms | 11128 KB | Output is correct |
13 | Correct | 59 ms | 14456 KB | Output is correct |
14 | Correct | 14 ms | 6400 KB | Output is correct |
15 | Correct | 72 ms | 16248 KB | Output is correct |
16 | Correct | 10 ms | 5760 KB | Output is correct |
17 | Correct | 31 ms | 11776 KB | Output is correct |
18 | Correct | 212 ms | 27516 KB | Output is correct |
19 | Correct | 342 ms | 34040 KB | Output is correct |
20 | Correct | 402 ms | 37240 KB | Output is correct |