-
Notifications
You must be signed in to change notification settings - Fork 0
/
Count number of free cell(Tle).cpp
70 lines (59 loc) · 1.46 KB
/
Count number of free cell(Tle).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
//{ 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:
vector<long long int> countZero(int n, int k, vector<vector<int>>& arr){
//Code Here
vector<long long int>ans;
vector<vector<int>>matrix(n,vector<int>(n,0));
for(int i=0;i<arr.size();i++){
int r=arr[i][0]-1;
int c=arr[i][1]-1;
for(int k=0;k<n;k++){
matrix[r][k]=1;
}
for(int k=0;k<n;k++){
matrix[k][c]=1;
}
long long int count=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
//cout<<matrix[i][j]<<" ";
if(matrix[i][j]==0) count++;
}
//cout<<endl;
}
//cout<<i<<endl;
ans.push_back(count);
}
return ans;
}
};
//{ Driver Code Starts.
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
vector<vector<int>> arr(k,vector<int>(2));
for(int i=0;i<k;i++){
int x, y;
cin>>x>>y;
arr[i][0] = x;
arr[i][1] = y;
}
Solution ob;
vector<long long int> ans = ob.countZero(n,k,arr);
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
return 0;
}
// } Driver Code Ends