-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimos.cpp
56 lines (45 loc) · 1.18 KB
/
imos.cpp
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
// BOJ 5541 釘 (Nails)
#include <bits/stdc++.h>
#define sz size()
#define bk back()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> imos(n + 5, vector<int>(n + 5));
while (m--) {
int a, b, x;
cin >> a >> b >> x;
imos[a][b]++;
imos[a][b + 1]--;
imos[a + x + 1][b]--;
imos[a + x + 2][b + 1]++;
imos[a + x + 1][b + x + 2]++;
imos[a + x + 2][b + x + 2]--;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
imos[i][j] += imos[i][j - 1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
imos[i][j] += imos[i - 1][j];
for (int k = 2; k <= 2 * n; k++) {
for (int i = max(1, k - n); i <= min(n, k - 1); i++) {
int j = k - i;
imos[i][j] += imos[i - 1][j - 1];
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (imos[i][j] > 0)
ans++;
cout << ans;
}