# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1088653 | 2024-09-14T17:56:26 Z | StefanSebez | 건포도 (IOI09_raisins) | C++14 | 135 ms | 25944 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define ll long long #define ld long double const int inf=1e9; int dp[51][51][51][51]; int main(){ int n,m;scanf("%i%i",&n,&m); int a[n+10][m+10],pref[n+10][m+10];memset(pref,0,sizeof(pref)); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%i",&a[i][j]); pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j]; } } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int k=1;k<=n;k++) for(int l=1;l<=m;l++) dp[i][j][k][l]=inf; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) dp[i][j][i][j]=0; for(int d1=1;d1<=n;d1++){ for(int d2=1;d2<=m;d2++){ for(int k=d1;k<=n;k++){ for(int l=d2;l<=m;l++){ int i=k-d1+1,j=l-d2+1; int sum=pref[k][l]-pref[i-1][l]-pref[k][j-1]+pref[i-1][j-1]; for(int ind=i+1;ind<=k;ind++){ dp[i][j][k][l]=min(dp[i][j][k][l],sum+dp[i][j][ind-1][l]+dp[ind][j][k][l]); } for(int ind=j+1;ind<=l;ind++){ dp[i][j][k][l]=min(dp[i][j][k][l],sum+dp[i][j][k][ind-1]+dp[i][ind][k][l]); } //printf("%i %i %i %i: %i\n",i,j,k,l,dp[i][j][k][l]); } } } } printf("%i\n",dp[1][1][n][m]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 1 ms | 1116 KB | Output is correct |
8 | Correct | 2 ms | 3420 KB | Output is correct |
9 | Correct | 4 ms | 5048 KB | Output is correct |
10 | Correct | 6 ms | 5976 KB | Output is correct |
11 | Correct | 6 ms | 4956 KB | Output is correct |
12 | Correct | 16 ms | 10572 KB | Output is correct |
13 | Correct | 25 ms | 12892 KB | Output is correct |
14 | Correct | 6 ms | 6236 KB | Output is correct |
15 | Correct | 31 ms | 14052 KB | Output is correct |
16 | Correct | 4 ms | 4700 KB | Output is correct |
17 | Correct | 15 ms | 9560 KB | Output is correct |
18 | Correct | 75 ms | 20056 KB | Output is correct |
19 | Correct | 120 ms | 24400 KB | Output is correct |
20 | Correct | 135 ms | 25944 KB | Output is correct |