Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
- template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
- const int maxn = 1005;
- vector<pair<pair<int,int>,char>>cows;
- vector<int>ans(maxn, -1), will_go(maxn, 1e9), stopper(maxn, -2);
- vector<int>g[maxn], sub(maxn, 0);
- int n;
- void dfs(int node) {
- if(ans[node]!=-1) return;
- for(auto it : g[node]) {
- dfs(it);
- sub[node] += sub[it];
- }
- ans[node] = sub[node];
- ++sub[node];
- }
- bool possible_stopper(int i, int j) {
- if(cows[i].second==cows[j].second) return false;
- if(cows[i].second=='E') {
- if(cows[j].first.second > cows[i].first.second) return false;
- if(cows[j].first.first < cows[i].first.first) return false;
- if(cows[j].first.first - cows[i].first.first <= cows[i].first.second - cows[j].first.second)
- return false;
- } else {
- if(cows[j].first.first > cows[i].first.first) return false;
- if(cows[j].first.second < cows[i].first.second) return false;
- if(cows[j].first.second - cows[i].first.second <= cows[i].first.first - cows[j].first.first)
- return false;
- }
- return true;
- }
- void AddEdge(int u, int v) {
- g[u].push_back(v);
- }
- void check(int i) {
- for(int j=0; j<n; ++j) if(i!=j) {
- if(possible_stopper(i, j)) {
- if(stopper[j]==-2) check(j);
- if(cows[i].second=='E') {
- if(cows[i].first.second - cows[j].first.second < will_go[j]) {
- if(will_go[i] > cows[j].first.first - cows[i].first.first)
- will_go[i] = cows[j].first.first - cows[i].first.first, stopper[i] = j;
- }
- } else {
- if(cows[j].first.first + will_go[j] > cows[i].first.first) {
- if(will_go[i] > cows[j].first.second - cows[i].first.second)
- will_go[i] = cows[j].first.second - cows[i].first.second, stopper[i] = j;
- }
- }
- }
- }
- if(stopper[i]==-2) stopper[i] = -1;
- if(stopper[i]!=-1) AddEdge(stopper[i], i);
- }
- void PlayGround() {
- cin >> n;
- for(int i=0; i<n; ++i) {
- char d;
- int x, y; cin >> d >> x >> y;
- cows.push_back(make_pair(make_pair(x, y), d));
- }
- for(int i=0; i<n; ++i) {
- if(stopper[i]==-2) check(i);
- }
- for(int i=0; i<n; ++i) {
- dfs(i);
- cout << ans[i] << '\n';
- }
- #ifndef ONLINE_JUDGE
- cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- #endif
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- //#ifndef ONLINE_JUDGE
- // freopen("input.txt", "r", stdin);
- //#endif
- PlayGround();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement