답안 #412702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412702 2021-05-27T11:14:23 Z dolijan 건포도 (IOI09_raisins) C++14
20 / 100
2 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
const int mn=55;
int a[mn][mn];
int rows[mn];
int cols[mn];
int dpr[mn][mn];
int dpc[mn][mn];
int prefr[mn];
int prefc[mn];
const int INF=1e9;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
            cols[i]+=a[i][j];
            rows[j]+=a[i][j];
        }
    }
    for(int i=0;i<m;i++) dpr[i][i]=0;
    prefr[0]=rows[0];
    for(int i=1;i<m;i++) prefr[i]=prefr[i-1]+rows[i];
    for(int k=1;k<m;k++)
    {
        for(int i=0;i<m;i++)
        {
            int l=i;
            int r=k+i;
            if(r>=m) continue;
            int sta=INF;
            int prefiksna=0;
            if(l==0) prefiksna=prefr[r];
            else prefiksna=prefr[r]-prefr[l-1];
            for(int j=l;j<=r-1;j++)
            {
                sta=min(sta,dpr[l][j]+dpr[j+1][r]+prefiksna);
            }
            dpr[l][r]=sta;
        }
    }
    for(int i=0;i<n;i++) dpc[i][i]=0;
    prefc[0]=cols[0];
    for(int i=1;i<n;i++) prefc[i]=prefc[i-1]+cols[i];
    for(int k=1;k<n;k++)
    {
        for(int i=0;i<n;i++)
        {
            int l=i;
            int r=k+i;
            if(r>=n) continue;
            int sta=INF;
            int prefiksna=0;
            if(l==0) prefiksna=prefc[r];
            else prefiksna=prefc[r]-prefc[l-1];
            for(int j=l;j<=r-1;j++)
            {
                sta=min(sta,dpc[l][j]+dpc[j+1][r]+prefiksna);
            }
            dpc[l][r]=sta;
        }
    }
    //cout<<dpr[0][1]<<endl;
    //cout<<dpr[0][m-1]<<endl;
    cout<<dpr[0][m-1]+dpc[0][n-1]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Incorrect 1 ms 204 KB Output isn't correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Incorrect 1 ms 204 KB Output isn't correct
11 Incorrect 1 ms 304 KB Output isn't correct
12 Incorrect 1 ms 204 KB Output isn't correct
13 Incorrect 2 ms 332 KB Output isn't correct
14 Incorrect 1 ms 204 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Incorrect 1 ms 332 KB Output isn't correct
19 Correct 1 ms 332 KB Output is correct
20 Incorrect 2 ms 332 KB Output isn't correct