Skip to content

Commit baab872

Browse files
authored
fix 1628
1 parent 5c8023f commit baab872

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

task_14_1628/1628.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#include <algorithm>
2+
#include <set>
23
#include <iostream>
34
#include <vector>
4-
#include <set>
55
using 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-
127
bool 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+
1717
int counter;
1818
int 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

Comments
 (0)