115652024-10-26 23:01:56balintPac-Mancpp17Time limit exceeded 18/1003.099s7748 KiB
#include <iostream>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <iterator>

using namespace std;

int main() {
    int N;
    cin >> N; // Read the number of points
    cin.ignore(); // Ignore the newline after reading N

    // Vectors to store the coordinates
    vector<int> X(N), Y(N), Z(N);

    // Read the X coordinates
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
    }
    cin.ignore(); // Ignore the newline after reading X

    // Read the Y coordinates
    for (int i = 0; i < N; ++i) {
        cin >> Y[i];
    }
    cin.ignore(); // Ignore the newline after reading Y

    // Read the Z coordinates
    for (int i = 0; i < N; ++i) {
        cin >> Z[i];
    }

    // Set to hold unique positions
    set<tuple<int, int, int>> poses;
    
    // Populate the set with the tuples
    for (int i = 0; i < N; ++i) {
        poses.insert(make_tuple(X[i], Y[i], Z[i]));
    }

    // Check the movement between positions
    for (auto from_pos = poses.begin(); from_pos != poses.end(); ++from_pos) {
        for (auto to_pos = next(from_pos); to_pos != poses.end(); ++to_pos) {
            vector<int> ghost_pos = {get<0>(*from_pos), get<1>(*from_pos), get<2>(*from_pos)};

            vector<int> dirs = {
                (get<0>(*to_pos) > ghost_pos[0]) - (get<0>(*to_pos) < ghost_pos[0]),
                (get<1>(*to_pos) > ghost_pos[1]) - (get<1>(*to_pos) < ghost_pos[1]),
                (get<2>(*to_pos) > ghost_pos[2]) - (get<2>(*to_pos) < ghost_pos[2])
            };

            // Continue moving the ghost until it reaches the destination
            while (ghost_pos != vector<int>{get<0>(*to_pos), get<1>(*to_pos), get<2>(*to_pos)}) {
                bool moved = false;
                for (int axis = 0; axis < 3; ++axis) {
                    // Use get with a constant index
                    if (ghost_pos[axis] != (axis == 0 ? get<0>(*to_pos) : (axis == 1 ? get<1>(*to_pos) : get<2>(*to_pos)))) {
                        vector<int> next_pos = ghost_pos;
                        next_pos[axis] += dirs[axis];
                        if (poses.count(make_tuple(next_pos[0], next_pos[1], next_pos[2]))) {
                            ghost_pos[axis] += dirs[axis];
                            moved = true;
                            break;
                        }
                    }
                }
                if (!moved) {
                    cout << "NO" << endl;
                    return 0; // Exit on failure
                }
            }
        }
    }

    cout << "YES" << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms320 KiB
3Accepted1ms320 KiB
subtask218/18
4Accepted1ms320 KiB
5Accepted1ms320 KiB
6Accepted14ms320 KiB
7Accepted4ms320 KiB
8Accepted3ms320 KiB
9Accepted1ms512 KiB
10Accepted4ms320 KiB
11Accepted3ms412 KiB
12Accepted1ms508 KiB
13Accepted2ms320 KiB
subtask30/19
14Accepted8ms724 KiB
15Accepted79ms500 KiB
16Accepted7ms824 KiB
17Accepted1.748s944 KiB
18Time limit exceeded3.091s824 KiB
19Time limit exceeded3.092s824 KiB
20Accepted1ms320 KiB
21Accepted19ms568 KiB
22Accepted8ms824 KiB
23Accepted2.387s960 KiB
24Time limit exceeded3.085s824 KiB
25Accepted21ms824 KiB
26Accepted1ms320 KiB
subtask40/24
27Accepted116ms7748 KiB
28Time limit exceeded3.085s420 KiB
29Time limit exceeded3.085s7736 KiB
30Time limit exceeded3.085s7748 KiB
31Time limit exceeded3.086s7736 KiB
32Time limit exceeded3.085s7736 KiB
33Accepted114ms320 KiB
34Time limit exceeded3.085s7748 KiB
35Time limit exceeded3.079s7736 KiB
36Time limit exceeded3.082s7744 KiB
37Time limit exceeded3.078s7736 KiB
38Accepted116ms7740 KiB
39Accepted97ms760 KiB
subtask50/22
40Accepted126ms7732 KiB
41Accepted94ms320 KiB
42Accepted32ms2540 KiB
43Accepted172ms7480 KiB
44Time limit exceeded3.086s7740 KiB
45Time limit exceeded3.072s7736 KiB
46Accepted1ms416 KiB
47Accepted39ms416 KiB
48Accepted63ms1848 KiB
49Time limit exceeded3.099s6968 KiB
50Accepted114ms7736 KiB
51Time limit exceeded3.085s7732 KiB
52Accepted114ms7736 KiB
53Accepted2ms320 KiB
subtask60/17
54Accepted156ms7732 KiB
55Time limit exceeded3.084s7736 KiB
56Accepted222ms7740 KiB
57Accepted477ms7736 KiB
58Time limit exceeded3.079s7736 KiB
59Time limit exceeded3.081s7736 KiB
60Time limit exceeded3.089s7736 KiB
61Accepted247ms7736 KiB
62Accepted279ms7736 KiB
63Time limit exceeded3.092s7736 KiB
64Time limit exceeded3.099s7736 KiB
65Accepted935ms7736 KiB
66Time limit exceeded3.099s7736 KiB