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>
using namespace std;
const int nx=5e3+5;
int n, x[nx], y[nx];
char dr[nx];
bool crash(int i, int j)
{
if (dr[i]==dr[j]) return 0;
if ((dr[i]=='N'&&dr[j]=='S')||(dr[i]=='S'&&dr[j]=='N'))
{
if (x[i]==x[j]) return !(abs(y[i]-y[j])%2);
else return 0;
}
if ((dr[i]=='W'&&dr[j]=='E')||(dr[i]=='E'&&dr[j]=='W'))
{
if (y[i]==y[j]) return !(abs(y[i]-y[j])%2);
else return 0;
}
if (dr[i]=='N')
{
if (dr[j]=='W'&&y[i]>y[j]&&y[i]-y[j]==x[j]-x[i]) return 1;
if (dr[j]=='E'&&y[i]>y[j]&&y[i]-y[j]==x[i]-x[j]) return 1;
}
if (dr[i]=='S')
{
if (dr[j]=='W'&&y[i]<y[j]&&y[j]-y[i]==x[j]-x[i]) return 1;
if (dr[j]=='E'&&y[i]<y[j]&&y[j]-y[i]==x[i]-x[j]) return 1;
}
if (dr[j]=='N')
{
if (dr[i]=='W'&&y[j]>y[i]&&y[j]-y[i]==x[i]-x[j]) return 1;
if (dr[i]=='E'&&y[j]>y[i]&&y[j]-y[i]==x[j]-x[i]) return 1;
}
if (dr[j]=='S')
{
if (dr[i]=='W'&&y[j]<y[i]&&y[i]-y[j]==x[i]-x[j]) return 1;
if (dr[i]=='E'&&y[j]<y[i]&&y[i]-y[j]==x[j]-x[i]) return 1;
}
return 0;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>x[i]>>y[i]>>dr[i];
//for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) cout<<i<<' '<<j<<' '<<crash(i, j)<<'\n';
if (!crash(1, 2)) cout<<1<<'\n'<<2;
}
# | 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... |