Submission #718340

# Submission time Handle Problem Language Result Execution time Memory
718340 2023-04-04T00:28:37 Z Yell0 Raisins (IOI09_raisins) C++17
100 / 100
117 ms 21408 KB
#include <bits/stdc++.h>

using namespace std;
int N,M,a[52][52],pfs[52][52],dp[52][52][52][52];

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  cin>>N>>M;
  for(int i=1;i<=N;++i)
    for(int j=1;j<=M;++j) {
      cin>>a[i][j];
      pfs[i][j]=pfs[i-1][j]+pfs[i][j-1]-pfs[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+i-1<=N;++k)
        for(int l=1;l+j-1<=M;++l) {
          if(i==1&&j==1) {
            dp[i][j][k][l]=0;
            continue;
          }
          dp[i][j][k][l]=INT_MAX;
          for(int c=1;c<i;++c) dp[i][j][k][l]=min(dp[i][j][k][l],dp[i-c][j][k+c][l]+dp[c][j][k][l]);
          for(int c=1;c<j;++c) dp[i][j][k][l]=min(dp[i][j][k][l],dp[i][j-c][k][l+c]+dp[i][c][k][l]);
          dp[i][j][k][l]+=pfs[k+i-1][l+j-1]-pfs[k-1][l+j-1]-pfs[k+i-1][l-1]+pfs[k-1][l-1];
        }
  cout<<dp[N][M][1][1]<<'\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 3668 KB Output is correct
10 Correct 4 ms 4308 KB Output is correct
11 Correct 4 ms 3796 KB Output is correct
12 Correct 10 ms 7496 KB Output is correct
13 Correct 16 ms 9472 KB Output is correct
14 Correct 5 ms 4692 KB Output is correct
15 Correct 18 ms 10496 KB Output is correct
16 Correct 3 ms 3668 KB Output is correct
17 Correct 9 ms 7376 KB Output is correct
18 Correct 58 ms 16324 KB Output is correct
19 Correct 103 ms 19924 KB Output is correct
20 Correct 117 ms 21408 KB Output is correct