# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
272657 | 2020-08-18T13:04:31 Z | mayhoubsaleh | Domino (COCI15_domino) | C++14 | 629 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 int maxn=2222; const int inf=1e12+10; const int mod=1e9+7; const int base=27; int n,k; int dp[maxn][maxn][11]; int dpr[maxn][maxn][11]; int dpc[maxn][maxn][11]; int a[maxn][maxn]; int sum; int main() { IOS cin>>n>>k; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; sum+=a[i][j]; } } for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ for(int d=0;d<=k;d++){ dp[i][j][d]=-inf; dpr[i][j][d]=-inf; dpc[i][j][d]=-inf; } } } for(int r=1;r<=n;r++){ dpr[r][0][0]=0; for(int c=1;c<=n;c++){ for(int d=0;d<=k;d++){ dpr[r][c][d]=dpr[r][c-1][d]; if(c-2>=0&&d>0)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(int c=1;c<=n;c++){ dpc[0][c][0]=0; for(int r=1;r<=n;r++){ for(int d=0;d<=k;d++){ dpc[r][c][d]=dpc[r-1][c][d]; if(r-2>=0&&d>0)dpc[r][c][d]=max(dpc[r][c][d],a[r][c]+a[r-1][c]+dpc[r-2][c][d-1]); } } } for(int i=0;i<=n;i++){ dp[0][i][0]=dp[i][0][0]=0; } for(int r=1;r<=n;r++){ for(int c=1;c<=n;c++){ for(int d=0;d<=k;d++){ for(int d1=0;d1<=d;d1++){ int 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; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 41848 KB | Output is correct |
2 | Correct | 51 ms | 41944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1536 KB | Output is correct |
2 | Correct | 1 ms | 1536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 584 ms | 524288 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 | Incorrect | 509 ms | 331000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 242 ms | 150064 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 629 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1536 KB | Output is correct |
2 | Incorrect | 2 ms | 1536 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 616 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 3328 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 611 ms | 524292 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2176 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 322 ms | 150096 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 606 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |