-
Notifications
You must be signed in to change notification settings - Fork 0
/
764.orderOfLargestPlusSign.cpp
62 lines (60 loc) · 1.51 KB
/
764.orderOfLargestPlusSign.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
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
int orderOfLargestPlusSign(int n, vector<vector<int>> &mines) {
vector<vector<int>> dp(n, vector<int>(n, n));
unordered_set<int> banned;
for (auto &&vec : mines) {
banned.emplace(vec[0] * n + vec[1]);
}
int ans = 0;
for (int i = 0; i < n; i++) {
int count = 0;
/* left */
for (int j = 0; j < n; j++) {
if (banned.count(i * n + j)) {
count = 0;
} else {
count++;
}
dp[i][j] = min(dp[i][j], count);
}
count = 0;
/* right */
for (int j = n - 1; j >= 0; j--) {
if (banned.count(i * n + j)) {
count = 0;
} else {
count++;
}
dp[i][j] = min(dp[i][j], count);
}
}
for (int i = 0; i < n; i++) {
int count = 0;
/* up */
for (int j = 0; j < n; j++) {
if (banned.count(j * n + i)) {
count = 0;
} else {
count++;
}
dp[j][i] = min(dp[j][i], count);
}
count = 0;
/* down */
for (int j = n - 1; j >= 0; j--) {
if (banned.count(j * n + i)) {
count = 0;
} else {
count++;
}
dp[j][i] = min(dp[j][i], count);
ans = max(ans, dp[j][i]);
}
}
return ans;
}
int main() {
cout << "13" << endl;
return 0;
}