QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22349. 農場の警備

Statistics

農場には多くの丘があり、Farmer John は大切な乳牛の安全のためそこに警備員を置きたいと考えています。

各頂上に 1 人置くには何人必要でしょうか。地図は $N$ 行 $(1 \lt N \le 700)$、$M$ 列 $(1 \lt M \le 700)$ の整数行列で、各要素は標高 $H_{ij}$ $(0 \le H_{ij} \le 10,000)$ です。地図の頂上の数を求めてください。

頂上とは、同じ値の隣接要素一つ以上からなり、周囲が地図の端か、より低い標高の要素だけであるものです。異なる二つの要素は $X$ 座標の差の絶対値が 1 以下で、$Y$ 座標の差の絶対値も 1 以下なら隣接します。

入力

  • 行 1:空白区切りの 2 整数 $N$ と $M$。
  • 行 $2,\ldots,N+1$:行 $i+1$ は $M$ 個の空白区切りの整数 $H_{ij}$ で行列の行 $i$ を示します。

出力

  • 行 1:頂上の数を表す整数。

入出力例

入力 1

8 7
4 3 2 2 1 0 1
3 3 3 2 1 0 1
2 2 2 2 1 0 0
2 1 1 1 1 0 0
1 1 0 0 0 1 0
0 0 0 1 1 1 0
0 1 2 2 1 1 0
0 1 1 1 2 1 0

出力 1

3

注記

頂上は三つです。左上の高さ 4 の点、下部の高さ 2 の点の一つ、右上角の高さ 1 の点の一つです。

問題作成:Fatih Gelgi, 2008

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.