알고리즘 풀이/백준

[백준][Java] 14719번 빗물

배게 2019. 12. 14. 04:09
728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int answer=0;
        
        boolean[][] map = new boolean[N][M];
        
        for(int j=0; j<M; j++) {
            
            int input = sc.nextInt();
            for(int i=0; i<input; i++) {
                map[i][j]=true;
            }
        }
        
        for(int i=0; i<N; i++) {
            Loop2 : for(int j=0; j<M; j++) {
                if (!map[i][j]) {
                    int pre = j;
                    while(pre>=0) {
                        if(map[i][pre]) break;
                        if(pre==0continue Loop2;
                        pre--;
                    }
                    pre=j;
                    while(pre<M) {
                        if(map[i][pre]) break;
                        if(pre==M-1continue Loop2;
                        pre++;
                    }
                    answer++;
                }
            }
        }
        System.out.println(answer);
    }
cs