답안 #483969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483969 2021-11-01T16:36:37 Z gg123_pe 건포도 (IOI09_raisins) C++14
100 / 100
161 ms 15552 KB
#include <bits/stdc++.h> 
using namespace std; 

#define f(i,a,b) for(int i = a; i < b; i++)
const int inf = 1e9+10; 

int n, m, a[55][55], s[55][55], r[55][55], dp[55][55][55][55]; 

int cal(int i, int j, int m, int n){
    return r[n][j] - r[m-1][j] - r[n][i-1] + r[m-1][i-1];
}
int main(){
    scanf("%d %d", &n, &m);  
    f(i,1,n+1) {
        f(j,1,m+1) {
            scanf("%d", &a[i][j]); 
            s[i][j] = s[i][j-1] + a[i][j]; 
        }
    }
    f(j,1,m+1) f(i,1,n+1) r[i][j] = r[i-1][j] + s[i][j];  
    
    f(d1, 0, m){
        f(d2, 0, n){
            if(d1 == 0 and d2 == 0) continue;
            f(i, 1, m-d1+1){
                f(x, 1, n-d2+1){
                    int j = i+d1, y = x+d2, A = cal(i, j, x, y);
                    dp[i][j][x][y] = inf; 
                    f(k, i, j)
                        dp[i][j][x][y] = min(dp[i][j][x][y], A + dp[i][k][x][y] + dp[k+1][j][x][y]); 
                    f(k, x, y)
                        dp[i][j][x][y] = min(dp[i][j][x][y], A + dp[i][j][x][k] + dp[i][j][k+1][y]); 
                }
            }
        }
    }
    printf("%d\n", dp[1][m][1][n]); 
    return 0; 
}

Compilation message

raisins.cpp: In function 'int main()':
raisins.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
raisins.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |             scanf("%d", &a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 3 ms 2480 KB Output is correct
9 Correct 4 ms 2508 KB Output is correct
10 Correct 4 ms 3240 KB Output is correct
11 Correct 4 ms 3788 KB Output is correct
12 Correct 12 ms 5708 KB Output is correct
13 Correct 20 ms 7552 KB Output is correct
14 Correct 6 ms 5324 KB Output is correct
15 Correct 24 ms 8132 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 8 ms 3020 KB Output is correct
18 Correct 70 ms 10584 KB Output is correct
19 Correct 132 ms 15000 KB Output is correct
20 Correct 161 ms 15552 KB Output is correct