11#include < algorithm>
2+ #include < set>
23#include < iostream>
34#include < vector>
4- #include < set>
55using namespace std ;
66
7- bool compare_y (pair<int , int > a, pair<int , int > b) {
8- if (a.second != b.second ) return a.second <b.second ;
9- return a.first < b.first ;
10- }
11-
127bool compare_x (pair<int , int > a, pair<int , int > b) {
138 if (a.first != b.first ) return a.first <b.first ;
149 return a.second < b.second ;
1510}
1611
12+ bool compare_y (pair<int , int > a, pair<int , int > b) {
13+ if (a.second != b.second ) return a.second <b.second ;
14+ return a.first < b.first ;
15+ }
16+
1717int counter;
1818int main () {
1919 int N, M, K;
@@ -27,6 +27,7 @@ int main() {
2727 cell.push_back (make_pair (x, y));
2828 }
2929
30+
3031 for (int i = 1 ; i <= M; i++) {
3132 cell.push_back (make_pair (0 , i));
3233 cell.push_back (make_pair (N + 1 , i));
@@ -39,6 +40,15 @@ int main() {
3940
4041 K += (M + N) * 2 ;
4142
43+ sort (cell.begin (), cell.begin () + K, compare_x);
44+ for (int i = 0 ; i < K ; i++) {
45+ int space = cell[i + 1 ].second - cell[i].second ;
46+ if (space == 2 )
47+ S.insert (make_pair (cell[i].first , cell[i].second + 1 ));
48+ else if (cell[i].first == cell[i + 1 ].first && space > 2 )
49+ counter ++;
50+ }
51+
4252 sort (cell.begin (), cell.begin () + K, compare_y);
4353 for (int i = 0 ; i < K; i++) {
4454 int space = cell[i + 1 ].first - cell[i].first ;
@@ -49,16 +59,8 @@ int main() {
4959 else if (cell[i].second == cell[i + 1 ].second && space > 2 )
5060 counter ++;
5161 }
52-
53- sort (cell.begin (), cell.begin () + K, compare_x);
54- for (int i = 0 ; i < K ; i++) {
55- int space = cell[i + 1 ].second - cell[i].second ;
56- if (space == 2 )
57- S.insert (make_pair (cell[i].first , cell[i].second + 1 ));
58- else if (cell[i].first == cell[i + 1 ].first && space > 2 )
59- counter ++;
60- }
6162
6263 cout << counter << endl;
64+
6365 return 0 ;
64- }
66+ }
0 commit comments