답안 #550621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
550621 2022-04-18T17:14:17 Z SorahISA Team Contest (JOI22_team) C++17
100 / 100
115 ms 12512 KB
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define double long double
using pii = pair<int, int>;
template <typename T>
using Prior = std::priority_queue<T>;
template <typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

// #define X first
// #define Y second
#define eb emplace_back
#define ef push_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

#ifdef local
#define fastIO() void()
#define debug(...) \
    cerr << "\u001b[33m" << "At [" << __FUNCTION__ << "], line " << __LINE__ << ", ",\
    cerr << "(" << #__VA_ARGS__ << ") = ", _do(__VA_ARGS__), cerr << "\u001b[0m"
template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif

template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}

void solve() {
    int N; cin >> N;
    
    vector<tuple<int, int, int>> skill(N);
    for (auto &[X, Y, Z] : skill) cin >> X >> Y >> Z;
    
    deque<int> id_x(N), id_y, id_z;
    iota(ALL(id_x), 0), id_y = id_z = id_x;
    sort(ALL(id_x), [&](int x, int y) {return get<0>(skill[x]) > get<0>(skill[y]);});
    sort(ALL(id_y), [&](int x, int y) {return get<1>(skill[x]) > get<1>(skill[y]);});
    sort(ALL(id_z), [&](int x, int y) {return get<2>(skill[x]) > get<2>(skill[y]);});
    
    vector<int> alive(N, 1);
    while (true) {
        while (SZ(id_x) and !alive[id_x[0]]) id_x.pf();
        while (SZ(id_y) and !alive[id_y[0]]) id_y.pf();
        while (SZ(id_z) and !alive[id_z[0]]) id_z.pf();
        if (!SZ(id_x) or !SZ(id_y) or !SZ(id_z)) return cout << -1 << "\n", void();
        
        auto &[xx, xy, xz] = skill[id_x[0]];
        auto &[yx, yy, yz] = skill[id_y[0]];
        auto &[zx, zy, zz] = skill[id_z[0]];
        int flag = 0;
        
        if (xy == yy or xz == zz) alive[id_x[0]] = 0, flag = 1;
        if (yx == xx or yz == zz) alive[id_y[0]] = 0, flag = 1;
        if (zx == xx or zy == yy) alive[id_z[0]] = 0, flag = 1;
        
        if (flag) continue;
        return cout << xx + yy + zz << "\n", void();
    }
}

int32_t main() {
    fastIO();
    
    int t = 1; // cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        solve();
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 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 340 KB Output is correct
17 Correct 1 ms 340 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 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 340 KB Output is correct
17 Correct 1 ms 340 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 552 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 588 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 43 ms 9160 KB Output is correct
12 Correct 31 ms 6284 KB Output is correct
13 Correct 36 ms 7792 KB Output is correct
14 Correct 53 ms 9548 KB Output is correct
15 Correct 46 ms 9124 KB Output is correct
16 Correct 42 ms 9284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 43 ms 9160 KB Output is correct
12 Correct 31 ms 6284 KB Output is correct
13 Correct 36 ms 7792 KB Output is correct
14 Correct 53 ms 9548 KB Output is correct
15 Correct 46 ms 9124 KB Output is correct
16 Correct 42 ms 9284 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 60 ms 9428 KB Output is correct
23 Correct 49 ms 9208 KB Output is correct
24 Correct 46 ms 6932 KB Output is correct
25 Correct 69 ms 9708 KB Output is correct
26 Correct 46 ms 9548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 43 ms 9160 KB Output is correct
12 Correct 31 ms 6284 KB Output is correct
13 Correct 36 ms 7792 KB Output is correct
14 Correct 53 ms 9548 KB Output is correct
15 Correct 46 ms 9124 KB Output is correct
16 Correct 42 ms 9284 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 60 ms 9428 KB Output is correct
23 Correct 49 ms 9208 KB Output is correct
24 Correct 46 ms 6932 KB Output is correct
25 Correct 69 ms 9708 KB Output is correct
26 Correct 46 ms 9548 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 320 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 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 63 ms 9508 KB Output is correct
35 Correct 64 ms 8780 KB Output is correct
36 Correct 70 ms 9660 KB Output is correct
37 Correct 76 ms 10156 KB Output is correct
38 Correct 53 ms 9580 KB Output is correct
39 Correct 35 ms 5964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 43 ms 9160 KB Output is correct
12 Correct 31 ms 6284 KB Output is correct
13 Correct 36 ms 7792 KB Output is correct
14 Correct 53 ms 9548 KB Output is correct
15 Correct 46 ms 9124 KB Output is correct
16 Correct 42 ms 9284 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 60 ms 9428 KB Output is correct
23 Correct 49 ms 9208 KB Output is correct
24 Correct 46 ms 6932 KB Output is correct
25 Correct 69 ms 9708 KB Output is correct
26 Correct 46 ms 9548 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 320 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 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 63 ms 9508 KB Output is correct
35 Correct 64 ms 8780 KB Output is correct
36 Correct 70 ms 9660 KB Output is correct
37 Correct 76 ms 10156 KB Output is correct
38 Correct 53 ms 9580 KB Output is correct
39 Correct 35 ms 5964 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 2 ms 468 KB Output is correct
44 Correct 86 ms 10688 KB Output is correct
45 Correct 87 ms 10512 KB Output is correct
46 Correct 87 ms 10244 KB Output is correct
47 Correct 90 ms 10792 KB Output is correct
48 Correct 62 ms 10660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 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 340 KB Output is correct
17 Correct 1 ms 340 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 552 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 588 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 43 ms 9160 KB Output is correct
51 Correct 31 ms 6284 KB Output is correct
52 Correct 36 ms 7792 KB Output is correct
53 Correct 53 ms 9548 KB Output is correct
54 Correct 46 ms 9124 KB Output is correct
55 Correct 42 ms 9284 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 320 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 60 ms 9428 KB Output is correct
62 Correct 49 ms 9208 KB Output is correct
63 Correct 46 ms 6932 KB Output is correct
64 Correct 69 ms 9708 KB Output is correct
65 Correct 46 ms 9548 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 320 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 328 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 63 ms 9508 KB Output is correct
74 Correct 64 ms 8780 KB Output is correct
75 Correct 70 ms 9660 KB Output is correct
76 Correct 76 ms 10156 KB Output is correct
77 Correct 53 ms 9580 KB Output is correct
78 Correct 35 ms 5964 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 2 ms 468 KB Output is correct
83 Correct 86 ms 10688 KB Output is correct
84 Correct 87 ms 10512 KB Output is correct
85 Correct 87 ms 10244 KB Output is correct
86 Correct 90 ms 10792 KB Output is correct
87 Correct 62 ms 10660 KB Output is correct
88 Correct 99 ms 11196 KB Output is correct
89 Correct 107 ms 10868 KB Output is correct
90 Correct 102 ms 12512 KB Output is correct
91 Correct 115 ms 10200 KB Output is correct
92 Correct 92 ms 10300 KB Output is correct
93 Correct 107 ms 11440 KB Output is correct
94 Correct 98 ms 11288 KB Output is correct
95 Correct 79 ms 12364 KB Output is correct
96 Correct 113 ms 12296 KB Output is correct
97 Correct 66 ms 11220 KB Output is correct
98 Correct 51 ms 11108 KB Output is correct
99 Correct 57 ms 11088 KB Output is correct