Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:what about...

Posted by Windows2k at 2005-06-05 09:40:33 on Problem 2444
In Reply To:what about... Posted by:frkstyc at 2005-06-04 16:42:41
#include <cstring>
#include <cstdio>
using namespace std;
#define _int64 long long int
_int64 a[501][501],b[501][501];
_int64 abs(_int64 a) { return (a>0) ? a : -a; }
int m,n;
int main()
{
	while(scanf("%d %d",&m,&n)==2) {
		if(!m&&!n) break;
		_int64 min=(_int64)65535*500*500;
		for(int i=1;i<=m;i++)
			for(int j=1;j<=n;j++) scanf("%lld",&a[i][j]);
		for(int i=1;i<=m;i++)
			for(int j=1;j<=n;j++) b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j];
		for(int i=1;i<m;i++)
			for(int j=1;j<n;j++) {
				_int64 x=b[i][j],y=b[m][j]-b[i][j],
				    z=b[m][n]-b[m][j];
				_int64 t=abs(x-y)+abs(y-z)+abs(z-x);
				if(t<min) min=t;
				x=b[i][j],y=b[m][n]-b[m][j],z=b[m][j]-b[i][j];
				t=abs(x-y)+abs(y-z)+abs(z-x);
				if(t<min) min=t;
			}
		for(int i=2;i<=m;i++)
			for(int j=2;j<=n;j++) {
				_int64 x=b[i-1][n],y=b[m][j-1]-b[i-1][j-1],z=b[m][n]-b[i-1][n]-b[m][j-1]+b[i-1][j-1];
				_int64 t=abs(x-y)+abs(y-z)+abs(z-x);
				if(t<min) min=t;
				x=b[m][j-1],y=b[i-1][n]-b[i-1][j-1],z=b[m][n]-b[i-1][n]-b[m][j-1]+b[i-1][j-1];
				t=abs(x-y)+abs(y-z)+abs(z-x);
				if(t<min) min=t;
			}
		for(int i=1;i<m-1;i++)
			for(int j=i+1;j<m;j++) {
				_int64 x=b[i][n],y=b[j][n]-b[i][n],z=b[m][n]-b[j][n];
				_int64 t=abs(x-y)+abs(y-z)+abs(z-x);
				if(t<min) min=t;
			}
		for(int i=1;i<n-1;i++)
			for(int j=i+1;j<n;j++) {
				_int64 x=b[m][i],y=b[m][j]-b[m][i],z=b[m][n]-b[m][j];
				_int64 t=abs(x-y)+abs(y-z)+abs(z-x);
				if(t<min) min=t;
			}
		printf("%lld\n",min);
	}
}
--
I have considerd 4 ways of partition. But still GET WA.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator