This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
struct ship{
int x,y;
char dir;
/*
Northern — decreases the y coordinate by 1
Southern — increases the y coordinate by 1
Eastern — increases the x coordinate by 1
Western — decreases the x coordinate by 1
*/
};
int calc(ship a, ship b)
{
if (a.dir == b.dir)
return 0;
if (a.x == b.x)
{
if (a.y < b.y)
swap(a,b);
if (a.dir == 'N' && b.dir == 'S')
return (a.y-b.y)/2;
return 0;
}
if (a.y == b.y)
{
if (a.x < b.x)
swap(a,b);
if (a.dir == 'W' && b.dir == 'E')
return (a.x-b.x)/2;
return 0;
}
if(a.dir == 'N')
{
if (b.dir == 'E')
{
if (b.x < a.x && a.y > b.y && b.y-a.y == b.x-a.x)
return abs(a.x-b.x);
}
else if (b.dir == 'W')
{
if (b.x > a.x && a.y > b.y && b.x+a.x == b.y+a.y)
return abs(a.x-b.x);
}
}
else if (a.dir == 'S')
{
if (b.dir == 'E')
{
if (b.x < a.x && a.y < b.y && b.x+a.x == b.y+a.y)
return abs(a.x-b.x);
}
else if (b.dir == 'W')
{
if (b.x > a.x && a.y < b.y && b.y-a.y == b.x-a.x)
return abs(a.x-b.x);
}
}
else if (a.dir == 'W')
{
if (b.dir == 'N')
{
if (b.x < a.x && a.y < b.y && b.x+a.x == b.y+a.y)
return abs(a.x-b.x);
}
else if (b.dir == 'S')
{
if (b.x < a.x && a.y > b.y && b.y-a.y == b.x-a.x)
return abs(a.x-b.x);
}
}
else if (a.dir == 'E')
{
if (b.dir == 'N')
{
if (b.x > a.x && a.y < b.y && b.y-a.y == b.x-a.x)
return abs(a.x-b.x);
}
else if (b.dir == 'S')
{
if (b.x > a.x && a.y > b.y && b.x+a.x == b.y+a.y)
return abs(a.x-b.x);
}
}
return 0;
}
signed main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<ship> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i].x >> v[i].y >> v[i].dir;
}
if (n>2)
{
cout << "n\n";
return 0;
}
ship c = v[0];
ship d = v[1];
if (!calc(c,d))
{
cout << "1\n2\n";
}
return 0;
}
# | 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... |