Submission #1031657

# Submission time Handle Problem Language Result Execution time Memory
1031657 2024-07-23T03:20:12 Z ezzzay Raisins (IOI09_raisins) C++14
100 / 100
378 ms 53340 KB
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define int long long
const int N=52;
int a[N][N];
int dp[N][N][N][N];
int ps[N][N];
int fun(int y, int x, int a, int b){
    if(dp[y][x][a][b]<INT_MAX)return dp[y][x][a][b] ;
    if(y==a and x==b){
        dp[y][x][a][b]=0;
        return 0;
    }
    
    for(int i=y;i<a;i++){
        int A= ps[a][b]-ps[a][x-1]-ps[y-1][b]+ps[y-1][x-1];
        dp[y][x][a][b]= min(dp[y][x][a][b], A+fun(y,x,i,b)+fun(i+1,x,a,b) );
    }
    
    for(int i=x;i<b;i++){
        int A=ps[a][b]-ps[a][x-1]-ps[y-1][b]+ps[y-1][x-1];
        dp[y][x][a][b]= min(dp[y][x][a][b], A+fun(y,x,a,i)+fun(y,i+1,a,b));
    }
    
    return dp[y][x][a][b];
    
}
signed main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            for(int y=1;y<=n;y++){
                for(int z=1;z<=m;z++){
                    dp[i][j][y][z]=INT_MAX;
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            ps[i][j]=ps[i][j-1]+ps[i-1][j]-ps[i-1][j-1]+a[i][j];
        }
    }
    cout<<fun(1,1,n,m);
   // cout<<dp[1][1][n][m];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 6 ms 4956 KB Output is correct
9 Correct 10 ms 7516 KB Output is correct
10 Correct 16 ms 9272 KB Output is correct
11 Correct 13 ms 7256 KB Output is correct
12 Correct 45 ms 17244 KB Output is correct
13 Correct 80 ms 22620 KB Output is correct
14 Correct 20 ms 9308 KB Output is correct
15 Correct 88 ms 25692 KB Output is correct
16 Correct 9 ms 8752 KB Output is correct
17 Correct 34 ms 18776 KB Output is correct
18 Correct 200 ms 41460 KB Output is correct
19 Correct 345 ms 50380 KB Output is correct
20 Correct 378 ms 53340 KB Output is correct