This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, x[5001], y[5001];
char c[5001];
vector<pair<int,pair<int,int>>>v;
int collision(int x1, int y1, char c1, int x2, int y2, char c2) {
if(c1 == c2) return -1;
if((c2 == 'N' && c1 == 'S') or (c2 == 'W' && c1 == 'E')) {
swap(x1, x2);
swap(y1, y2);
swap(c1, c2);
}
if(c1 == 'N' && c2 == 'S') {
if(x1 != x2 or y1 < y2) return -1;
return y1 - y2;
}
if(c1 == 'W' && c2 == 'E') {
if(y1 != y2 or x1 < x2) return -1;
return x1 - x2;
}
int X = abs(x1 - x2), Y = abs(y1 - y2);
if(X != Y) return -1;
if(c1 == 'E' or c1 == 'W') {
swap(x1, x2);
swap(y1, y2);
swap(c1, c2);
}
if(c1 == 'N' && y1 - Y != y2) return -1;
else if(c1 == 'S' && y1 + Y != y2) return -1;
if(c2 == 'W' && x2 - X != x1) return -1;
else if(c2 == 'E' && x2 + X != x1) return -1;
return X;
}
void solve() {
cin >> n;
for(int i=0; i<n; ++i) {
cin >> x[i] >> y[i] >> c[i];
}
for(int i=0; i<n; ++i) {
for(int j = i+1; j<n; ++j) {
int X = collision(x[i], y[i], c[i], x[j], y[j], c[j]);
if(X != -1) v.push_back({X, {i, j}});
}
}
sort(v.begin(), v.end());
vector<int>taken(n, -1);
for(int i=0; i<v.size(); ++i) {
int first = v[i].second.first, second = v[i].second.second;
if((taken[first] < v[i].first && taken[first] != -1) or (taken[second] < v[i].first && taken[second] != -1)) continue;
taken[first] = taken[second] = v[i].first;
}
vector<int>ans;
for(int i=0; i<n; ++i) {
if(taken[i] == -1) ans.push_back(i);
}
for(int i: ans) cout << i+1 << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:52:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0; i<v.size(); ++i) {
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |