Submission #295991

# Submission time Handle Problem Language Result Execution time Memory
295991 2020-09-10T07:00:41 Z Hemimor Raisins (IOI09_raisins) C++14
100 / 100
1002 ms 14104 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=52;
int n,m,dp[M][M][M][M];
vvi a;

int f(int x,int X,int y,int Y){
	if(x+1==X&&y+1==Y) return 0;
	if(dp[x][X][y][Y]) return dp[x][X][y][Y];
	int mn=inf;
	for(int i=x+1;i<X;i++) mn=min(mn,f(x,i,y,Y)+f(i,X,y,Y));
	for(int i=y+1;i<Y;i++) mn=min(mn,f(x,X,y,i)+f(x,X,i,Y));
	return dp[x][X][y][Y]=mn+a[X][Y]-a[x][Y]-a[X][y]+a[x][y];
}

int main(){
	scanf("%d%d",&n,&m);
	a=vvi(n+1,vi(m+1));
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
	printf("%d\n",f(0,n,0,m));
}

Compilation message

raisins.cpp: In function 'int main()':
raisins.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
raisins.cpp:54:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]);
      |                                              ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 2 ms 1024 KB Output is correct
8 Correct 12 ms 1792 KB Output is correct
9 Correct 22 ms 2816 KB Output is correct
10 Correct 31 ms 3192 KB Output is correct
11 Correct 25 ms 2424 KB Output is correct
12 Correct 97 ms 5752 KB Output is correct
13 Correct 171 ms 7032 KB Output is correct
14 Correct 41 ms 2808 KB Output is correct
15 Correct 210 ms 7928 KB Output is correct
16 Correct 20 ms 5120 KB Output is correct
17 Correct 90 ms 7672 KB Output is correct
18 Correct 547 ms 12408 KB Output is correct
19 Correct 858 ms 13048 KB Output is correct
20 Correct 1002 ms 14104 KB Output is correct