Submission #1080534

#TimeUsernameProblemLanguageResultExecution timeMemory
1080534raphaelpNaval battle (CEOI24_battle)C++14
0 / 100
136 ms11464 KiB
#include <bits/stdc++.h>
using namespace std;
struct ship
{
    int x, y;
    char type;
    int dirx, diry, i;
};
istream &operator>>(istream &is, ship &s)
{
    is >> s.x >> s.y >> s.type;
    if (s.type == 'E')
        s.dirx = 1, s.diry = 0;
    if (s.type == 'W')
        s.dirx = -1, s.diry = 0;
    if (s.type == 'S')
        s.dirx = 0, s.diry = 1;
    if (s.type == 'N')
        s.dirx = 0, s.diry = -1;
    return is;
}
bool operator<(ship a, ship b)
{
    if (a.x + a.y == b.x + b.y)
        return a.x > b.x;
    return a.x + a.y < b.x + b.y;
}
void colide(int i, int j, vector<ship> &ships, vector<vector<int>> &colisions)
{
    ship a = ships[i], b = ships[j];
    if (a.type == b.type)
        return;
    if (a.dirx == 0 && b.dirx == 0 && ((a.y < b.y && a.diry == 1) || (a.y > b.y && a.diry == -1)) && a.x == b.x)
        colisions.push_back({abs(a.y - b.y) / 2, i, j});
    if (a.diry == 0 && b.diry == 0 && ((a.x < b.x && a.dirx == 1) || (a.x > b.x && a.dirx == -1)) && a.y == b.y)
        colisions.push_back({abs(a.x - b.x) / 2, i, j});
    if (a.diry == 0)
        swap(a, b);
    if (((a.y < b.y && a.diry == 1) || (a.y > b.y && a.diry == -1)) && ((b.x < a.x && b.dirx == 1) || (b.x > a.x && b.dirx == -1)) && abs(a.x - b.x) == abs(a.y - b.y))
        colisions.push_back({abs(a.x - b.x), i, j});
}
int main()
{
    int N;
    cin >> N;
    vector<ship> ships(N);
    vector<ship> E, S;
    for (int i = 0; i < N; i++)
    {
        cin >> ships[i];
        ships[i].i = i;
        if (ships[i].type == 'E')
        {
            E.push_back(ships[i]);
        }
        else
            S.push_back(ships[i]);
    }
    sort(E.begin(), E.end());
    vector<int> alive(N, 1);
    vector<int> l(E.size()), r(E.size());
    for (int i = 0; i < E.size(); i++)
    {
        l[i] = i - 1;
        r[i] = i + 1;
    }
    for (int i = 0; i < S.size(); i++)
    {
        int x = lower_bound(E.begin(), E.end(), S[i]) - E.begin();
        if (x == E.size())
            continue;
        if (alive[E[x].i] == 0)
            x = r[x];
        if (x == E.size())
            continue;
        if (E[x].x + E[x].y == S[i].x + S[i].y)
        {
            alive[E[x].i] = 0;
            alive[S[i].i] = 0;
            if (l[x] != -1)
                r[l[x]] = r[x];
            if (r[x] != E.size())
                l[r[x]] = l[x];
        }
    }
    for (int i = 0; i < N; i++)
        if (alive[i])
            cout << i + 1 << '\n';
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < E.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i < S.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp:70:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         if (x == E.size())
      |             ~~^~~~~~~~~~~
Main.cpp:74:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         if (x == E.size())
      |             ~~^~~~~~~~~~~
Main.cpp:82:22: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<ship>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             if (r[x] != E.size())
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...