Codeforces Round 249 (Div. 2)
D
Special Grid
Codeforces
2000
原题
← CE →
翻译中…

You are given an $*n* × *m*$ grid, some of its nodes are black, the others are white. Moreover, it's not an ordinary grid — each unit square of the grid has painted diagonals.

翻译中…

The figure below is an example of such grid of size $3 × 5$. Four nodes of this grid are black, the other $11$ nodes are white.

翻译中…

image

翻译中…

Your task is to count the number of such triangles on the given grid that:

翻译中…
  • the corners match the white nodes, and the area is positive;
  • all sides go along the grid lines (horizontal, vertical or diagonal);
  • no side contains black nodes.
翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*m*$ $(2 ≤ *n*, *m* ≤ 400)$. Each of the following $*n*$ lines contain $*m*$ characters (zeros and ones) — the description of the grid. If the $*j*$-th character in the $*i*$-th line equals zero, then the node on the $*i*$-th horizontal line and on the $*j*$-th vertical line is painted white. Otherwise, the node is painted black.

翻译中…

The horizontal lines are numbered starting from one from top to bottom, the vertical lines are numbered starting from one from left to right.

翻译中…

Output

翻译中…

Print a single integer — the number of required triangles.

翻译中…

Note

翻译中…

The figure below shows red and blue triangles. They are the examples of the required triangles in the first sample. One of the invalid triangles is painted green. It is invalid because not all sides go along the grid lines.

翻译中…

image

翻译中…

样例

Input #1
3 5
10000
10010
00001
Output #1
20
InputCopy OutputCopy
Input #2
2 2
00
00
Output #2
4
InputCopy OutputCopy
Input #3
2 2
11
11
Output #3
0
InputCopy OutputCopy
题目信息
题号
435D
时间限制
4 s
内存限制
256 MB
标签
暴力
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。