-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammers_92344.java
More file actions
56 lines (48 loc) · 1.55 KB
/
Programmers_92344.java
File metadata and controls
56 lines (48 loc) · 1.55 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class Programmers_92344 {
public int solution(int[][] board, int[][] skill) {
int answer = 0;
int colSize = board[0].length;
int rowSize = board.length;
// 누적합 배열 생성
int[][] sum = new int[board.length+1][board[0].length+1];
// 2차원 누적합
for (int[] s : skill) {
int x1 = s[1];
int y1 = s[2];
int x2 = s[3];
int y2 = s[4];
int degree;
if (s[0] == 1) {
degree = -s[5];
} else {
degree = s[5];
}
sum[x1][y1] += degree;
sum[x2+1][y1] -= degree;
sum[x1][y2+1] -= degree;
sum[x2+1][y2+1] += degree;
}
// 위->아래 누적합 갱신
for (int i = 0; i < colSize; i++) { // 열
for (int j = 1; j < rowSize; j++) { // 행
sum[j][i] += sum[j-1][i];
}
}
// 왼쪽->오른쪽 누적합 갱신
for (int i = 0; i < rowSize; i++) {
for (int j = 1; j < colSize; j++) {
sum[i][j] += sum[i][j-1];
}
}
// 누적합과 초기값 더해서 결과 도출
for (int i = 0; i < rowSize; i++) {
for (int j = 0; j < colSize; j++) {
sum[i][j] += board[i][j];
if (sum[i][j] > 0) {
answer++;
}
}
}
return answer;
}
}