Submission #855153

# Submission time Handle Problem Language Result Execution time Memory
855153 2023-09-30T10:34:30 Z abcvuitunggio Raisins (IOI09_raisins) C++17
100 / 100
259 ms 21136 KB
#include <bits/stdc++.h>
using namespace std;
int n,m,dp[51][51][51][51],r[51][51];
int f(int i, int j, int k, int l){
    if (i==k&&j==l)
        return 0;
    if (dp[i][j][k][l])
        return dp[i][j][k][l];
    dp[i][j][k][l]=1e9;
    for (int m=i;m<k;m++)
        dp[i][j][k][l]=min(dp[i][j][k][l],f(i,j,m,l)+f(m+1,j,k,l));
    for (int m=j;m<l;m++)
        dp[i][j][k][l]=min(dp[i][j][k][l],f(i,j,k,m)+f(i,m+1,k,l));
    dp[i][j][k][l]+=r[k][l]-r[i-1][l]-r[k][j-1]+r[i-1][j-1];
    return dp[i][j][k][l];
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> m;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++){
            cin >> r[i][j];
            r[i][j]+=r[i][j-1]+r[i-1][j]-r[i-1][j-1];
        }
    cout << f(1,1,n,m);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 1112 KB Output is correct
8 Correct 4 ms 2652 KB Output is correct
9 Correct 6 ms 3676 KB Output is correct
10 Correct 9 ms 4304 KB Output is correct
11 Correct 7 ms 3932 KB Output is correct
12 Correct 24 ms 7544 KB Output is correct
13 Correct 37 ms 9552 KB Output is correct
14 Correct 14 ms 4696 KB Output is correct
15 Correct 46 ms 10324 KB Output is correct
16 Correct 5 ms 3744 KB Output is correct
17 Correct 20 ms 7348 KB Output is correct
18 Correct 124 ms 16160 KB Output is correct
19 Correct 181 ms 19540 KB Output is correct
20 Correct 259 ms 21136 KB Output is correct