Submission #222920

# Submission time Handle Problem Language Result Execution time Memory
222920 2020-04-14T10:52:50 Z miello Raisins (IOI09_raisins) C++11
100 / 100
307 ms 35192 KB
#include <bits/stdc++.h>

using namespace std;
const int INF = 1e9 + 7;

int dp[55][55][55][55];
int c[55][55];
int n , m;

void recur(int f , int s , int l , int r){
    if(f == l && s == r){
        dp[f][s][f][s] = 0;
        return;
    }
    for(int i = f ; i < l ; i++){
        if(dp[f][s][i][r] == INF){
            recur(f , s , i , r);
        }
        if(dp[i + 1][s][l][r] == INF){
            recur(i + 1 , s , l , r);
        }
        dp[f][s][l][r] = min(dp[f][s][l][r],dp[f][s][i][r] + dp[i + 1][s][l][r] + c[l][r] - c[f - 1][r] - c[l][s - 1] + c[f - 1][s - 1]); 
    }
    for(int i = s ; i < r ; i++){
        if(dp[f][s][l][i] == INF){
            recur(f , s , l , i);
        }
        if(dp[f][i + 1][l][r] == INF){
            recur(f , i + 1 , l , r);
        }
        dp[f][s][l][r] = min(dp[f][s][l][r],dp[f][s][l][i] + dp[f][i + 1][l][r] + c[l][r] - c[f - 1][r] - c[l][s - 1] + c[f - 1][s - 1]);         
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            scanf("%d",&c[i][j]);
        }
    }
    for(int i = 1 ; i < 55 ; i++){
        for(int j = 1 ; j < 55 ; j++){
            for(int k = 1 ; k < 55 ; k++){
                for(int l = 1 ; l < 55 ; l++){
                    dp[i][j][k][l] = INF;
                }
            }
        }
    }
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
        }
    }
    recur(1 , 1 , n , m);
    printf("%d",dp[1][1][n][m]);
}

Compilation message

raisins.cpp: In function 'int main()':
raisins.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
raisins.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&c[i][j]);
             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 35072 KB Output is correct
2 Correct 29 ms 35064 KB Output is correct
3 Correct 31 ms 35072 KB Output is correct
4 Correct 30 ms 35072 KB Output is correct
5 Correct 29 ms 35072 KB Output is correct
6 Correct 29 ms 35064 KB Output is correct
7 Correct 30 ms 35072 KB Output is correct
8 Correct 33 ms 35072 KB Output is correct
9 Correct 35 ms 35072 KB Output is correct
10 Correct 38 ms 35072 KB Output is correct
11 Correct 36 ms 35072 KB Output is correct
12 Correct 53 ms 35064 KB Output is correct
13 Correct 68 ms 35072 KB Output is correct
14 Correct 40 ms 35064 KB Output is correct
15 Correct 82 ms 35072 KB Output is correct
16 Correct 34 ms 35072 KB Output is correct
17 Correct 49 ms 35072 KB Output is correct
18 Correct 168 ms 35064 KB Output is correct
19 Correct 255 ms 35072 KB Output is correct
20 Correct 307 ms 35192 KB Output is correct