답안 #797780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797780 2023-07-29T22:14:24 Z Liudas 건포도 (IOI09_raisins) C++17
100 / 100
652 ms 49236 KB
#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long arr[50][50], pref[55][55], best[50][50][50][50];
long long calc(int a, int b, int c, int d){
    return pref[c][d] - pref[c][b] - pref[a][d] + pref[a][b];
}
long long split(int a, int b, int c, int d){
    if(c-a==1 && d-b==1){
        return 0;
    }
    if(best[a][b][c-1][d-1] < 2e12){
        return best[a][b][c-1][d-1];
    }
    for(int i = a + 1; i < c; i ++){
        best[a][b][c-1][d-1] = min(best[a][b][c-1][d-1], split(a,b,i,d) + split(i,b,c,d) + calc(a,b,c,d));
    }
    for(int i = b + 1; i < d; i ++){
        best[a][b][c-1][d-1] = min(best[a][b][c-1][d-1], split(a,b,c,i) + split(a,i,c,d) + calc(a,b,c,d));
    }
    return best[a][b][c-1][d-1];
}
int main()
{
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < N; i ++){
        for(int j = 0; j < M; j ++){
            cin >> arr[i][j];
        }
    }
    for(int i = 0; i < N; i ++){
        for(int j = 0; j < M; j ++){
            pref[i + 1][j + 1] = arr[i][j] + pref[i][j+1] + pref[i + 1][j] - pref[i][j];
        }
    }
    for(int i = 0; i < N; i ++){
        for(int j = 0; j < M; j ++){
            for(int ii = 0; ii < N; ii ++){
                for(int jj = 0; jj < M; jj ++){
                    best[i][j][ii][jj] = 1e18;
                }
            }
        }
    }
    cout << split(0, 0, N, M) << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 9 ms 4824 KB Output is correct
9 Correct 16 ms 7252 KB Output is correct
10 Correct 23 ms 8852 KB Output is correct
11 Correct 19 ms 6996 KB Output is correct
12 Correct 74 ms 16596 KB Output is correct
13 Correct 110 ms 21864 KB Output is correct
14 Correct 30 ms 8916 KB Output is correct
15 Correct 141 ms 24828 KB Output is correct
16 Correct 13 ms 8528 KB Output is correct
17 Correct 61 ms 17620 KB Output is correct
18 Correct 367 ms 38188 KB Output is correct
19 Correct 567 ms 46508 KB Output is correct
20 Correct 652 ms 49236 KB Output is correct