알고리즘/프로그래머스

Programers 덧칠하기/ C++

내이름은 킹햄찌 2023. 3. 4. 16:10

https://school.programmers.co.kr/learn/courses/30/lessons/161989

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

아이디어

특별한 trap은 없고 배열에 페인트가 칠해지지 않은 벽의 번호 표시해두고 배열의 앞에서 부터 롤러의 길이만큼 칠해주면 되는 간단한 문제이다.

 

#include <string>
#include <vector>
#include <iostream>
using namespace std;

int solution(int n, int m, vector<int> section) {
    int answer = 0;
    vector<bool> wall(n+1,true);
    for(auto iter : section)
        wall[iter] = false;
    
    for(int i=1;i<=n;i++){
        if(wall[i]) continue;
        answer++;
        for(int j=1;j<m;j++){
            if(i > n) break;
            wall[i++] = true;
        }
        
    }
    
    return answer;
}