-
Notifications
You must be signed in to change notification settings - Fork 5
/
BS_BomberMan.cpp
53 lines (43 loc) · 971 Bytes
/
BS_BomberMan.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
/*
https://binarysearch.com/problems/Bomber-Man
Bomber Man
*/
int solve_(vector<vector<int>>& matrix) {
int m = matrix.size();
int n = matrix[0].size();
vector<int> row(m,0), col(n,0);
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
{
if(matrix[i][j]==1)
{
row[i]=1;
col[j]=1;
}
}
int safe=0;
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
{
if(!row[i] && !col[j])
{
safe++;
}
}
return safe;
}
int solve(vector<vector<int>>& matrix) {
int m = matrix.size();
int n = matrix[0].size();
set<int> sr, sc;
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
{
if(matrix[i][j]==1)
{
sr.insert(i);
sc.insert(j);
}
}
return (m-sr.size())*(n-sc.size());
}