-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cpp
96 lines (59 loc) · 1.49 KB
/
Enemy.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//{ Driver Code Starts
//Initial Template for C++
#include<bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function Template for C++
class Solution
{
public:
int largestArea(int n,int m,int k,vector<vector<int>> &enemy)
{
vector<int> row(n,0),col(m,0);
for(int i=0;i<enemy.size();i++){
row[enemy[i][0]-1]=-1;
col[enemy[i][1]-1]=-1;
}
int area=0;
int maxrow=0,maxcol=0;
int rcnt=0,ccnt=0;
for(int i=0;i<row.size();i++){
if(row[i]!=-1){
rcnt++;
maxrow=max(maxrow,rcnt);
}else{
maxrow=max(maxrow,rcnt);
rcnt=0;
}
}
for(int i=0;i<col.size();i++){
if(col[i]!=-1){
ccnt++;
maxcol=max(maxcol,ccnt);
}else{
maxcol=max(maxcol,ccnt);
ccnt=0;
}
}return maxrow*maxcol;
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int k;
cin>>k;
vector<vector<int>> e(k,vector<int>(2));
for(int i=0;i<k;i++)
cin>>e[i][0]>>e[i][1];
Solution a;
cout<<a.largestArea(n,m,k,e)<<endl;
}
return 0;
}
// } Driver Code Ends