[BOJ] ๋น—๋ฌผ - 14719

Kyeongminยท2021๋…„ 9์›” 27์ผ
0

์•Œ๊ณ ๋ฆฌ์ฆ˜

๋ชฉ๋ก ๋ณด๊ธฐ
8/24

๐Ÿ“ƒ ๋ฌธ์ œ

[BOJ 14719] ๋น—๋ฌผ ๐Ÿ”—๋งํฌ


๐Ÿง  ํ’€์ด

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int map[501][501] = {0,};
    int H,W,block;
    
    cin >> H >> W;
    for(int i=1; i<=W; i++) {
        cin >> block;
        for(int j=H; j>(H-block); j--) {
            map[j][i] = 1;
        }
    }
    
    int left_side, rain=0;
    
    for(int y=1; y<=H; y++) {
        left_side = 0;
        
        for(int x=1; x<=W; x++) {
            if(map[y][x] == 1) {
                if(left_side) {
                    rain += x - left_side - 1;
                    left_side = x;
                }
                
                else
                    left_side = x;
            }
        }
    }
    
    cout << rain;
    
    return 0;
}
profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๋˜๊ณ  ์‹ถ์€ ๊ณต์žฅ์žฅ์ด๐Ÿ› 

0๊ฐœ์˜ ๋Œ“๊ธ€