Submission #371248

# Submission time Handle Problem Language Result Execution time Memory
371248 2021-02-26T09:47:59 Z uacoder123 Raisins (IOI09_raisins) C++14
95 / 100
1197 ms 34028 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) lli(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <ii,lli> iii;
typedef vector <lli> vi;
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ii dp[50][50][50][50];
int arr[50][50],n,m;
ii cal(int r1,int c1,int r2,int c2)
{
  if(dp[r1][c1][r2][c2].F>0)
    return dp[r1][c1][r2][c2];
  if(r1==r2&&c1==c2)
  {
    dp[r1][c1][r2][c2]=mp(0,arr[r1][c1]);
    return dp[r1][c1][r2][c2];
  }
  dp[r1][c1][r2][c2]=mp(1000*25000,1000*25000);
  for(int i=r1;i<r2;++i)
  {
    ii v1=cal(r1,c1,i,c2),v2=cal(i+1,c1,r2,c2);
    dp[r1][c1][r2][c2]=min(dp[r1][c1][r2][c2],mp(v1.F+v1.S+v2.F+v2.S,v1.S+v2.S));
  }
  for(int i=c2-1;i>=c1;--i)
  {
    ii v1=cal(r1,c1,r2,i),v2=cal(r1,i+1,r2,c2);
    dp[r1][c1][r2][c2]=min(dp[r1][c1][r2][c2],mp(v1.F+v1.S+v2.F+v2.S,v1.S+v2.S));
  }
  return dp[r1][c1][r2][c2];
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);\
  cin>>n>>m;
  for(int i=0;i<n;++i)
  {
    for(int j=0;j<m;++j)
    {
      cin>>arr[i][j];
    }
  }
  cout<<cal(0,0,n-1,m-1).F<<endl;
  return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 3 ms 1132 KB Output is correct
8 Correct 13 ms 3436 KB Output is correct
9 Correct 24 ms 4880 KB Output is correct
10 Correct 40 ms 5996 KB Output is correct
11 Correct 32 ms 4972 KB Output is correct
12 Correct 100 ms 10476 KB Output is correct
13 Correct 172 ms 13804 KB Output is correct
14 Correct 44 ms 6124 KB Output is correct
15 Correct 233 ms 15448 KB Output is correct
16 Correct 19 ms 5356 KB Output is correct
17 Correct 86 ms 11116 KB Output is correct
18 Correct 594 ms 25452 KB Output is correct
19 Incorrect 1025 ms 31340 KB Output isn't correct
20 Correct 1197 ms 34028 KB Output is correct