-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFENCE.cpp
More file actions
62 lines (51 loc) · 1.47 KB
/
FENCE.cpp
File metadata and controls
62 lines (51 loc) · 1.47 KB
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
// FENCING
// https://www.codechef.com/APRIL19B/problems/FENCE
#include<bits/stdc++.h>
using namespace std ;
int main(){
int t=1;
cin>>t;
while(t--){
long long ans=0;
int m,n,d;
vector<pair<int,int>> v;
map< pair<int,int> , int > mp ;
cin>>n>>m>>d;
int p,q,d2=d;
while(d2--){
cin>>p>>q;
mp[{p,q}] = 1 ;
v.push_back({p,q}) ;
}
sort(v.begin(),v.end());
for(int i=0;i<d;i++){
p = v[i].first;
q = v[i].second;
auto p1 = make_pair(p-1,q);
auto q1 = make_pair(p,q-1);
if( mp[p1]!=1 && mp[q1]!= 1 ){
/* 0
0 $ 0
0
*/
ans+=4;
}
else if( mp[p1]==1 && mp[q1]!= 1 ){
/* 0
1 $ 0
0
*/
ans+=2;
}
else if( mp[p1]!=1 && mp[q1]== 1 ){
/* 1
0 $ 0
0
*/
ans+=2;
}
}
cout<<ans<<endl ;
}
return 0;
}