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

Counting square

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1213    Accepted Submission(s): 644


Problem Description
There is a matrix of size R rows by C columns. Each element in the matrix is either ¡°0¡± or ¡°1¡±. A square is called magic square if it meets the following three conditions.
(1)  The elements on the four borders are all ¡°1¡±.
(2)  Inside the square (excluding the elements on the borders), the number of ¡°1¡±s and the number of ¡°0¡±s are different at most by 1.
(3)  The size of the square is at least 2 by 2.
Now given the matrix, please tell me how many magic square are there in the matrix.
 

Input
The input begins with a line containing an integer T, the number of test cases.
Each case begins with two integers R, C(1<=R,C<=300), representing the size of the matrix. Then R lines follow. Each contains C integers, either 0 or 1. The integers are separated by a single space.
 

Output
For each case, output the number of magic square in a single line.
 

Sample Input
3 4 4 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 5 5 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 1 0 0 1 1 1 1 1 1 1 2 2 1 1 1 1
 

Sample Output
3 2 1
 

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-22 08:55:31, Gzip enabled