Submission #1001029

# Submission time Handle Problem Language Result Execution time Memory
1001029 2024-06-18T13:05:54 Z LucaLucaM Team Contest (JOI22_team) C++17
100 / 100
882 ms 92432 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <set>
#include <map>
#warning That's the baby, that's not my baby

typedef long long ll;

int dumb(int n, std::vector<int> a, std::vector<int> b, std::vector<int> c) {
  int answer = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (a[i] > a[j] && a[i] > a[k] && b[j] > b[i] && b[j] > b[k] && c[k] > c[i] && c[k] > c[j]) {
          answer = std::max(answer, a[i] + b[j] + c[k]);
        }
      }
    }
  }
  return answer;
}

int smart(int n, std::vector<int> a, std::vector<int> b, std::vector<int> c) {
  if (n < 3) {
    return -1;
  }
  int answer = 0;
  int maxA = *std::max_element(a.begin(), a.end());
  int maxB = *std::max_element(b.begin(), b.end());
  int maxC = *std::max_element(c.begin(), c.end());
  std::vector<int> A, B, C;
  for (int i = 0; i < n; i++) {
    int cnt = (a[i] == maxA) + (b[i] == maxB) + (c[i] == maxC);
    if (cnt <= 1) {
      A.push_back(a[i]);
      B.push_back(b[i]);
      C.push_back(c[i]);
    }
  }

  if ((int) A.size() == n) {
    return maxA + maxB + maxC;
  } else {
    return smart((int) A.size(), A, B, C);
  }
}

int full(int n, std::vector<int> a, std::vector<int> b, std::vector<int> c) {
  std::multiset<int> as, bs, cs;
  std::map<std::pair<int, int>, std::set<int>> AB, BC, AC;
  for (int i = 0; i < n; i++) {
    as.insert(a[i]);
    bs.insert(b[i]);
    cs.insert(c[i]);
    AB[{a[i], b[i]}].insert(i);
    BC[{b[i], c[i]}].insert(i);
    AC[{a[i], c[i]}].insert(i);
  }

  auto del = [&] (int i) {
    as.erase(as.find(a[i]));
    bs.erase(bs.find(b[i]));
    cs.erase(cs.find(c[i]));
    AB[{a[i], b[i]}].erase(i);
    BC[{b[i], c[i]}].erase(i);
    AC[{a[i], c[i]}].erase(i);
    if (AB[{a[i], b[i]}].empty()) {
      AB.erase({a[i], b[i]});
    }
    if (BC[{b[i], c[i]}].empty()) {
      BC.erase({b[i], c[i]});
    }
    if (AC[{a[i], c[i]}].empty()) {
      AC.erase({a[i], c[i]});
    }
  };

  while ((int) as.size() >= 3) {
    int maxA = *as.rbegin();
    int maxB = *bs.rbegin();
    int maxC = *cs.rbegin();
    auto it = AB.find({maxA, maxB});
    if (it != AB.end()) {
      int i = *(it -> second).begin();
      del(i);
      continue;
    }
    it = BC.find({maxB, maxC});
    if (it != BC.end()) {
      int i = *(it -> second).begin();
      del(i);
      continue;
    }
    it = AC.find({maxA, maxC});
    if (it != AC.end()) {
      int i = *(it -> second).begin();
      del(i);
      continue;
    }
    break;
  }
  if ((int) as.size() < 3) {
    return -1;
  } else {
    return *as.rbegin() + *bs.rbegin() + *cs.rbegin();
  }
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i] >> b[i] >> c[i];
  }
  std::cout << full(n, a, b, c);

  return 0;
}

Compilation message

team.cpp:8:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    8 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
team.cpp: In function 'int smart(int, std::vector<int>, std::vector<int>, std::vector<int>)':
team.cpp:30:7: warning: unused variable 'answer' [-Wunused-variable]
   30 |   int answer = 0;
      |       ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 456 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 456 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 8 ms 2908 KB Output is correct
27 Correct 8 ms 2652 KB Output is correct
28 Correct 8 ms 2656 KB Output is correct
29 Correct 14 ms 2908 KB Output is correct
30 Correct 6 ms 2032 KB Output is correct
31 Correct 8 ms 2652 KB Output is correct
32 Correct 10 ms 2396 KB Output is correct
33 Correct 7 ms 2140 KB Output is correct
34 Correct 6 ms 2900 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 2 ms 856 KB Output is correct
37 Correct 4 ms 2392 KB Output is correct
38 Correct 6 ms 2404 KB Output is correct
39 Correct 3 ms 1112 KB Output is correct
# Verdict Execution time Memory 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 344 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 344 KB Output is correct
11 Correct 300 ms 46240 KB Output is correct
12 Correct 241 ms 30800 KB Output is correct
13 Correct 179 ms 38740 KB Output is correct
14 Correct 352 ms 46932 KB Output is correct
15 Correct 292 ms 47116 KB Output is correct
16 Correct 216 ms 46928 KB Output is correct
# Verdict Execution time Memory 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 344 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 344 KB Output is correct
11 Correct 300 ms 46240 KB Output is correct
12 Correct 241 ms 30800 KB Output is correct
13 Correct 179 ms 38740 KB Output is correct
14 Correct 352 ms 46932 KB Output is correct
15 Correct 292 ms 47116 KB Output is correct
16 Correct 216 ms 46928 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 427 ms 47444 KB Output is correct
23 Correct 418 ms 46168 KB Output is correct
24 Correct 329 ms 34264 KB Output is correct
25 Correct 485 ms 47368 KB Output is correct
26 Correct 316 ms 47068 KB Output is correct
# Verdict Execution time Memory 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 344 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 344 KB Output is correct
11 Correct 300 ms 46240 KB Output is correct
12 Correct 241 ms 30800 KB Output is correct
13 Correct 179 ms 38740 KB Output is correct
14 Correct 352 ms 46932 KB Output is correct
15 Correct 292 ms 47116 KB Output is correct
16 Correct 216 ms 46928 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 427 ms 47444 KB Output is correct
23 Correct 418 ms 46168 KB Output is correct
24 Correct 329 ms 34264 KB Output is correct
25 Correct 485 ms 47368 KB Output is correct
26 Correct 316 ms 47068 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 12 ms 2396 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 587 ms 66004 KB Output is correct
35 Correct 602 ms 58208 KB Output is correct
36 Correct 670 ms 60804 KB Output is correct
37 Correct 749 ms 59540 KB Output is correct
38 Correct 370 ms 46652 KB Output is correct
39 Correct 201 ms 37340 KB Output is correct
# Verdict Execution time Memory 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 344 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 344 KB Output is correct
11 Correct 300 ms 46240 KB Output is correct
12 Correct 241 ms 30800 KB Output is correct
13 Correct 179 ms 38740 KB Output is correct
14 Correct 352 ms 46932 KB Output is correct
15 Correct 292 ms 47116 KB Output is correct
16 Correct 216 ms 46928 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 427 ms 47444 KB Output is correct
23 Correct 418 ms 46168 KB Output is correct
24 Correct 329 ms 34264 KB Output is correct
25 Correct 485 ms 47368 KB Output is correct
26 Correct 316 ms 47068 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 12 ms 2396 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 587 ms 66004 KB Output is correct
35 Correct 602 ms 58208 KB Output is correct
36 Correct 670 ms 60804 KB Output is correct
37 Correct 749 ms 59540 KB Output is correct
38 Correct 370 ms 46652 KB Output is correct
39 Correct 201 ms 37340 KB Output is correct
40 Correct 7 ms 1884 KB Output is correct
41 Correct 7 ms 2800 KB Output is correct
42 Correct 5 ms 2476 KB Output is correct
43 Correct 8 ms 2396 KB Output is correct
44 Correct 691 ms 90212 KB Output is correct
45 Correct 828 ms 78520 KB Output is correct
46 Correct 882 ms 82256 KB Output is correct
47 Correct 862 ms 77392 KB Output is correct
48 Correct 420 ms 49232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 456 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 8 ms 2908 KB Output is correct
27 Correct 8 ms 2652 KB Output is correct
28 Correct 8 ms 2656 KB Output is correct
29 Correct 14 ms 2908 KB Output is correct
30 Correct 6 ms 2032 KB Output is correct
31 Correct 8 ms 2652 KB Output is correct
32 Correct 10 ms 2396 KB Output is correct
33 Correct 7 ms 2140 KB Output is correct
34 Correct 6 ms 2900 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 2 ms 856 KB Output is correct
37 Correct 4 ms 2392 KB Output is correct
38 Correct 6 ms 2404 KB Output is correct
39 Correct 3 ms 1112 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 344 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 344 KB Output is correct
50 Correct 300 ms 46240 KB Output is correct
51 Correct 241 ms 30800 KB Output is correct
52 Correct 179 ms 38740 KB Output is correct
53 Correct 352 ms 46932 KB Output is correct
54 Correct 292 ms 47116 KB Output is correct
55 Correct 216 ms 46928 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 3 ms 1116 KB Output is correct
61 Correct 427 ms 47444 KB Output is correct
62 Correct 418 ms 46168 KB Output is correct
63 Correct 329 ms 34264 KB Output is correct
64 Correct 485 ms 47368 KB Output is correct
65 Correct 316 ms 47068 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 604 KB Output is correct
70 Correct 12 ms 2396 KB Output is correct
71 Correct 1 ms 860 KB Output is correct
72 Correct 1 ms 860 KB Output is correct
73 Correct 587 ms 66004 KB Output is correct
74 Correct 602 ms 58208 KB Output is correct
75 Correct 670 ms 60804 KB Output is correct
76 Correct 749 ms 59540 KB Output is correct
77 Correct 370 ms 46652 KB Output is correct
78 Correct 201 ms 37340 KB Output is correct
79 Correct 7 ms 1884 KB Output is correct
80 Correct 7 ms 2800 KB Output is correct
81 Correct 5 ms 2476 KB Output is correct
82 Correct 8 ms 2396 KB Output is correct
83 Correct 691 ms 90212 KB Output is correct
84 Correct 828 ms 78520 KB Output is correct
85 Correct 882 ms 82256 KB Output is correct
86 Correct 862 ms 77392 KB Output is correct
87 Correct 420 ms 49232 KB Output is correct
88 Correct 619 ms 92340 KB Output is correct
89 Correct 724 ms 90452 KB Output is correct
90 Correct 658 ms 91984 KB Output is correct
91 Correct 773 ms 89392 KB Output is correct
92 Correct 772 ms 89560 KB Output is correct
93 Correct 773 ms 89648 KB Output is correct
94 Correct 861 ms 86692 KB Output is correct
95 Correct 496 ms 70876 KB Output is correct
96 Correct 334 ms 92432 KB Output is correct
97 Correct 229 ms 50208 KB Output is correct
98 Correct 224 ms 76884 KB Output is correct
99 Correct 291 ms 76984 KB Output is correct