Submission #1227282

#TimeUsernameProblemLanguageResultExecution timeMemory
1227282dreamxhavaNaval battle (CEOI24_battle)C++20
0 / 100
3094 ms2116 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    vector<int> x(n), y(n);
    vector<char> d(n);
    vector<bool> active(n, true);
    vector<bool> collided(n, false);

    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> d[i];
    }

    int xmax = *max_element(x.begin(), x.end());
    int ymax = *max_element(y.begin(), y.end());

    if (n == 1) {
        // Only one ship, cannot collide
        collided[0] = false;
    } else {
        bool moving = true;
        while (moving) {
            moving = false;
            // Move all active ships
            for (int i = 0; i < n; i++) {
                if (!active[i]) continue;
                if (d[i] == 'N') y[i] -= 2;
                else if (d[i] == 'S') y[i] += 2;
                else if (d[i] == 'E') x[i] += 2;
                else if (d[i] == 'W') x[i] -= 2;

                if (x[i] > xmax || x[i] < 0 || y[i] > ymax || y[i] < 0) {
                    active[i] = false;
                } else {
                    moving = true;
                }
            }
            // Check for collisions
            for (int i = 0; i < n; i++) {
                if (!active[i]) continue;
                for (int j = i + 1; j < n; j++) {
                    if (!active[j]) continue;
                    if (x[i] == x[j] && y[i] == y[j]) {
                        collided[i] = true;
                        collided[j] = true;
                        active[i] = false;
                        active[j] = false;
                    }
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (!collided[i]) {
            cout << i + 1 << "\n";
        }
    }

    return 0;
}
#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...