답안 #892503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892503 2023-12-25T12:40:57 Z viwlesxq Team Contest (JOI22_team) C++17
100 / 100
89 ms 11712 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
    return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
    return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 998244353;

struct person {
    int x, y, z;
};

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    person v[n];
    vector<int> a, b, c;
    for (int i = 0; i < n; ++i) {
        cin >> v[i].x >> v[i].y >> v[i].z;
        a.push_back(i), b.push_back(i), c.push_back(i);
    }
    sort(all(a), [&](int &i, int &j) {
        return v[i].x < v[j].x;
    });
    sort(all(b), [&](int &i, int &j) {
        return v[i].y < v[j].y;
    });
    sort(all(c), [&](int &i, int &j) {
        return v[i].z < v[j].z;
    });
    while (!a.empty() && !b.empty() && !c.empty()) {
        if (v[a.back()].y >= v[b.back()].y || v[a.back()].z >= v[c.back()].z) {
            a.pop_back();
            continue;
        }
        if (v[b.back()].x >= v[a.back()].x || v[b.back()].z >= v[c.back()].z) {
            b.pop_back();
            continue;
        }
        if (v[c.back()].x >= v[a.back()].x || v[c.back()].y >= v[b.back()].y) {
            c.pop_back();
            continue;
        }
        if (a.back() == b.back()) {
            if (v[a.back()].x >= v[b.back()].y) {
                b.pop_back();
            } else {
                a.pop_back();
            }
        } else if (b.back() == c.back()) {
            if (v[b.back()].y >= v[c.back()].z) {
                c.pop_back();
            } else {
                b.pop_back();
            }
        } else if (a.back() == c.back()) {
            if (v[a.back()].x >= v[c.back()].z) {
                c.pop_back();
            } else {
                a.pop_back();
            }
        } else {
            cout << v[a.back()].x + v[b.back()].y + v[c.back()].z;
            return 0;
        }
    }
    cout << -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 448 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 448 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 788 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 852 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 728 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 664 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 38 ms 8912 KB Output is correct
12 Correct 24 ms 5824 KB Output is correct
13 Correct 25 ms 7108 KB Output is correct
14 Correct 37 ms 8900 KB Output is correct
15 Correct 32 ms 8900 KB Output is correct
16 Correct 28 ms 8900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 38 ms 8912 KB Output is correct
12 Correct 24 ms 5824 KB Output is correct
13 Correct 25 ms 7108 KB Output is correct
14 Correct 37 ms 8900 KB Output is correct
15 Correct 32 ms 8900 KB Output is correct
16 Correct 28 ms 8900 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 43 ms 9156 KB Output is correct
23 Correct 38 ms 8892 KB Output is correct
24 Correct 30 ms 6336 KB Output is correct
25 Correct 43 ms 9148 KB Output is correct
26 Correct 34 ms 9156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 38 ms 8912 KB Output is correct
12 Correct 24 ms 5824 KB Output is correct
13 Correct 25 ms 7108 KB Output is correct
14 Correct 37 ms 8900 KB Output is correct
15 Correct 32 ms 8900 KB Output is correct
16 Correct 28 ms 8900 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 43 ms 9156 KB Output is correct
23 Correct 38 ms 8892 KB Output is correct
24 Correct 30 ms 6336 KB Output is correct
25 Correct 43 ms 9148 KB Output is correct
26 Correct 34 ms 9156 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 49 ms 9404 KB Output is correct
35 Correct 48 ms 9148 KB Output is correct
36 Correct 54 ms 9744 KB Output is correct
37 Correct 53 ms 9792 KB Output is correct
38 Correct 37 ms 9664 KB Output is correct
39 Correct 21 ms 5584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 38 ms 8912 KB Output is correct
12 Correct 24 ms 5824 KB Output is correct
13 Correct 25 ms 7108 KB Output is correct
14 Correct 37 ms 8900 KB Output is correct
15 Correct 32 ms 8900 KB Output is correct
16 Correct 28 ms 8900 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 43 ms 9156 KB Output is correct
23 Correct 38 ms 8892 KB Output is correct
24 Correct 30 ms 6336 KB Output is correct
25 Correct 43 ms 9148 KB Output is correct
26 Correct 34 ms 9156 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 49 ms 9404 KB Output is correct
35 Correct 48 ms 9148 KB Output is correct
36 Correct 54 ms 9744 KB Output is correct
37 Correct 53 ms 9792 KB Output is correct
38 Correct 37 ms 9664 KB Output is correct
39 Correct 21 ms 5584 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 62 ms 10164 KB Output is correct
45 Correct 65 ms 10172 KB Output is correct
46 Correct 63 ms 11188 KB Output is correct
47 Correct 64 ms 10172 KB Output is correct
48 Correct 47 ms 10312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 448 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 788 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 852 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 728 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 664 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 600 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 38 ms 8912 KB Output is correct
51 Correct 24 ms 5824 KB Output is correct
52 Correct 25 ms 7108 KB Output is correct
53 Correct 37 ms 8900 KB Output is correct
54 Correct 32 ms 8900 KB Output is correct
55 Correct 28 ms 8900 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 43 ms 9156 KB Output is correct
62 Correct 38 ms 8892 KB Output is correct
63 Correct 30 ms 6336 KB Output is correct
64 Correct 43 ms 9148 KB Output is correct
65 Correct 34 ms 9156 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 2 ms 604 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 464 KB Output is correct
73 Correct 49 ms 9404 KB Output is correct
74 Correct 48 ms 9148 KB Output is correct
75 Correct 54 ms 9744 KB Output is correct
76 Correct 53 ms 9792 KB Output is correct
77 Correct 37 ms 9664 KB Output is correct
78 Correct 21 ms 5584 KB Output is correct
79 Correct 2 ms 604 KB Output is correct
80 Correct 2 ms 604 KB Output is correct
81 Correct 2 ms 604 KB Output is correct
82 Correct 2 ms 604 KB Output is correct
83 Correct 62 ms 10164 KB Output is correct
84 Correct 65 ms 10172 KB Output is correct
85 Correct 63 ms 11188 KB Output is correct
86 Correct 64 ms 10172 KB Output is correct
87 Correct 47 ms 10312 KB Output is correct
88 Correct 77 ms 11708 KB Output is correct
89 Correct 80 ms 11560 KB Output is correct
90 Correct 84 ms 11608 KB Output is correct
91 Correct 82 ms 11704 KB Output is correct
92 Correct 72 ms 10276 KB Output is correct
93 Correct 78 ms 10684 KB Output is correct
94 Correct 75 ms 10436 KB Output is correct
95 Correct 52 ms 11444 KB Output is correct
96 Correct 85 ms 11712 KB Output is correct
97 Correct 43 ms 11704 KB Output is correct
98 Correct 39 ms 10436 KB Output is correct
99 Correct 89 ms 10432 KB Output is correct