Cardinal Adjacencies
题号:NC226651
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

In landscape ecology, one is interested in the connectedness of regions, particularly near shorelines. A fine grid is overlaid on a map or aerial photo and grid squares with land are marked: 
Land squares which share an edge are cardinal (North, East, South and West) adjacent (blue lines in the image) and land squares which share an edge or a vertex (red and blue lines in the image) are intercardinal adjacent. Write a program which takes as input a marked grid and outputs the total cardinal adjacencies in the grid and the total number of intercardinal adjacencies in the grid. 

输入描述:

The input consists of multiple lines. The first line of input contains two space separated decimal integers nrows and ncolumns, (0 < nrows,ncolumns ≤ 1000). This line is followed by nrows additional lines of input each of which contains mcolumns space separated values of 0 or 1. 1 indicates land.

输出描述:

There is one line of output containing two space separated decimal integers: the number of cardinal adjacencies followed by the number of intercardinal adjacencies.
示例1

输入

复制
5 5
1 0 0 1 0
0 1 1 0 1
0 1 0 1 1
1 0 1 1 1
0 1 1 1 1

输出

复制
14 31