답안 #730150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730150 2023-04-25T10:49:11 Z lucri 건포도 (IOI09_raisins) C++17
100 / 100
286 ms 30020 KB
#include <iostream>
using namespace std;
int n,m,a[55][55],pd[55][55][55][55];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
        {
            cin>>a[i][j];
            a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
        }
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            for(int ii=1;ii<=n;++ii)
                for(int jj=1;jj<=m;++jj)
                    pd[i][j][ii][jj]=1000000000;
    for(int l=1;l<=n;++l)
        for(int c=1;c<=m;++c)
            for(int i=1;i+l-1<=n;++i)
                for(int j=1;j+c-1<=m;++j)
                {
                    int ii=i+l-1;
                    int jj=j+c-1;
                    if(i==ii&&j==jj)
                        pd[i][j][ii][jj]=0;
                    else
                    {
                        for(int iii=i+1;iii<=ii;++iii)
                            pd[i][j][ii][jj]=min(pd[i][j][ii][jj],pd[i][j][iii-1][jj]+pd[iii][j][ii][jj]);
                        for(int jjj=j+1;jjj<=jj;++jjj)
                            pd[i][j][ii][jj]=min(pd[i][j][ii][jj],pd[i][j][ii][jjj-1]+pd[i][jjj][ii][jj]);
                        pd[i][j][ii][jj]+=a[ii][jj]-a[i-1][jj]-a[ii][j-1]+a[i-1][j-1];
                    }
                }
    cout<<pd[1][1][n][m];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1072 KB Output is correct
8 Correct 3 ms 3412 KB Output is correct
9 Correct 5 ms 5040 KB Output is correct
10 Correct 6 ms 6100 KB Output is correct
11 Correct 6 ms 5048 KB Output is correct
12 Correct 22 ms 11072 KB Output is correct
13 Correct 39 ms 14372 KB Output is correct
14 Correct 7 ms 6328 KB Output is correct
15 Correct 43 ms 16096 KB Output is correct
16 Correct 4 ms 5332 KB Output is correct
17 Correct 22 ms 10840 KB Output is correct
18 Correct 136 ms 23240 KB Output is correct
19 Correct 244 ms 28244 KB Output is correct
20 Correct 286 ms 30020 KB Output is correct