-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstuckinarut.cpp
56 lines (46 loc) · 1.24 KB
/
stuckinarut.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
#include <bits/stdc++.h>
using namespace std;
using pi = array<int, 3>;
using vpi = vector<pi>;
const int maxn = 1000 + 8;
bool ycmp(pi a, pi b) { return a[1] < b[1]; }
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vpi north, east;
bool removed[maxn]{false};
int stop[maxn]{0};
for (int i = 0; i < n; i++) {
char c;
int x, y;
cin >> c >> x >> y;
if(c == 'N') {
north.push_back({x, y, i});
} else {
east.push_back({x, y, i});
}
}
sort(north.begin(), north.end());
sort(east.begin(), east.end(), ycmp);
for(pi nc : north) {
for(pi ec : east) {
if(removed[ec[2]]) continue;
if(ec[1] < nc[1] || ec[0] > nc[0]) continue;
int ec_dist = nc[0] - ec[0];
int nc_dist = ec[1] - nc[1];
if(nc_dist == ec_dist) continue;
if(ec_dist < nc_dist) {
stop[ec[2]] += stop[nc[2]] + 1;
break;
}
if(nc_dist < ec_dist) {
stop[nc[2]] += stop[ec[2]] + 1;
removed[ec[2]] = true;
}
}
}
for (int i = 0; i < n; i++) {
cout << stop[i] << endl;
}
return 0;
}