8098: Just Green Enough

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Farmer John 的草地可以被看作是一个由 N×N 个正方形方格组成的方阵(想象一个巨大的棋盘)。

由于土壤变异性,某些方格中的草可能更绿。

每个方格 (i,j) 可以用一个整数绿度值 G(i,j) 来描述,范围为 1…200。

Farmer John 想要给他的草地的一个子矩阵拍摄一张照片。

他希望确保这一子矩阵看上去足够绿,但又不绿得过分,所以他决定拍摄一个 G 的最小值恰好等于 100 的子矩阵。

请帮助他求出他可以拍摄多少不同的照片。

子矩阵最大可以为整个草地,最小可以仅为一个方格(共有 N2(N+1)2/4 个不同的子矩阵——注意该数可能无法用 32 位整数型存储,所以你可能需要使用 64 位整数类型,例如 C++ 中的 long long)。

输入格式

输入的第一行包含 N。

以下 N 行每行包含 N 个整数,表示 N×N 草地的 G(i,j) 值。

输出格式

输出 Farmer John 可以拍摄的不同的照片数量——也就是说,最小绿度值等于 100100 的子矩阵数量。

注意这个问题涉及到的整数大小可能需要使用 6464 位整数型存储(例如,C/C++ 中的 long long)。

数据范围

1≤N≤500


Farmer John's pasture can be regarded as an N×N grid (1≤N≤500) of square "cells" of grass (picture a huge chessboard). Due to soil variability, the grass in some cells is greener than in others. Each cell (i,j)is described by an integer level of green-ness G(i,j), ranging from 1…200.

Farmer John wants to take a photograph of a rectangular sub-grid of his pasture. He wants to be sure the sub-grid looks sufficiently green, but not ridiculously green, so he decides to photograph a sub-grid for which the minimum value of GG is exactly 100. Please help him determine how many different photographs he could possibly take. A sub-grid can be as large as the entire pasture or as small as a single grid cell (there are N2(N+1)2/4different sub-grids in total --- note that this number might be too large to store in a standard 32-bit integer, so you might need to use 64-bit integer data types like a "long long" in C++).

INPUT FORMAT (input arrives from the terminal / stdin):

The first line of input contains N. The next N lines each contain N integers and collectively describe the G(i,j)Gvalues for the N×Npasture.

OUTPUT FORMAT (print output to the terminal / stdout):

Please print the number of distinct photos Farmer John can take -- that is, the number of rectangular sub-grids for which the minimum level of green-ness is exactly 100. Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

SAMPLE INPUT:

3
57 120 87
200 100 150
2 141 135

SAMPLE OUTPUT:

8

输入样例 复制

3
57 120 87
200 100 150
2 141 135

输出样例 复制

8