CF729B.Spotlights

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.

You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.

A position is good if two conditions hold:

  • there is no actor in the cell the spotlight is placed to;
  • there is at least one actor in the direction the spotlight projects.

Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.

舞台是一个大小为 n×mn \times m 的矩形区域。导演向你提供了演员在舞台上站位的计划表:对于每个格子,计划表中都标明该格子上是否会有演员。

你需要在舞台上某个“好位置”放置一盏聚光灯。聚光灯将从其所在位置向四个方向之一(从舞台正上方俯视时)投射光线——左、右、上或下。因此,聚光灯的位置由其所处的格子及其照射方向共同确定。

一个位置是“好位置”,当且仅当满足以下两个条件:

  • 聚光灯所放置的格子上没有演员;
  • 在聚光灯照射的方向上,至少存在一个格子上有演员。

请计算所有可能的“好位置”的总数。若两盏聚光灯所处的格子不同,或照射方向不同,则视为不同的位置。

输入格式

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the plan.

The next n lines contain m integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.

第一行包含两个正整数 nn 和 mm(1 ≤ n, m ≤ 10001 ≤ n, m ≤ 1000)—— 分别表示平面图的行数和列数。

接下来的 nn 行,每行包含 mm 个整数,每个为 00 或 11 —— 描述该平面图。整数 11 表示对应单元格中将有一名演员,而 00 表示该单元格将保持为空。保证平面图中至少有一名演员。

输出格式

Print one integer — the number of good positions for placing the spotlight.

输出一个整数——表示放置聚光灯的“好位置”的数量。

输入输出样例

  • 输入#1

    2 4
    0 1 0 0
    1 0 1 0

    输出#1

    9
  • 输入#2

    4 4
    0 0 0 0
    1 0 0 1
    0 1 1 0
    0 1 0 0

    输出#2

    20

说明/提示

In the first example the following positions are good:

  1. the (1, 1) cell and right direction;
  2. the (1, 1) cell and down direction;
  3. the (1, 3) cell and left direction;
  4. the (1, 3) cell and down direction;
  5. the (1, 4) cell and left direction;
  6. the (2, 2) cell and left direction;
  7. the (2, 2) cell and up direction;
  8. the (2, 2) and right direction;
  9. the (2, 4) cell and left direction.

Therefore, there are 9 good positions in this example.

在第一个例子中,以下位置是好的:

  1. (1, 1) 单元格,方向为右;
  2. (1, 1) 单元格,方向为下;
  3. (1, 3) 单元格,方向为左;
  4. (1, 3) 单元格,方向为下;
  5. (1, 4) 单元格,方向为左;
  6. (2, 2) 单元格,方向为左;
  7. (2, 2) 单元格,方向为上;
  8. (2, 2) 单元格,方向为右;
  9. (2, 4) 单元格,方向为左。

因此,本例中有 9 个好位置。

输入解题思路,AI测评打分。不知道怎么写?

首页