답안 #1029782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029782 2024-07-21T10:23:07 Z NeroZein Team Contest (JOI22_team) C++17
100 / 100
70 ms 8124 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> x(n), y(n), z(n); 
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> z[i];
  }
  vector<int> ptx(n), pty(n), ptz(n);
  iota(ptx.begin(), ptx.end(), 0);
  iota(pty.begin(), pty.end(), 0);
  iota(ptz.begin(), ptz.end(), 0);
  sort(ptx.begin(), ptx.end(), [&](int i, int j) {
    return x[i] < x[j];
  });
  sort(pty.begin(), pty.end(), [&](int i, int j) {
    return y[i] < y[j];
  });
  sort(ptz.begin(), ptz.end(), [&](int i, int j) {
    return z[i] < z[j];
  });
  int tx = n - 1, ty = n - 1, tz = n - 1;
  vector<bool> used(n); 
  while (tx >= 0 && ty >= 0 && tz >= 0) {
    int mx = x[ptx[tx]], my = y[pty[ty]], mz = z[ptz[tz]];
    int cntx = 1 + (y[ptx[tx]] == my) + (z[ptx[tx]] == mz);
    int cnty = 1 + (x[pty[ty]] == mx) + (z[pty[ty]] == mz);
    int cntz = 1 + (x[ptz[tz]] == mx) + (y[ptz[tz]] == my);
    if (cntx >= 2) {
      used[ptx[tx]] = true;
      tx--; 
    } else if (cnty >= 2) {
      used[pty[ty]] = true;
      ty--;
    } else if (cntz >= 2) {
      used[ptz[tz]] = true;
      tz--;
    } else {
      cout << mx + my + mz << '\n';
      return 0; 
    }
    while (tx >= 0 && used[ptx[tx]]) tx--;
    while (ty >= 0 && used[pty[ty]]) ty--;
    while (tz >= 0 && used[ptz[tz]]) tz--;
  }
  cout << -1 << '\n';
  return 0;
}
# 결과 실행 시간 메모리 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 348 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 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 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 348 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 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 608 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 472 KB Output is correct
38 Correct 2 ms 600 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 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 25 ms 3928 KB Output is correct
12 Correct 18 ms 2652 KB Output is correct
13 Correct 19 ms 3876 KB Output is correct
14 Correct 28 ms 4700 KB Output is correct
15 Correct 25 ms 4688 KB Output is correct
16 Correct 22 ms 4712 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 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 25 ms 3928 KB Output is correct
12 Correct 18 ms 2652 KB Output is correct
13 Correct 19 ms 3876 KB Output is correct
14 Correct 28 ms 4700 KB Output is correct
15 Correct 25 ms 4688 KB Output is correct
16 Correct 22 ms 4712 KB Output is correct
17 Correct 0 ms 348 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 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 33 ms 5128 KB Output is correct
23 Correct 30 ms 4604 KB Output is correct
24 Correct 24 ms 3676 KB Output is correct
25 Correct 34 ms 5132 KB Output is correct
26 Correct 26 ms 4948 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 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 25 ms 3928 KB Output is correct
12 Correct 18 ms 2652 KB Output is correct
13 Correct 19 ms 3876 KB Output is correct
14 Correct 28 ms 4700 KB Output is correct
15 Correct 25 ms 4688 KB Output is correct
16 Correct 22 ms 4712 KB Output is correct
17 Correct 0 ms 348 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 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 33 ms 5128 KB Output is correct
23 Correct 30 ms 4604 KB Output is correct
24 Correct 24 ms 3676 KB Output is correct
25 Correct 34 ms 5132 KB Output is correct
26 Correct 26 ms 4948 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 39 ms 5336 KB Output is correct
35 Correct 38 ms 4992 KB Output is correct
36 Correct 41 ms 5528 KB Output is correct
37 Correct 43 ms 5464 KB Output is correct
38 Correct 31 ms 5468 KB Output is correct
39 Correct 17 ms 3416 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 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 25 ms 3928 KB Output is correct
12 Correct 18 ms 2652 KB Output is correct
13 Correct 19 ms 3876 KB Output is correct
14 Correct 28 ms 4700 KB Output is correct
15 Correct 25 ms 4688 KB Output is correct
16 Correct 22 ms 4712 KB Output is correct
17 Correct 0 ms 348 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 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 33 ms 5128 KB Output is correct
23 Correct 30 ms 4604 KB Output is correct
24 Correct 24 ms 3676 KB Output is correct
25 Correct 34 ms 5132 KB Output is correct
26 Correct 26 ms 4948 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 39 ms 5336 KB Output is correct
35 Correct 38 ms 4992 KB Output is correct
36 Correct 41 ms 5528 KB Output is correct
37 Correct 43 ms 5464 KB Output is correct
38 Correct 31 ms 5468 KB Output is correct
39 Correct 17 ms 3416 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 52 ms 6056 KB Output is correct
45 Correct 52 ms 5932 KB Output is correct
46 Correct 53 ms 5976 KB Output is correct
47 Correct 53 ms 5980 KB Output is correct
48 Correct 34 ms 5968 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 348 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 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 608 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 472 KB Output is correct
38 Correct 2 ms 600 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 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 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 25 ms 3928 KB Output is correct
51 Correct 18 ms 2652 KB Output is correct
52 Correct 19 ms 3876 KB Output is correct
53 Correct 28 ms 4700 KB Output is correct
54 Correct 25 ms 4688 KB Output is correct
55 Correct 22 ms 4712 KB Output is correct
56 Correct 0 ms 348 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 344 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 33 ms 5128 KB Output is correct
62 Correct 30 ms 4604 KB Output is correct
63 Correct 24 ms 3676 KB Output is correct
64 Correct 34 ms 5132 KB Output is correct
65 Correct 26 ms 4948 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 39 ms 5336 KB Output is correct
74 Correct 38 ms 4992 KB Output is correct
75 Correct 41 ms 5528 KB Output is correct
76 Correct 43 ms 5464 KB Output is correct
77 Correct 31 ms 5468 KB Output is correct
78 Correct 17 ms 3416 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 2 ms 348 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 2 ms 348 KB Output is correct
83 Correct 52 ms 6056 KB Output is correct
84 Correct 52 ms 5932 KB Output is correct
85 Correct 53 ms 5976 KB Output is correct
86 Correct 53 ms 5980 KB Output is correct
87 Correct 34 ms 5968 KB Output is correct
88 Correct 63 ms 7764 KB Output is correct
89 Correct 70 ms 7772 KB Output is correct
90 Correct 66 ms 7840 KB Output is correct
91 Correct 70 ms 7860 KB Output is correct
92 Correct 70 ms 6416 KB Output is correct
93 Correct 64 ms 6776 KB Output is correct
94 Correct 62 ms 6444 KB Output is correct
95 Correct 43 ms 7788 KB Output is correct
96 Correct 69 ms 7844 KB Output is correct
97 Correct 41 ms 8124 KB Output is correct
98 Correct 30 ms 6480 KB Output is correct
99 Correct 62 ms 6484 KB Output is correct