-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path230410-2.cpp
More file actions
42 lines (38 loc) · 1.11 KB
/
230410-2.cpp
File metadata and controls
42 lines (38 loc) · 1.11 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
#include <string>
#include <vector>
using namespace std;
int pSum[1001][1001] = {0};
int solution(vector<vector<int>> board, vector<vector<int>> skill) {
int answer = 0;
int n = board.size();
int m = board[0].size();
for(int i = 0; i < skill.size(); i++)
{
int type = skill[i][0], r1 = skill[i][1], c1 = skill[i][2], r2 = skill[i][3], c2 = skill[i][4], degree = skill[i][5];
int flag = type == 1 ? -degree : degree;
pSum[r1][c1] += flag;
pSum[r2 + 1][c1] -= flag;
pSum[r1][c2 + 1] -= flag;
pSum[r2 + 1][c2 + 1] += flag;
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if(i == 0 && j > 0)
{
pSum[0][j] += pSum[0][j-1];
}
if(i > 0 && j == 0)
{
pSum[i][0] += pSum[i - 1][0];
}
if(i > 0 && j > 0)
{
pSum[i][j] += pSum[i - 1][j] + pSum[i][j - 1] - pSum[i - 1][j - 1];
}
if(pSum[i][j] + board[i][j] > 0) answer++;
}
}
return answer;
}