반응형
https://school.programmers.co.kr/learn/courses/30/lessons/92344
class Solution {
public int solution(int[][] board, int[][] skill) {
int N = board.length;
int M = board[0].length;
int[][] newBoard = new int[N+1][M+1];
for(int i=0; i<skill.length; i++) {
int type = skill[i][0];
int r1 = skill[i][1];
int c1 = skill[i][2];
int r2 = skill[i][3];
int c2 = skill[i][4];
int degree = skill[i][5] * (type == 1 ? -1 : 1);
newBoard[r1][c1] += degree;
newBoard[r1][c2+1] -= degree;
newBoard[r2+1][c1] -= degree;
newBoard[r2+1][c2+1] += degree;
}
// 열 누적합
for(int i=0; i<N; i++) {
for(int j=1; j<M; j++) {
newBoard[i][j] += newBoard[i][j-1];
}
}
// 행 누적합
for(int j=0; j<M; j++) {
for(int i=1; i<N; i++) {
newBoard[i][j] += newBoard[i-1][j];
}
}
int answer = 0;
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
board[i][j] += newBoard[i][j];
if(board[i][j] > 0) answer++;
}
}
System.out.println(answer);
return answer;
}
}
반응형
'알고리즘 > 카카오' 카테고리의 다른 글
[프로그래머스] 이모티콘 할인행사 (0) | 2023.10.08 |
---|---|
[프로그래머스] 두 큐 합 같게 만들기 (0) | 2022.10.02 |
[프로그래머스] 행렬 테두리 회전하기 (0) | 2022.08.15 |
[프로그래머스] k진수에서 소수 개수 구하기 (0) | 2022.08.12 |
[프로그래머스] 양궁대회 (0) | 2022.08.09 |