Submission #272655

#TimeUsernameProblemLanguageResultExecution timeMemory
272655mayhoubsalehDomino (COCI15_domino)C++14
Compilation error
0 ms0 KiB
#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 (stderr)

domino.cpp:12:19: warning: overflow in conversion from 'double' to 'int' changes value from '1.00000000001e+12' to '2147483647' [-Woverflow]
   12 | const int inf=1e12+10;
      |               ~~~~^~~
domino.cpp: In function 'int main()':
domino.cpp:50:29: error: expected ')' before numeric constant
   50 |                 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]);
      |                   ~         ^~
      |                             )