Không hỗ trợ Mobile

Chế độ luyện tập yêu cầu môi trường màn hình lớn để làm bài và chống gian lận hiệu quả. Vui lòng truy cập bằng máy tính (Desktop/Laptop) để tiếp tục thao tác.

Quay lại trang chủ

#1253 · ZSHAPE

MÔ TẢ BÀI TOÁN

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.

Ràng buộc

BẢNG TỔNG QUAN KẾT QUẢ

# Tài khoản Kết suất Lúc nộp
1
T
161 ms 23224 KB
1663 Bytes
25/02/2023
20:41
2
199 ms 20332 KB
3789 Bytes
18/10/2025
08:50
3
203 ms 29612 KB
2377 Bytes
23/02/2023
16:12
4
Lê Duy Hải @2280600799
486 ms 116108 KB
4031 Bytes
18/01/2025
01:28
5
Lê Duy Hải @2280600799
500 ms 116104 KB
3944 Bytes
18/01/2025
01:29
6
704 ms 64012 KB
2985 Bytes
26/02/2023
11:45
7
829 ms 64016 KB
2983 Bytes
25/02/2023
20:31
8
856 ms 64048 KB
2985 Bytes
23/12/2025
15:28

LỊCH SỬ CÁ NHÂN

Vui lòng đăng nhập để xem lịch sử làm bài của bạn.

THẢO LUẬN BÀI TOÁN

Chưa có thảo luận nào cho bài này.

GỢI Ý & HƯỚNG DẪN

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

Viết code