https://programmers.co.kr/learn/courses/30/lessons/92344
#include <string>
#include <vector>
#include <cstring>
using namespace std;
int solution(vector<vector<int>> board, vector<vector<int>> skill) {
int answer = 0;
int n = board.size();
int m = board[0].size();
int tmp[1010][1010];
memset(tmp, 0, sizeof(tmp));
for (int i = 0; i < skill.size(); i++) {
int type = skill[i][0];
int x1 = skill[i][1];
int y1 = skill[i][2];
int x2 = skill[i][3];
int y2 = skill[i][4];
int deg = skill[i][5];
if (type == 1) deg = -deg;
tmp[x1][y1] += deg;
tmp[x1][y2 + 1] -= deg;
tmp[x2 + 1][y1] -= deg;
tmp[x2 + 1][y2 + 1] += deg;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
tmp[i][j] += tmp[i-1][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 1; j < m; j++) {
tmp[i][j] += tmp[i][j-1];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
board[i][j] += tmp[i][j];
if (board[i][j] > 0) answer++;
}
}
return answer;
}
'프로그래머스' 카테고리의 다른 글
양궁대회 C++ (0) | 2022.02.19 |
---|---|
주차 요금 계산 C++ (0) | 2022.02.18 |
스타 수열 C++ (0) | 2022.02.11 |
모두 0으로 만들기 C++ (0) | 2022.02.08 |
아이템 줍기 C++ (0) | 2022.02.07 |