F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

One to Four

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 232    Accepted Submission(s): 69


Problem Description
Given one n * m matrix consist of only positive numbers, It is guaranteed that the product of n and m is a multiple of 4, therefore, we can divide it into four identical parts(that is, every part is a 4-connected subset and we can obtain each part from each other by rotation and translation, every element must be included in exactly one part).


(Grids that from the same part are labeled by the same colour, all four partitions above are valid.)
Note that the partition below is NOT valid because we can only use translation and rotation, no symmetrical reverse:

Once we choose a partition, we can choose some translation and rotation to make these four parts coincide, finally we add up every four values lying on the same grid and choose the minimum sum as the score of the partition and transformation.
Now you're given the matrix, your task is to choose a proper partition and transformation to get the maximum score.
 

Input
There are several testcases, please process till EOF.
In each test case, first line contains two integers n and m. Following n lines each contains m integers Aij, describing the matrix.
1 ¡Ü n,m ¡Ü 30,1 ¡Ü Aij ¡Ü 10000.
 

Output
For each testcase output one line contains one integer: the maximum score you can get.
 

Sample Input
2 4 1 1 1 1 2 2 2 2 4 4 1 1 1 3 2 1 3 3 2 2 4 3 2 4 4 4
 

Sample Output
6 10
 

Author
Fudan University
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-23 01:00:46, Gzip enabled