# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1068641 | BigBadBully | Naval battle (CEOI24_battle) | C++17 | 3034 ms | 213400 KiB |
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)
{
map<char,int> bae;
bae['N'] = 0;
bae['S'] = 1;
bae['W'] = 2;
bae['E'] = 3;
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.x + a.y == b.x + b.y)
{
if (bae[a.dir]+bae[b.dir] >= 2 && bae[a.dir]+bae[b.dir]<= 4)
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;
string s;
cin >> s;
v[i].dir = s[0];
}
set<int> left;
for (int i = 0; i < n; i++)
left.insert(i);
vector<pair<int,pair<int,int>>> crash;
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++)
if (calc(v[i],v[j]))
crash.push_back({calc(v[i],v[j]),{i,j}});
sort(crash.begin(),crash.end());
int i = 0;
int old = 0;
auto exset = left;
while (old < crash.size())
{
while ((i == 0 || crash[i].ff == crash[i-1].ff) && i < crash.size())
i++;
for (old = old; old < i && old < crash.size(); old++)
{
int j = old;
if (exset.find(crash[j].ss.ff) == exset.end() ||
exset.find(crash[j].ss.ss) == exset.end())
continue;
if (left.find(crash[j].ss.ff) != left.end())
left.erase(crash[j].ss.ff);
if (left.find(crash[j].ss.ss) != left.end())
left.erase(crash[j].ss.ss);
}
i++;
exset = left;
}
if (left.size() > 0)
for (int c : left)
cout << c+1 << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |