포럼
문제 ICPC00328

E. Efficiently Elevated

설명

You are an employee of the Brussels Architectural Projects Consultancy in charge of ensuring all building designs meet the accessibility requirements. As law dictates, every part of your building should be reachable for wheelchair users, which means elevators will have to be installed. You are given the blueprints of the company's current project and have to determine the minimum number of elevators required.

The floor plan is laid out on a square grid and the blueprints tell you the number of floors above any given square. You can place an elevator at any square, which stops at all floors of that square. A wheelchair user can move up and down between floors using the elevators and can freely move to any of the four adjacent squares on the same floor. Buildings do not connect diagonally.

Figure shows the second sample input. Designs can consist of multiple buildings; this one contains three buildings. The design requires two elevators: one for the pyramid-shaped building and one for the tall tower. The small building of height one does not require an elevator, since it only has a ground floor.

제약
입력 형식

The input consists of:
- One line containing integers \(h\) and \(w\) (\(1\leq h, w\leq 500\)), the height and width of the grid.
- \(h\) lines of \(w\) integers each, where \(x_{i,j}\) (\(0\leq x_{i,j} \leq 10^9\)), the \(j\)th integer on the \(i\)th line, denotes the number of floors at position \((i,j)\) of the grid.

출력 형식

Output the minimum number of elevators you need to build to be able to reach every part of the building(s) in the grid.

예제 1
입력
3 3
1 2 3
0 0 4
7 6 5
출력
1
예제 2
입력
6 7
0 0 0 0 0 0 0
0 1 2 3 2 1 0
0 1 2 3 2 1 0
0 0 0 0 0 0 0
0 1 0 5 0 0 0
0 0 0 0 0 0 0
출력
2
예제 3
입력
4 4
1 1 2 1
2 2 1 2
1 2 2 1
2 1 2 2
출력
4
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2020

평가 및 의견

E. Efficiently Elevated

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

E. Efficiently Elevated

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8