# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
415268 |
2021-05-31T18:59:07 Z |
Antekb |
Raisins (IOI09_raisins) |
C++14 |
|
368 ms |
52664 KB |
#include<bits/stdc++.h>
using namespace std;
const int N=51;
long long dp[N][N][N][N], sum[N][N][N][N];
int tab[N][N];
int main(){
int n, m;
cin>>n>>m;
for(int i=0; i<n; i++){
for(int j=0; j<m;j ++){
cin>>sum[i][i][j][j];
}
}
for(int d1=0; d1<n; d1++){
for(int i=0; i<n-d1; i++){
for(int d2=0; d2<m; d2++){
for(int j=0; j<m-d2; j++){
if(d1==0 && d2==0)continue;
dp[i][i+d1][j][j+d2]=1e18;
if(d1){
sum[i][i+d1][j][j+d2]=sum[i][i][j][j+d2]+sum[i+1][i+d1][j][j+d2];
for(int k=0; k<d1; k++){
dp[i][i+d1][j][j+d2]=min(dp[i][i+d1][j][j+d2], dp[i][i+k][j][j+d2]+dp[i+k+1][i+d1][j][j+d2]);
}
}
if(d2){
sum[i][i+d1][j][j+d2]=sum[i][i+d1][j][j]+sum[i][i+d1][j+1][j+d2];
for(int k=0; k<d2; k++){
dp[i][i+d1][j][j+d2]=min(dp[i][i+d1][j][j+d2], dp[i][i+d1][j][j+k]+dp[i][i+d1][j+k+1][j+d2]);
}
}
dp[i][i+d1][j][j+d2]+=sum[i][i+d1][j][j+d2];
//cout<<i<<" "<<i+d1<<" "<<j<<" "<<j+d2<<" "<<dp[i][i+d1][j][j+d2]<<" "<<sum[i][i+d1][j][j+d2]<<"\n";
}
}
}
}
cout<<dp[0][n-1][0][m-1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
428 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
1228 KB |
Output is correct |
7 |
Correct |
2 ms |
1964 KB |
Output is correct |
8 |
Correct |
6 ms |
4772 KB |
Output is correct |
9 |
Correct |
8 ms |
7884 KB |
Output is correct |
10 |
Correct |
10 ms |
9292 KB |
Output is correct |
11 |
Correct |
8 ms |
6732 KB |
Output is correct |
12 |
Correct |
54 ms |
17476 KB |
Output is correct |
13 |
Correct |
47 ms |
22772 KB |
Output is correct |
14 |
Correct |
11 ms |
8396 KB |
Output is correct |
15 |
Correct |
44 ms |
25988 KB |
Output is correct |
16 |
Correct |
12 ms |
13004 KB |
Output is correct |
17 |
Correct |
24 ms |
22324 KB |
Output is correct |
18 |
Correct |
189 ms |
46152 KB |
Output is correct |
19 |
Correct |
253 ms |
48592 KB |
Output is correct |
20 |
Correct |
368 ms |
52664 KB |
Output is correct |