Submission #917367

# Submission time Handle Problem Language Result Execution time Memory
917367 2024-01-28T03:08:20 Z cig32 Team Contest (JOI22_team) C++17
100 / 100
142 ms 23760 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
static void run_with_stack_size(void (*func)(void), size_t stsize) {
  char *stack, *send;
  stack = (char *)malloc(stsize);
  send = stack + stsize - 16;
  send = (char *)((uintptr_t)send / 16 * 16);
  asm volatile(
    "mov %%rsp, (%0)\n"
    "mov %0, %%rsp\n"
    :
    : "r"(send));
  func();
  asm volatile("mov (%0), %%rsp\n" : : "r"(send));
  free(stack);
}
void solve(int tc) {
  int n;
  cin >> n;
  int x[n+1], y[n+1], z[n+1], ban[n+1];
  priority_queue<pair<int,int>> xx,yy,zz;
  for(int i=1; i<=n; i++) {
    cin >> x[i] >> y[i] >> z[i];
    xx.push({x[i],i});
    yy.push({y[i],i});
    zz.push({z[i],i});
    ban[i] = 0;
  }
  while(1) {
    while(xx.size() && ban[xx.top().second]) xx.pop();
    while(yy.size() && ban[yy.top().second]) yy.pop();
    while(zz.size() && ban[zz.top().second]) zz.pop();
    if(xx.empty() || yy.empty() || zz.empty()) break;
    pair<int,int> xt= xx.top();
    pair<int,int> yt= yy.top();
    pair<int,int> zt= zz.top();
    vector<int> bruhs = {xt.second, yt.second, zt.second};
    vector<int> bad;
    for(int w: bruhs) {
      int cnt = (x[w] == xt.first) + (y[w] == yt.first) + (z[w] == zt.first);
      if(cnt > 1) bad.push_back(w);
    }
    if(bad.size()) {
      for(int w: bad) {
        ban[w] = 1;
      }
      continue;
    }
    cout << xt.first + yt.first + zt.first << '\n'; return;
  }
  cout << "-1\n"; return;
  
}
void uwu() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
int32_t main() {
  #ifdef ONLINE_JUDGE
  uwu();
  #endif
  #ifndef ONLINE_JUDGE
  run_with_stack_size(uwu, 1024 * 1024 * 1024); // run with a 1 GiB stack
  #endif
}
/*
g++ E.cpp -std=c++17 -O2 -o E
./E < input.txt
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 476 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 1 ms 496 KB Output is correct
17 Correct 1 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 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 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 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 476 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 1 ms 496 KB Output is correct
17 Correct 1 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 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 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 1 ms 348 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 3 ms 2908 KB Output is correct
34 Correct 3 ms 860 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 860 KB Output is correct
38 Correct 2 ms 856 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 424 KB Output is correct
11 Correct 39 ms 17572 KB Output is correct
12 Correct 45 ms 10188 KB Output is correct
13 Correct 31 ms 11700 KB Output is correct
14 Correct 87 ms 16808 KB Output is correct
15 Correct 81 ms 16548 KB Output is correct
16 Correct 75 ms 17320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 424 KB Output is correct
11 Correct 39 ms 17572 KB Output is correct
12 Correct 45 ms 10188 KB Output is correct
13 Correct 31 ms 11700 KB Output is correct
14 Correct 87 ms 16808 KB Output is correct
15 Correct 81 ms 16548 KB Output is correct
16 Correct 75 ms 17320 KB Output is correct
17 Correct 0 ms 504 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 484 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 37 ms 17320 KB Output is correct
23 Correct 47 ms 20644 KB Output is correct
24 Correct 54 ms 10672 KB Output is correct
25 Correct 109 ms 17072 KB Output is correct
26 Correct 89 ms 20388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 424 KB Output is correct
11 Correct 39 ms 17572 KB Output is correct
12 Correct 45 ms 10188 KB Output is correct
13 Correct 31 ms 11700 KB Output is correct
14 Correct 87 ms 16808 KB Output is correct
15 Correct 81 ms 16548 KB Output is correct
16 Correct 75 ms 17320 KB Output is correct
17 Correct 0 ms 504 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 484 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 37 ms 17320 KB Output is correct
23 Correct 47 ms 20644 KB Output is correct
24 Correct 54 ms 10672 KB Output is correct
25 Correct 109 ms 17072 KB Output is correct
26 Correct 89 ms 20388 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 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 3 ms 856 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 560 KB Output is correct
34 Correct 43 ms 18916 KB Output is correct
35 Correct 64 ms 18044 KB Output is correct
36 Correct 65 ms 21672 KB Output is correct
37 Correct 117 ms 18740 KB Output is correct
38 Correct 85 ms 21416 KB Output is correct
39 Correct 57 ms 9144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 424 KB Output is correct
11 Correct 39 ms 17572 KB Output is correct
12 Correct 45 ms 10188 KB Output is correct
13 Correct 31 ms 11700 KB Output is correct
14 Correct 87 ms 16808 KB Output is correct
15 Correct 81 ms 16548 KB Output is correct
16 Correct 75 ms 17320 KB Output is correct
17 Correct 0 ms 504 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 484 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 37 ms 17320 KB Output is correct
23 Correct 47 ms 20644 KB Output is correct
24 Correct 54 ms 10672 KB Output is correct
25 Correct 109 ms 17072 KB Output is correct
26 Correct 89 ms 20388 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 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 3 ms 856 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 560 KB Output is correct
34 Correct 43 ms 18916 KB Output is correct
35 Correct 64 ms 18044 KB Output is correct
36 Correct 65 ms 21672 KB Output is correct
37 Correct 117 ms 18740 KB Output is correct
38 Correct 85 ms 21416 KB Output is correct
39 Correct 57 ms 9144 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 2908 KB Output is correct
42 Correct 2 ms 800 KB Output is correct
43 Correct 3 ms 760 KB Output is correct
44 Correct 47 ms 21672 KB Output is correct
45 Correct 100 ms 21672 KB Output is correct
46 Correct 90 ms 18592 KB Output is correct
47 Correct 113 ms 18472 KB Output is correct
48 Correct 86 ms 17288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 476 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 1 ms 496 KB Output is correct
17 Correct 1 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 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 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 1 ms 348 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 3 ms 2908 KB Output is correct
34 Correct 3 ms 860 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 860 KB Output is correct
38 Correct 2 ms 856 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 424 KB Output is correct
50 Correct 39 ms 17572 KB Output is correct
51 Correct 45 ms 10188 KB Output is correct
52 Correct 31 ms 11700 KB Output is correct
53 Correct 87 ms 16808 KB Output is correct
54 Correct 81 ms 16548 KB Output is correct
55 Correct 75 ms 17320 KB Output is correct
56 Correct 0 ms 504 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 484 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
61 Correct 37 ms 17320 KB Output is correct
62 Correct 47 ms 20644 KB Output is correct
63 Correct 54 ms 10672 KB Output is correct
64 Correct 109 ms 17072 KB Output is correct
65 Correct 89 ms 20388 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 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 3 ms 856 KB Output is correct
71 Correct 1 ms 600 KB Output is correct
72 Correct 1 ms 560 KB Output is correct
73 Correct 43 ms 18916 KB Output is correct
74 Correct 64 ms 18044 KB Output is correct
75 Correct 65 ms 21672 KB Output is correct
76 Correct 117 ms 18740 KB Output is correct
77 Correct 85 ms 21416 KB Output is correct
78 Correct 57 ms 9144 KB Output is correct
79 Correct 2 ms 604 KB Output is correct
80 Correct 2 ms 2908 KB Output is correct
81 Correct 2 ms 800 KB Output is correct
82 Correct 3 ms 760 KB Output is correct
83 Correct 47 ms 21672 KB Output is correct
84 Correct 100 ms 21672 KB Output is correct
85 Correct 90 ms 18592 KB Output is correct
86 Correct 113 ms 18472 KB Output is correct
87 Correct 86 ms 17288 KB Output is correct
88 Correct 50 ms 19368 KB Output is correct
89 Correct 94 ms 19316 KB Output is correct
90 Correct 56 ms 23760 KB Output is correct
91 Correct 139 ms 23612 KB Output is correct
92 Correct 80 ms 21928 KB Output is correct
93 Correct 108 ms 19616 KB Output is correct
94 Correct 126 ms 19600 KB Output is correct
95 Correct 95 ms 18860 KB Output is correct
96 Correct 142 ms 20164 KB Output is correct
97 Correct 88 ms 23168 KB Output is correct
98 Correct 49 ms 22696 KB Output is correct
99 Correct 84 ms 19112 KB Output is correct