Submission #784995

# Submission time Handle Problem Language Result Execution time Memory
784995 2023-07-16T21:19:53 Z thimote75 Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 6556 KB
#include "towers.h"

#include <bits/stdc++.h>
using namespace std;

using idata = vector<int>;

idata heights;
int nbTowers;

void init(int N, idata H) {
  nbTowers = N;
  heights  = H;
}

int D0 = -1;
idata jumps;

struct MContainer {
  set<pair<int, int>> m;

  void append (int node, int height) {
    m.insert({ height, node });

    auto it = m.find({ height, node });
    while (it != m.begin()) {
      it --;
      m.erase(*it);
      it = m.find({ height, node });
    }
  }
  int query (int height) { // find the first node greater
    auto it = m.upper_bound({ height, - 1 });
    if (it == m.end()) return -1;

    return (*it).second;
  }
};

int toMiddle (int i) {
  if (i == -1) return -1;
  return 2 * i + 1;
}
int toNormal (int i) {
  if (i == -1) return -1;
  return 2 * i;
}

void init (int D) {
  // node 2i     represents node i as a normal node
  // node 2i + 1 represents node i as a middle node
  jumps.resize(2 * nbTowers, - 1);
  D0 = D;

  MContainer container;
  MContainer inverted;

  for (int i = nbTowers - 1; i >= 0; i --) {
    int lnt_mid = container.query( heights[i] + D );
    int lnt_lnt = inverted .query( - heights[i] );
    int mid_mid = container.query( heights[i] );
    int mid_lnt = inverted .query( - heights[i] + D );
    
    jumps[toNormal(i)] = toMiddle(lnt_mid);
    if (lnt_mid == -1 || (lnt_lnt != -1 && lnt_lnt < lnt_mid))
      jumps[toNormal(i)] = toNormal(lnt_lnt);
    jumps[toMiddle(i)] = toNormal(mid_lnt);
    if (mid_lnt == -1 || (mid_mid != -1 && mid_mid < mid_lnt))
      jumps[toMiddle(i)] = toMiddle(mid_mid);

    container.append(i, heights[i]);
    inverted.append(i, -heights[i]);
  }
}

int jump ( int node, int max ) {
  node = toNormal(node);
  max  = toMiddle(max);
  int res = 1;
  while (node <= max && node != -1) {
    if (jumps[node] != -1 && jumps[node] <= max && (node & 1) == 1 && (jumps[node] & 1) == 0)
      res ++;
    node = jumps[node];
  }

  return res;
}

int max_towers(int L, int R, int D) {
  if (D != D0) {
    init(D);
  }

  return jump(L, R);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4026 ms 3420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 25 ms 1232 KB Output is correct
37 Correct 40 ms 1824 KB Output is correct
38 Correct 37 ms 1880 KB Output is correct
39 Correct 30 ms 1864 KB Output is correct
40 Correct 36 ms 1816 KB Output is correct
41 Correct 31 ms 1856 KB Output is correct
42 Correct 36 ms 1860 KB Output is correct
43 Correct 51 ms 6556 KB Output is correct
44 Correct 48 ms 6548 KB Output is correct
45 Correct 46 ms 5276 KB Output is correct
46 Correct 47 ms 4672 KB Output is correct
47 Correct 31 ms 1836 KB Output is correct
48 Correct 30 ms 1860 KB Output is correct
49 Correct 35 ms 1856 KB Output is correct
50 Correct 50 ms 6492 KB Output is correct
51 Correct 50 ms 6400 KB Output is correct
52 Correct 32 ms 1820 KB Output is correct
53 Correct 30 ms 1852 KB Output is correct
54 Correct 29 ms 1864 KB Output is correct
55 Correct 51 ms 6464 KB Output is correct
56 Correct 48 ms 6056 KB Output is correct
57 Correct 33 ms 1700 KB Output is correct
58 Correct 40 ms 1864 KB Output is correct
59 Correct 36 ms 1836 KB Output is correct
60 Correct 30 ms 1864 KB Output is correct
61 Correct 31 ms 1828 KB Output is correct
62 Correct 33 ms 1852 KB Output is correct
63 Correct 31 ms 1856 KB Output is correct
64 Correct 47 ms 6548 KB Output is correct
65 Correct 47 ms 6432 KB Output is correct
66 Correct 42 ms 4648 KB Output is correct
67 Correct 46 ms 6168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4057 ms 1840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4011 ms 720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 25 ms 1232 KB Output is correct
37 Correct 40 ms 1824 KB Output is correct
38 Correct 37 ms 1880 KB Output is correct
39 Correct 30 ms 1864 KB Output is correct
40 Correct 36 ms 1816 KB Output is correct
41 Correct 31 ms 1856 KB Output is correct
42 Correct 36 ms 1860 KB Output is correct
43 Correct 51 ms 6556 KB Output is correct
44 Correct 48 ms 6548 KB Output is correct
45 Correct 46 ms 5276 KB Output is correct
46 Correct 47 ms 4672 KB Output is correct
47 Correct 31 ms 1836 KB Output is correct
48 Correct 30 ms 1860 KB Output is correct
49 Correct 35 ms 1856 KB Output is correct
50 Correct 50 ms 6492 KB Output is correct
51 Correct 50 ms 6400 KB Output is correct
52 Correct 32 ms 1820 KB Output is correct
53 Correct 30 ms 1852 KB Output is correct
54 Correct 29 ms 1864 KB Output is correct
55 Correct 51 ms 6464 KB Output is correct
56 Correct 48 ms 6056 KB Output is correct
57 Correct 33 ms 1700 KB Output is correct
58 Correct 40 ms 1864 KB Output is correct
59 Correct 36 ms 1836 KB Output is correct
60 Correct 30 ms 1864 KB Output is correct
61 Correct 31 ms 1828 KB Output is correct
62 Correct 33 ms 1852 KB Output is correct
63 Correct 31 ms 1856 KB Output is correct
64 Correct 47 ms 6548 KB Output is correct
65 Correct 47 ms 6432 KB Output is correct
66 Correct 42 ms 4648 KB Output is correct
67 Correct 46 ms 6168 KB Output is correct
68 Execution timed out 4057 ms 1840 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4026 ms 3420 KB Time limit exceeded
2 Halted 0 ms 0 KB -