Submission #597619

# Submission time Handle Problem Language Result Execution time Memory
597619 2022-07-16T12:10:42 Z MilosMilutinovic Team Contest (JOI22_team) C++14
100 / 100
387 ms 33604 KB
/**
 *    author:  wxhtzdy
 *    created: 16.07.2022 13:52:34
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  vector<set<pair<int, int>>> st(3);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      st[j].emplace(a[i][j], i);
    }
  }             
  vector<bool> is(n);
  while (!st[0].empty() && !st[1].empty() && !st[2].empty()) {
    bool ok = true;
    for (int i = 0; i < 3; i++) {
      int idx = prev(st[i].end())->second;
      for (int j = 0; j < 3; j++) {
        if (i == j) {
          continue;
        }   
        if (a[idx][j] >= a[prev(st[j].end())->second][j]) {
          ok = false;
          is[idx] = true;
        }
      }
    }
    if (ok) {     
      int ans = 0;
      for (int i = 0; i < 3; i++) {
        ans += prev(st[i].end())->first;
      }
      cout << ans << '\n';
      return 0;
    }               
    for (int i = 0; i < 3; i++) {
      while (!st[i].empty() && is[prev(st[i].end())->second]) {
        st[i].erase(prev(st[i].end()));
      }
    }
  }
  cout << -1 << '\n';                                  
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 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 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 264 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 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 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 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 264 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 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 1108 KB Output is correct
27 Correct 4 ms 1108 KB Output is correct
28 Correct 4 ms 1108 KB Output is correct
29 Correct 5 ms 1108 KB Output is correct
30 Correct 3 ms 848 KB Output is correct
31 Correct 4 ms 1048 KB Output is correct
32 Correct 5 ms 1132 KB Output is correct
33 Correct 4 ms 1108 KB Output is correct
34 Correct 5 ms 1104 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 1108 KB Output is correct
38 Correct 4 ms 1108 KB Output is correct
39 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 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 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 166 ms 30544 KB Output is correct
12 Correct 126 ms 20356 KB Output is correct
13 Correct 105 ms 25164 KB Output is correct
14 Correct 154 ms 30544 KB Output is correct
15 Correct 126 ms 30452 KB Output is correct
16 Correct 133 ms 30540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 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 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 166 ms 30544 KB Output is correct
12 Correct 126 ms 20356 KB Output is correct
13 Correct 105 ms 25164 KB Output is correct
14 Correct 154 ms 30544 KB Output is correct
15 Correct 126 ms 30452 KB Output is correct
16 Correct 133 ms 30540 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 186 ms 30716 KB Output is correct
23 Correct 190 ms 29844 KB Output is correct
24 Correct 136 ms 22236 KB Output is correct
25 Correct 225 ms 30680 KB Output is correct
26 Correct 136 ms 30664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 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 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 166 ms 30544 KB Output is correct
12 Correct 126 ms 20356 KB Output is correct
13 Correct 105 ms 25164 KB Output is correct
14 Correct 154 ms 30544 KB Output is correct
15 Correct 126 ms 30452 KB Output is correct
16 Correct 133 ms 30540 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 186 ms 30716 KB Output is correct
23 Correct 190 ms 29844 KB Output is correct
24 Correct 136 ms 22236 KB Output is correct
25 Correct 225 ms 30680 KB Output is correct
26 Correct 136 ms 30664 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 5 ms 1108 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 248 ms 29756 KB Output is correct
35 Correct 251 ms 28212 KB Output is correct
36 Correct 300 ms 31164 KB Output is correct
37 Correct 259 ms 31080 KB Output is correct
38 Correct 168 ms 30624 KB Output is correct
39 Correct 104 ms 18932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 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 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 166 ms 30544 KB Output is correct
12 Correct 126 ms 20356 KB Output is correct
13 Correct 105 ms 25164 KB Output is correct
14 Correct 154 ms 30544 KB Output is correct
15 Correct 126 ms 30452 KB Output is correct
16 Correct 133 ms 30540 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 186 ms 30716 KB Output is correct
23 Correct 190 ms 29844 KB Output is correct
24 Correct 136 ms 22236 KB Output is correct
25 Correct 225 ms 30680 KB Output is correct
26 Correct 136 ms 30664 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 5 ms 1108 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 248 ms 29756 KB Output is correct
35 Correct 251 ms 28212 KB Output is correct
36 Correct 300 ms 31164 KB Output is correct
37 Correct 259 ms 31080 KB Output is correct
38 Correct 168 ms 30624 KB Output is correct
39 Correct 104 ms 18932 KB Output is correct
40 Correct 4 ms 840 KB Output is correct
41 Correct 4 ms 1096 KB Output is correct
42 Correct 3 ms 1100 KB Output is correct
43 Correct 3 ms 1108 KB Output is correct
44 Correct 340 ms 31780 KB Output is correct
45 Correct 387 ms 31688 KB Output is correct
46 Correct 341 ms 31788 KB Output is correct
47 Correct 354 ms 31820 KB Output is correct
48 Correct 205 ms 31676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 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 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 264 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 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 1108 KB Output is correct
27 Correct 4 ms 1108 KB Output is correct
28 Correct 4 ms 1108 KB Output is correct
29 Correct 5 ms 1108 KB Output is correct
30 Correct 3 ms 848 KB Output is correct
31 Correct 4 ms 1048 KB Output is correct
32 Correct 5 ms 1132 KB Output is correct
33 Correct 4 ms 1108 KB Output is correct
34 Correct 5 ms 1104 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 1108 KB Output is correct
38 Correct 4 ms 1108 KB Output is correct
39 Correct 3 ms 724 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 316 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 320 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 166 ms 30544 KB Output is correct
51 Correct 126 ms 20356 KB Output is correct
52 Correct 105 ms 25164 KB Output is correct
53 Correct 154 ms 30544 KB Output is correct
54 Correct 126 ms 30452 KB Output is correct
55 Correct 133 ms 30540 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 324 KB Output is correct
60 Correct 2 ms 724 KB Output is correct
61 Correct 186 ms 30716 KB Output is correct
62 Correct 190 ms 29844 KB Output is correct
63 Correct 136 ms 22236 KB Output is correct
64 Correct 225 ms 30680 KB Output is correct
65 Correct 136 ms 30664 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 5 ms 1108 KB Output is correct
71 Correct 2 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 248 ms 29756 KB Output is correct
74 Correct 251 ms 28212 KB Output is correct
75 Correct 300 ms 31164 KB Output is correct
76 Correct 259 ms 31080 KB Output is correct
77 Correct 168 ms 30624 KB Output is correct
78 Correct 104 ms 18932 KB Output is correct
79 Correct 4 ms 840 KB Output is correct
80 Correct 4 ms 1096 KB Output is correct
81 Correct 3 ms 1100 KB Output is correct
82 Correct 3 ms 1108 KB Output is correct
83 Correct 340 ms 31780 KB Output is correct
84 Correct 387 ms 31688 KB Output is correct
85 Correct 341 ms 31788 KB Output is correct
86 Correct 354 ms 31820 KB Output is correct
87 Correct 205 ms 31676 KB Output is correct
88 Correct 313 ms 33476 KB Output is correct
89 Correct 327 ms 33500 KB Output is correct
90 Correct 345 ms 33488 KB Output is correct
91 Correct 341 ms 33452 KB Output is correct
92 Correct 338 ms 32112 KB Output is correct
93 Correct 344 ms 32432 KB Output is correct
94 Correct 352 ms 32348 KB Output is correct
95 Correct 193 ms 33344 KB Output is correct
96 Correct 223 ms 33508 KB Output is correct
97 Correct 157 ms 33604 KB Output is correct
98 Correct 134 ms 32180 KB Output is correct
99 Correct 154 ms 32328 KB Output is correct