QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#22356. 맛없는 풀

Estadísticas

Bessie는 연한 풀싹을 먹으며 소들처럼 우주를 생각했습니다. 농장의 기준 높이에 있는 넓은 목초지의 풀만 좋아한다는 것을 알았습니다. 겨우 1미터만 높아도 풀이 질기고 덜 맛있으며, 높을수록 더 나쁩니다.

계속 씹으면서 맛없는 풀이 언덕 비탈에서 자라며 부드럽고 푸르고 맛있고 풍부한 풀의 바다에 “섬”을 이룬다는 것을 알았습니다.

Bessie는 실험복을 입고 섬 수를 세기로 했습니다. 목초지를 $R$행 ($1 \lt R \le 1,000$), $C$열 ($1 \lt C \le 1,000$)의 $1 \times 1$미터 정사각형으로 나눈 지도를 만들었습니다. 각 칸의 기준 높이보다 높은 정도를 측정해 음이 아닌 정수로 반올림했습니다. 맛있는 풀은 모두 높이 0임을 배고픈 채로 알아챘습니다.

섬을 세기 시작했습니다. 두 칸이 가로, 세로 또는 대각선으로 이웃하면 같은 섬의 일부입니다.

각 지도에서 맛없는 풀의 섬을 몇 개 세었나요?

입력

  • $1$번째 줄: 공백으로 구분된 정수 $R$과 $C$.

  • $2,\ldots,R+1$번째 줄: $i+1$번째 줄은 공백으로 구분된 $C$개 정수로 지도의 $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

2

참고

섬은 두 개입니다. 왼쪽의 큰 섬은 대각선 연결로 맨 아래까지 이어지고, 작은 섬은 오른쪽 위에 있습니다.

문제 작성: Fatih, 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.