1253 - ZSHAPE

Tạo bởi: CLB Olympic Tin học HUTECH

Mô tả yêu cầu

Given a grid of size n \times m, where each cell in the grid contains either 0 or 1. Write a program to count the number of Z-shaped figures consisting entirely of 1's that appear in the grid.

An Z-shaped figure consists of:

Two horizontal lines consisting entirely of 1's, containing at least two 1's and of the same length. These two lines are located in two different rows in the grid.

A diagonal line consisting entirely of 1's connecting the rightmost cell of the upper horizontal line to the leftmost cell of the lower horizontal line. This diagonal line forms a 45-degree angle with the two horizontal lines.

The following are some valid Z-shaped figures:

The following are some invalid Z-shaped figures:

Dữ liệu vào

  • The first line contains two positive integers n and m, which are the number of rows and columns in the grid.
  • The next n lines each contain m characters, which are either 0 or 1, representing the grid.

Dữ liệu ra

A single line containing a single integer, which is the number of Z-shaped figures in the given grid.

Note that this value may be larger than the limit of the int type in C++ or longint type in Pascal.

Giới hạn

  • Subtask 1 (10 points): 1 \leq n, m \leq 6
  • Subtask 2 (40 points): 1 \leq n, m \leq 10^3

Ví dụ

Dữ liệu vào Sao chép
3 3
011
011
000
Dữ liệu ra Sao chép
1
Dữ liệu vào Sao chép
3 3
011
011
011
Dữ liệu ra Sao chép
2
Dữ liệu vào Sao chép
3 3
111
111
111
Dữ liệu ra Sao chép
6

Gợi ý/Hướng dẫn

The following are 6 Z-shaped figures that appear in the 3^th example:

Đăng nhập để làm bài
Thông tin
Giới hạn thời gian 1 giây
Giới hạn bộ nhớ 128 MB