Submission #776767

# Submission time Handle Problem Language Result Execution time Memory
776767 2023-07-08T08:49:30 Z danikoynov Team Contest (JOI22_team) C++14
100 / 100
181 ms 11840 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


struct beaver
{
    int x, y, z, idx;

    beaver(int _x =  0, int _y = 0, int _z = 0, int _idx = 0)
    {
        x = _x;
        y = _y;
        z = _z;
        idx = _idx;
    }
};

const int maxn = 150010;
beaver bx[maxn], by[maxn], bz[maxn];

bool cmp_x(beaver b1, beaver b2)
{
    return b1.x < b2.x;
}

bool cmp_y(beaver b1, beaver b2)
{
    return b1.y < b2.y;
}

bool cmp_z(beaver b1, beaver b2)
{
    return b1.z < b2.z;
}


int n, used[maxn];
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        beaver b;
        cin >> b.x >> b.y >> b.z;
        b.idx = i;
        bx[i] = by[i] = bz[i] = b;
    }

    sort(bx + 1, bx + n + 1, cmp_x);
    sort(by + 1, by + n + 1, cmp_y);
    sort(bz + 1, bz + n + 1, cmp_z);

    int px, py, pz;
    px = n;
    py = n;
    pz = n;

    for (int i = 1; i <= n; i ++)
    {
        while(used[bx[px].idx] == 1)
            px --;
        while(used[by[py].idx] == 1)
            py --;
        while(used[bz[pz].idx] == 1)
            pz --;

        int mx = bx[px].x;
        int my = by[py].y;
        int mz = bz[pz].z;

        if (bx[px].y == my || bx[px].z == mz)
        {
            used[bx[px].idx] = 1;
            continue;
        }

        if (by[py].x == mx || by[py].z == mz)
        {
            used[by[py].idx] = 1;
            continue;
        }


        if (bz[pz].x == mx || bz[pz].y == my)
        {
            used[bz[pz].idx] = 1;
            continue;
        }

        cout << mx + my + mz << endl;
        return;
    }

    cout << -1 << endl;
}

int main()
{
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 3 ms 7252 KB Output is correct
12 Correct 3 ms 7252 KB Output is correct
13 Correct 3 ms 7276 KB Output is correct
14 Correct 4 ms 7356 KB Output is correct
15 Correct 3 ms 7344 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7364 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 3 ms 7252 KB Output is correct
20 Correct 4 ms 7352 KB Output is correct
21 Correct 3 ms 7252 KB Output is correct
22 Correct 4 ms 7252 KB Output is correct
23 Correct 4 ms 7252 KB Output is correct
24 Correct 4 ms 7252 KB Output is correct
25 Correct 4 ms 7352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 3 ms 7252 KB Output is correct
12 Correct 3 ms 7252 KB Output is correct
13 Correct 3 ms 7276 KB Output is correct
14 Correct 4 ms 7356 KB Output is correct
15 Correct 3 ms 7344 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7364 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 3 ms 7252 KB Output is correct
20 Correct 4 ms 7352 KB Output is correct
21 Correct 3 ms 7252 KB Output is correct
22 Correct 4 ms 7252 KB Output is correct
23 Correct 4 ms 7252 KB Output is correct
24 Correct 4 ms 7252 KB Output is correct
25 Correct 4 ms 7352 KB Output is correct
26 Correct 7 ms 7460 KB Output is correct
27 Correct 7 ms 7364 KB Output is correct
28 Correct 7 ms 7364 KB Output is correct
29 Correct 7 ms 7368 KB Output is correct
30 Correct 7 ms 7388 KB Output is correct
31 Correct 6 ms 7364 KB Output is correct
32 Correct 6 ms 7400 KB Output is correct
33 Correct 7 ms 7452 KB Output is correct
34 Correct 8 ms 7448 KB Output is correct
35 Correct 4 ms 7368 KB Output is correct
36 Correct 4 ms 7252 KB Output is correct
37 Correct 6 ms 7380 KB Output is correct
38 Correct 10 ms 7368 KB Output is correct
39 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7272 KB Output is correct
7 Correct 5 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 3 ms 7252 KB Output is correct
11 Correct 64 ms 7332 KB Output is correct
12 Correct 46 ms 7728 KB Output is correct
13 Correct 52 ms 8440 KB Output is correct
14 Correct 70 ms 8720 KB Output is correct
15 Correct 65 ms 8692 KB Output is correct
16 Correct 67 ms 8780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7272 KB Output is correct
7 Correct 5 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 3 ms 7252 KB Output is correct
11 Correct 64 ms 7332 KB Output is correct
12 Correct 46 ms 7728 KB Output is correct
13 Correct 52 ms 8440 KB Output is correct
14 Correct 70 ms 8720 KB Output is correct
15 Correct 65 ms 8692 KB Output is correct
16 Correct 67 ms 8780 KB Output is correct
17 Correct 3 ms 7352 KB Output is correct
18 Correct 3 ms 7252 KB Output is correct
19 Correct 3 ms 7356 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 5 ms 7364 KB Output is correct
22 Correct 75 ms 8396 KB Output is correct
23 Correct 71 ms 8732 KB Output is correct
24 Correct 55 ms 8524 KB Output is correct
25 Correct 83 ms 8988 KB Output is correct
26 Correct 71 ms 8844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7272 KB Output is correct
7 Correct 5 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 3 ms 7252 KB Output is correct
11 Correct 64 ms 7332 KB Output is correct
12 Correct 46 ms 7728 KB Output is correct
13 Correct 52 ms 8440 KB Output is correct
14 Correct 70 ms 8720 KB Output is correct
15 Correct 65 ms 8692 KB Output is correct
16 Correct 67 ms 8780 KB Output is correct
17 Correct 3 ms 7352 KB Output is correct
18 Correct 3 ms 7252 KB Output is correct
19 Correct 3 ms 7356 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 5 ms 7364 KB Output is correct
22 Correct 75 ms 8396 KB Output is correct
23 Correct 71 ms 8732 KB Output is correct
24 Correct 55 ms 8524 KB Output is correct
25 Correct 83 ms 8988 KB Output is correct
26 Correct 71 ms 8844 KB Output is correct
27 Correct 3 ms 7356 KB Output is correct
28 Correct 4 ms 7352 KB Output is correct
29 Correct 3 ms 7252 KB Output is correct
30 Correct 4 ms 7356 KB Output is correct
31 Correct 6 ms 7364 KB Output is correct
32 Correct 4 ms 7364 KB Output is correct
33 Correct 4 ms 7360 KB Output is correct
34 Correct 91 ms 8740 KB Output is correct
35 Correct 103 ms 9248 KB Output is correct
36 Correct 92 ms 9372 KB Output is correct
37 Correct 97 ms 9516 KB Output is correct
38 Correct 104 ms 9364 KB Output is correct
39 Correct 51 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7272 KB Output is correct
7 Correct 5 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 3 ms 7252 KB Output is correct
11 Correct 64 ms 7332 KB Output is correct
12 Correct 46 ms 7728 KB Output is correct
13 Correct 52 ms 8440 KB Output is correct
14 Correct 70 ms 8720 KB Output is correct
15 Correct 65 ms 8692 KB Output is correct
16 Correct 67 ms 8780 KB Output is correct
17 Correct 3 ms 7352 KB Output is correct
18 Correct 3 ms 7252 KB Output is correct
19 Correct 3 ms 7356 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 5 ms 7364 KB Output is correct
22 Correct 75 ms 8396 KB Output is correct
23 Correct 71 ms 8732 KB Output is correct
24 Correct 55 ms 8524 KB Output is correct
25 Correct 83 ms 8988 KB Output is correct
26 Correct 71 ms 8844 KB Output is correct
27 Correct 3 ms 7356 KB Output is correct
28 Correct 4 ms 7352 KB Output is correct
29 Correct 3 ms 7252 KB Output is correct
30 Correct 4 ms 7356 KB Output is correct
31 Correct 6 ms 7364 KB Output is correct
32 Correct 4 ms 7364 KB Output is correct
33 Correct 4 ms 7360 KB Output is correct
34 Correct 91 ms 8740 KB Output is correct
35 Correct 103 ms 9248 KB Output is correct
36 Correct 92 ms 9372 KB Output is correct
37 Correct 97 ms 9516 KB Output is correct
38 Correct 104 ms 9364 KB Output is correct
39 Correct 51 ms 8584 KB Output is correct
40 Correct 5 ms 7380 KB Output is correct
41 Correct 6 ms 7396 KB Output is correct
42 Correct 6 ms 7368 KB Output is correct
43 Correct 7 ms 7368 KB Output is correct
44 Correct 109 ms 9408 KB Output is correct
45 Correct 114 ms 9968 KB Output is correct
46 Correct 120 ms 9888 KB Output is correct
47 Correct 118 ms 9992 KB Output is correct
48 Correct 96 ms 9872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 3 ms 7252 KB Output is correct
12 Correct 3 ms 7252 KB Output is correct
13 Correct 3 ms 7276 KB Output is correct
14 Correct 4 ms 7356 KB Output is correct
15 Correct 3 ms 7344 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7364 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 3 ms 7252 KB Output is correct
20 Correct 4 ms 7352 KB Output is correct
21 Correct 3 ms 7252 KB Output is correct
22 Correct 4 ms 7252 KB Output is correct
23 Correct 4 ms 7252 KB Output is correct
24 Correct 4 ms 7252 KB Output is correct
25 Correct 4 ms 7352 KB Output is correct
26 Correct 7 ms 7460 KB Output is correct
27 Correct 7 ms 7364 KB Output is correct
28 Correct 7 ms 7364 KB Output is correct
29 Correct 7 ms 7368 KB Output is correct
30 Correct 7 ms 7388 KB Output is correct
31 Correct 6 ms 7364 KB Output is correct
32 Correct 6 ms 7400 KB Output is correct
33 Correct 7 ms 7452 KB Output is correct
34 Correct 8 ms 7448 KB Output is correct
35 Correct 4 ms 7368 KB Output is correct
36 Correct 4 ms 7252 KB Output is correct
37 Correct 6 ms 7380 KB Output is correct
38 Correct 10 ms 7368 KB Output is correct
39 Correct 4 ms 7252 KB Output is correct
40 Correct 3 ms 7252 KB Output is correct
41 Correct 4 ms 7252 KB Output is correct
42 Correct 3 ms 7252 KB Output is correct
43 Correct 4 ms 7252 KB Output is correct
44 Correct 3 ms 7252 KB Output is correct
45 Correct 3 ms 7272 KB Output is correct
46 Correct 5 ms 7252 KB Output is correct
47 Correct 4 ms 7252 KB Output is correct
48 Correct 4 ms 7252 KB Output is correct
49 Correct 3 ms 7252 KB Output is correct
50 Correct 64 ms 7332 KB Output is correct
51 Correct 46 ms 7728 KB Output is correct
52 Correct 52 ms 8440 KB Output is correct
53 Correct 70 ms 8720 KB Output is correct
54 Correct 65 ms 8692 KB Output is correct
55 Correct 67 ms 8780 KB Output is correct
56 Correct 3 ms 7352 KB Output is correct
57 Correct 3 ms 7252 KB Output is correct
58 Correct 3 ms 7356 KB Output is correct
59 Correct 4 ms 7252 KB Output is correct
60 Correct 5 ms 7364 KB Output is correct
61 Correct 75 ms 8396 KB Output is correct
62 Correct 71 ms 8732 KB Output is correct
63 Correct 55 ms 8524 KB Output is correct
64 Correct 83 ms 8988 KB Output is correct
65 Correct 71 ms 8844 KB Output is correct
66 Correct 3 ms 7356 KB Output is correct
67 Correct 4 ms 7352 KB Output is correct
68 Correct 3 ms 7252 KB Output is correct
69 Correct 4 ms 7356 KB Output is correct
70 Correct 6 ms 7364 KB Output is correct
71 Correct 4 ms 7364 KB Output is correct
72 Correct 4 ms 7360 KB Output is correct
73 Correct 91 ms 8740 KB Output is correct
74 Correct 103 ms 9248 KB Output is correct
75 Correct 92 ms 9372 KB Output is correct
76 Correct 97 ms 9516 KB Output is correct
77 Correct 104 ms 9364 KB Output is correct
78 Correct 51 ms 8584 KB Output is correct
79 Correct 5 ms 7380 KB Output is correct
80 Correct 6 ms 7396 KB Output is correct
81 Correct 6 ms 7368 KB Output is correct
82 Correct 7 ms 7368 KB Output is correct
83 Correct 109 ms 9408 KB Output is correct
84 Correct 114 ms 9968 KB Output is correct
85 Correct 120 ms 9888 KB Output is correct
86 Correct 118 ms 9992 KB Output is correct
87 Correct 96 ms 9872 KB Output is correct
88 Correct 156 ms 11236 KB Output is correct
89 Correct 158 ms 11796 KB Output is correct
90 Correct 159 ms 11748 KB Output is correct
91 Correct 181 ms 11704 KB Output is correct
92 Correct 127 ms 10272 KB Output is correct
93 Correct 134 ms 10652 KB Output is correct
94 Correct 138 ms 10516 KB Output is correct
95 Correct 136 ms 11664 KB Output is correct
96 Correct 157 ms 11752 KB Output is correct
97 Correct 163 ms 11840 KB Output is correct
98 Correct 106 ms 9764 KB Output is correct
99 Correct 154 ms 10396 KB Output is correct