Submission #272617

# Submission time Handle Problem Language Result Execution time Memory
272617 2020-08-18T12:51:25 Z mayhoubsaleh Domino (COCI15_domino) C++14
30 / 160
628 ms 524292 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;
const ll maxn=2222;
const ll inf=1e12+10;
const ll mod=1e9+7;
const ll base=27;

ll n,k;
ll dp[maxn][maxn][11];
ll dpr[maxn][maxn][11];
ll dpc[maxn][maxn][11];
ll a[maxn][maxn];
ll sum;

int main()
{
    IOS
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            cin>>a[i][j];
            sum+=a[i][j];
        }
    }


    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            for(ll d=0;d<=k;d++){
                dp[i][j][d]=-inf;
                dpr[i][j][d]=-inf;
                dpc[i][j][d]=-inf;
            }
        }
    }

    for(ll r=1;r<=n;r++){
        dpr[r][0][0]=0;
        for(ll c=1;c<=n;c++){
            for(ll d=0;d<=k;d++){
                dpr[r][c][d]=dpr[r][c-1][d];
                if(c-2>=0&&d)dpr[r][c][d]=max(dpr[r][c][d],a[r][c]+a[r][c-1]+dpr[r][c-2][d-1]);
            }
        }
    }
    /*for(int d=0;d<=k;d++){
        cout<<"******"<<endl;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                cout<<dpr[i][j][d]<<' ';
            }
            cout<<endl;
        }
    }*/
    for(ll c=1;c<=n;c++){
        dpc[0][c][0]=0;
        for(ll r=1;r<=n;r++){
            for(ll d=0;d<=k;d++){
                dpc[r][c][d]=dpc[r-1][c][d];
                if(r-2>=0&&d)dpc[r][c][d]=max(dpc[r][c][d],a[r][c]+a[r-1][c]+dpc[r-2][c][d-1]);
            }
        }
    }

    for(ll i=0;i<=n;i++){
        dp[0][i][0]=dp[i][0][0]=0;
    }

    for(ll r=1;r<=n;r++){
        for(ll c=1;c<=n;c++){
            for(ll d=0;d<=k;d++){
                for(ll d1=0;d1<=d;d1++){
                    ll d2=d-d1;
                    dp[r][c][d]=max(dp[r][c][d],dpr[r][c][d1]+dp[r-1][c][d2]);
                    dp[r][c][d]=max(dp[r][c][d],dpc[r][c][d1]+dp[r][c-1][d2]);
                }
            }
        }
    }
    cout<<sum-dp[n][n][k]<<endl;
    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 74 ms 76024 KB Output is correct
2 Correct 72 ms 76024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 579 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 468 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 322 ms 283512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 593 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Incorrect 2 ms 1920 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 585 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 628 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 406 ms 283732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 624 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -