File tree Expand file tree Collapse file tree 2 files changed +109
-0
lines changed
Expand file tree Collapse file tree 2 files changed +109
-0
lines changed Original file line number Diff line number Diff line change 1+ # [ Gold V] 빗물 - 14719
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/14719 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 15072 KB, 시간: 144 ms
8+
9+ ### 분류
10+
11+ 구현, 시뮬레이션
12+
13+ ### 제출 일자
14+
15+ 2025년 3월 16일 16:18:46
16+
17+ ### 문제 설명
18+
19+ <p >2차원 세계에 블록이 쌓여있다. 비가 오면 블록 사이에 빗물이 고인다.</p >
20+
21+ <p style =" text-align : center ;" ><img alt =" " src =" https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14719/1.png " style =" height :79px ; width :146px " ><img alt =" " src =" https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14719/2.png " style =" height :79px ; width :143px " ></p >
22+
23+ <p >비는 충분히 많이 온다. 고이는 빗물의 총량은 얼마일까?</p >
24+
25+ ### 입력
26+
27+ <p >첫 번째 줄에는 2차원 세계의 세로 길이 H과 2차원 세계의 가로 길이 W가 주어진다. (1 ≤ H, W ≤ 500)</p >
28+
29+ <p >두 번째 줄에는 블록이 쌓인 높이를 의미하는 0이상 H이하의 정수가 2차원 세계의 맨 왼쪽 위치부터 차례대로 W개 주어진다.</p >
30+
31+ <p >따라서 블록 내부의 빈 공간이 생길 수 없다. 또 2차원 세계의 바닥은 항상 막혀있다고 가정하여도 좋다.</p >
32+
33+ ### 출력
34+
35+ <p >2차원 세계에서는 한 칸의 용량은 1이다. 고이는 빗물의 총량을 출력하여라.</p >
36+
37+ <p >빗물이 전혀 고이지 않을 경우 0을 출력하여라.</p >
38+
Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ static int arr [][];
7+
8+ static int dy [] = {-1 ,1 };
9+ static int N ,M ;
10+ static int answer = 0 ;
11+ public static void main (String [] args ) throws IOException {
12+
13+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
14+
15+ StringTokenizer st = new StringTokenizer (br .readLine ());
16+
17+ N = Integer .parseInt (st .nextToken ());
18+ M = Integer .parseInt (st .nextToken ());
19+
20+ arr = new int [N ][M ];
21+ st = new StringTokenizer (br .readLine ());
22+ for (int i =0 ; i <M ; i ++) {
23+ int height = Integer .parseInt (st .nextToken ());
24+ for (int j =N -1 ; j > N -1 -height ; j --) {
25+ arr [j ][i ] = 1 ;
26+ }
27+ }
28+
29+ for (int i =N -1 ; i >=0 ; i --) {
30+ for (int j = M -1 ; j >=0 ; j --) {
31+ if (arr [i ][j ]== 0 ) {
32+ bfs (i ,j );
33+ }
34+ }
35+
36+ }
37+
38+
39+ System .out .println (answer );
40+ // 0 0 0 0 1 0 0 0
41+ // 1 2 2 1 1 0 0 0
42+ // 1 2 1 1 1 2 2 1
43+ // 1 1 1 1 1 1 1 1
44+ }
45+
46+ static void bfs (int x , int y ) {
47+
48+ boolean check1 = false ;
49+ boolean check2 = false ;
50+
51+ for (int j = y ; j <M ; j ++) {
52+ if (arr [x ][j ] == 1 ) {
53+ check1 = true ;
54+ break ;
55+ }
56+ }
57+ for (int j = y ; j >=0 ; j --) {
58+ if (arr [x ][j ] == 1 ) {
59+ check2 = true ;
60+ break ;
61+ }
62+ }
63+
64+ if (check1 && check2 ) {
65+ arr [x ][y ] = 2 ;
66+ answer +=1 ;
67+ }
68+ }
69+
70+
71+ }
You can’t perform that action at this time.
0 commit comments