Submission #586151

# Submission time Handle Problem Language Result Execution time Memory
586151 2022-06-30T02:40:52 Z nota Team Contest (JOI22_team) C++14
100 / 100
114 ms 7936 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
using namespace std;
const int maxN = 150001;
int n;
int x[maxN], y[maxN], z[maxN];

void Input()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> x[i] >> y[i] >> z[i];
}

int idx[maxN], idy[maxN], idz[maxN];
bool flag[maxN];

bool ss1(int a, int b)
{
    return x[a] < x[b];
}

bool ss2(int a, int b)
{
    return y[a] < y[b];
}

bool ss3(int a, int b)
{
    return z[a] < z[b];
}

void Solve()
{
    for(int i = 1; i <= n; i++)
    {
        idx[i] = i;
        idy[i] = i;
        idz[i] = i;
    }
    sort(idx + 1, idx + 1 + n, ss1);
    sort(idy + 1, idy + 1 + n, ss2);
    sort(idz + 1, idz + 1 + n, ss3);
    int resx = n, resy = n, resz = n;
    while(resx != 0 && resy != 0 && resz != 0)
    {
        int tmpx = x[idx[resx]], tmpy = y[idy[resy]], tmpz = z[idz[resz]];
        int xx = (y[idx[resx]] == tmpy) + (z[idx[resx]] == tmpz);
        int yy = (z[idy[resy]] == tmpz) + (x[idy[resy]] == tmpx);
        int zz = (x[idz[resz]] == tmpx) + (y[idz[resz]] == tmpy);
        if(xx == 0 && yy == 0 && zz == 0)
        {
            cout << tmpx + tmpy + tmpz;
            return;
        }
        if(xx > 0)
        {
            flag[idx[resx]] = true;
            goto hi;
        }
        if(yy > 0)
        {
            flag[idy[resy]] = true;
            goto hi;
        }
        if(zz > 0)
        {
            flag[idz[resz]] = true;
            goto hi;
        }
        hi:
        while(resx != 0 && flag[idx[resx]])
            resx--;
        while(resy != 0 && flag[idy[resy]])
            resy--;
        while(resz != 0 && flag[idz[resz]])
            resz--;
    }
    cout << -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Input();
    Solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 476 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 412 KB Output is correct
33 Correct 2 ms 452 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 3 ms 472 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 41 ms 3828 KB Output is correct
12 Correct 28 ms 2772 KB Output is correct
13 Correct 36 ms 4008 KB Output is correct
14 Correct 47 ms 4944 KB Output is correct
15 Correct 37 ms 4852 KB Output is correct
16 Correct 35 ms 4820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 41 ms 3828 KB Output is correct
12 Correct 28 ms 2772 KB Output is correct
13 Correct 36 ms 4008 KB Output is correct
14 Correct 47 ms 4944 KB Output is correct
15 Correct 37 ms 4852 KB Output is correct
16 Correct 35 ms 4820 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 50 ms 4952 KB Output is correct
23 Correct 46 ms 4812 KB Output is correct
24 Correct 35 ms 3712 KB Output is correct
25 Correct 53 ms 5100 KB Output is correct
26 Correct 39 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 41 ms 3828 KB Output is correct
12 Correct 28 ms 2772 KB Output is correct
13 Correct 36 ms 4008 KB Output is correct
14 Correct 47 ms 4944 KB Output is correct
15 Correct 37 ms 4852 KB Output is correct
16 Correct 35 ms 4820 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 50 ms 4952 KB Output is correct
23 Correct 46 ms 4812 KB Output is correct
24 Correct 35 ms 3712 KB Output is correct
25 Correct 53 ms 5100 KB Output is correct
26 Correct 39 ms 4956 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 63 ms 5276 KB Output is correct
35 Correct 56 ms 4988 KB Output is correct
36 Correct 61 ms 5484 KB Output is correct
37 Correct 61 ms 5636 KB Output is correct
38 Correct 56 ms 5368 KB Output is correct
39 Correct 26 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 41 ms 3828 KB Output is correct
12 Correct 28 ms 2772 KB Output is correct
13 Correct 36 ms 4008 KB Output is correct
14 Correct 47 ms 4944 KB Output is correct
15 Correct 37 ms 4852 KB Output is correct
16 Correct 35 ms 4820 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 50 ms 4952 KB Output is correct
23 Correct 46 ms 4812 KB Output is correct
24 Correct 35 ms 3712 KB Output is correct
25 Correct 53 ms 5100 KB Output is correct
26 Correct 39 ms 4956 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 63 ms 5276 KB Output is correct
35 Correct 56 ms 4988 KB Output is correct
36 Correct 61 ms 5484 KB Output is correct
37 Correct 61 ms 5636 KB Output is correct
38 Correct 56 ms 5368 KB Output is correct
39 Correct 26 ms 3408 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 3 ms 508 KB Output is correct
44 Correct 77 ms 5908 KB Output is correct
45 Correct 74 ms 6012 KB Output is correct
46 Correct 74 ms 6020 KB Output is correct
47 Correct 74 ms 6000 KB Output is correct
48 Correct 57 ms 5960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 476 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 412 KB Output is correct
33 Correct 2 ms 452 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 3 ms 472 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 41 ms 3828 KB Output is correct
51 Correct 28 ms 2772 KB Output is correct
52 Correct 36 ms 4008 KB Output is correct
53 Correct 47 ms 4944 KB Output is correct
54 Correct 37 ms 4852 KB Output is correct
55 Correct 35 ms 4820 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 328 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 50 ms 4952 KB Output is correct
62 Correct 46 ms 4812 KB Output is correct
63 Correct 35 ms 3712 KB Output is correct
64 Correct 53 ms 5100 KB Output is correct
65 Correct 39 ms 4956 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 332 KB Output is correct
68 Correct 1 ms 336 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 63 ms 5276 KB Output is correct
74 Correct 56 ms 4988 KB Output is correct
75 Correct 61 ms 5484 KB Output is correct
76 Correct 61 ms 5636 KB Output is correct
77 Correct 56 ms 5368 KB Output is correct
78 Correct 26 ms 3408 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 2 ms 468 KB Output is correct
81 Correct 2 ms 468 KB Output is correct
82 Correct 3 ms 508 KB Output is correct
83 Correct 77 ms 5908 KB Output is correct
84 Correct 74 ms 6012 KB Output is correct
85 Correct 74 ms 6020 KB Output is correct
86 Correct 74 ms 6000 KB Output is correct
87 Correct 57 ms 5960 KB Output is correct
88 Correct 91 ms 7744 KB Output is correct
89 Correct 114 ms 7860 KB Output is correct
90 Correct 93 ms 7800 KB Output is correct
91 Correct 105 ms 7744 KB Output is correct
92 Correct 89 ms 6392 KB Output is correct
93 Correct 94 ms 6716 KB Output is correct
94 Correct 86 ms 6476 KB Output is correct
95 Correct 67 ms 7652 KB Output is correct
96 Correct 95 ms 7844 KB Output is correct
97 Correct 56 ms 7936 KB Output is correct
98 Correct 51 ms 6368 KB Output is correct
99 Correct 108 ms 6500 KB Output is correct