Submission #629873

# Submission time Handle Problem Language Result Execution time Memory
629873 2022-08-15T09:41:22 Z abeker Radio Towers (IOI22_towers) C++17
40 / 100
4000 ms 17416 KB
#include <bits/stdc++.h>
#include "towers.h"
using namespace std;

const int INF = 2e9;

struct Node {
  int mini, arg_max;
};

class Tournament {
  int n, offset;
  vector <int> vals;
  vector <Node> tour;
public:
  Node merge(Node lhs, Node rhs) const {
    return {min(lhs.mini, rhs.mini), vals[lhs.arg_max] > vals[rhs.arg_max] ? lhs.arg_max : rhs.arg_max};
  }
  Tournament(int n, vector <int> _vals) : n(n), vals(_vals) {
    vals.push_back(0);
    for (offset = 1; offset <= n; offset *= 2);
    tour.resize(2 * offset);
    vals.resize(offset);
    for (int i = 0; i < offset; i++)
      tour[i + offset] = {vals[i], i};
    for (int i = offset - 1; i; i--)
      tour[i] = merge(tour[2 * i], tour[2 * i + 1]);
  }
  Tournament() {}
  Node query(int x, int lo, int hi, int from, int to) const {
    if (lo >= to || hi <= from)
      return {INF, n};
    if (lo >= from && hi <= to)
      return tour[x];
    int mid = (lo + hi) / 2;
    return merge(query(2 * x, lo, mid, from, to), query(2 * x + 1, mid, hi, from, to));
  }
  Node query(int from, int to) const {
    return query(1, 0, offset, from, to);
  }
  int get(int x) const {
    return vals[x];
  }
};

int N;
Tournament solver;
vector <int> lbs, ubs;

int build_tree(int lo, int hi, int prev) {
  if (lo >= hi)
    return -INF;
  Node tmp = solver.query(lo, hi);
  int mid = tmp.arg_max;
  int maks = solver.get(mid);
  int res = prev - tmp.mini;
  lbs.push_back(max(build_tree(lo, mid, maks), build_tree(mid + 1, hi, maks)));
  ubs.push_back(res);
  return res;
}

void init(int n, vector <int> h) {
  N = n;
  solver = Tournament(n, h);
  build_tree(0, n, INF);
  sort(lbs.begin(), lbs.end());
  sort(ubs.begin(), ubs.end());
}

int solve(int lo, int hi, int ub, int diff) {
  if (lo >= hi)
    return 0;
  Node tmp = solver.query(lo, hi);
  if (tmp.mini > ub)
    return 0;
  int mid = tmp.arg_max;
  int maks = solver.get(mid);
  return max(solve(lo, mid, maks - diff, diff) + solve(mid + 1, hi, maks - diff, diff), 1);
}

int get_smaller(const vector <int> &v, int x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int max_towers(int l, int r, int d) {
  if (l == 0 && r == N - 1)
    return get_smaller(lbs, d) - get_smaller(ubs, d);
  return solve(l, r + 1, INF, d);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4019 ms 8696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 476 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 476 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 30 ms 2740 KB Output is correct
37 Correct 42 ms 4816 KB Output is correct
38 Correct 42 ms 4900 KB Output is correct
39 Correct 46 ms 4916 KB Output is correct
40 Correct 42 ms 4804 KB Output is correct
41 Correct 49 ms 4876 KB Output is correct
42 Correct 38 ms 4888 KB Output is correct
43 Correct 40 ms 17416 KB Output is correct
44 Correct 39 ms 17332 KB Output is correct
45 Correct 40 ms 13992 KB Output is correct
46 Correct 41 ms 12740 KB Output is correct
47 Correct 49 ms 4888 KB Output is correct
48 Correct 41 ms 4908 KB Output is correct
49 Correct 39 ms 4916 KB Output is correct
50 Correct 42 ms 17304 KB Output is correct
51 Correct 45 ms 17176 KB Output is correct
52 Correct 42 ms 4884 KB Output is correct
53 Correct 38 ms 4804 KB Output is correct
54 Correct 39 ms 4884 KB Output is correct
55 Correct 46 ms 17368 KB Output is correct
56 Correct 42 ms 16172 KB Output is correct
57 Correct 38 ms 4872 KB Output is correct
58 Correct 42 ms 4900 KB Output is correct
59 Correct 40 ms 4892 KB Output is correct
60 Correct 46 ms 4900 KB Output is correct
61 Correct 39 ms 4900 KB Output is correct
62 Correct 44 ms 4792 KB Output is correct
63 Correct 45 ms 4896 KB Output is correct
64 Correct 35 ms 17292 KB Output is correct
65 Correct 38 ms 17288 KB Output is correct
66 Correct 39 ms 12468 KB Output is correct
67 Correct 46 ms 16736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4008 ms 4888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 233 ms 1436 KB Output is correct
2 Correct 814 ms 4844 KB Output is correct
3 Correct 826 ms 4792 KB Output is correct
4 Correct 868 ms 4772 KB Output is correct
5 Correct 910 ms 4892 KB Output is correct
6 Correct 733 ms 4792 KB Output is correct
7 Correct 884 ms 4996 KB Output is correct
8 Correct 860 ms 17348 KB Output is correct
9 Correct 806 ms 17308 KB Output is correct
10 Correct 716 ms 12308 KB Output is correct
11 Correct 658 ms 13368 KB Output is correct
12 Correct 40 ms 4784 KB Output is correct
13 Correct 40 ms 4884 KB Output is correct
14 Correct 39 ms 4896 KB Output is correct
15 Correct 40 ms 17380 KB Output is correct
16 Correct 43 ms 16196 KB Output is correct
17 Correct 39 ms 4828 KB Output is correct
18 Correct 41 ms 4884 KB Output is correct
19 Correct 40 ms 4868 KB Output is correct
20 Correct 46 ms 4924 KB Output is correct
21 Correct 39 ms 4768 KB Output is correct
22 Correct 38 ms 4872 KB Output is correct
23 Correct 38 ms 4900 KB Output is correct
24 Correct 34 ms 17308 KB Output is correct
25 Correct 39 ms 17328 KB Output is correct
26 Correct 39 ms 12524 KB Output is correct
27 Correct 56 ms 16672 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 464 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 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 592 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 476 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 30 ms 2740 KB Output is correct
37 Correct 42 ms 4816 KB Output is correct
38 Correct 42 ms 4900 KB Output is correct
39 Correct 46 ms 4916 KB Output is correct
40 Correct 42 ms 4804 KB Output is correct
41 Correct 49 ms 4876 KB Output is correct
42 Correct 38 ms 4888 KB Output is correct
43 Correct 40 ms 17416 KB Output is correct
44 Correct 39 ms 17332 KB Output is correct
45 Correct 40 ms 13992 KB Output is correct
46 Correct 41 ms 12740 KB Output is correct
47 Correct 49 ms 4888 KB Output is correct
48 Correct 41 ms 4908 KB Output is correct
49 Correct 39 ms 4916 KB Output is correct
50 Correct 42 ms 17304 KB Output is correct
51 Correct 45 ms 17176 KB Output is correct
52 Correct 42 ms 4884 KB Output is correct
53 Correct 38 ms 4804 KB Output is correct
54 Correct 39 ms 4884 KB Output is correct
55 Correct 46 ms 17368 KB Output is correct
56 Correct 42 ms 16172 KB Output is correct
57 Correct 38 ms 4872 KB Output is correct
58 Correct 42 ms 4900 KB Output is correct
59 Correct 40 ms 4892 KB Output is correct
60 Correct 46 ms 4900 KB Output is correct
61 Correct 39 ms 4900 KB Output is correct
62 Correct 44 ms 4792 KB Output is correct
63 Correct 45 ms 4896 KB Output is correct
64 Correct 35 ms 17292 KB Output is correct
65 Correct 38 ms 17288 KB Output is correct
66 Correct 39 ms 12468 KB Output is correct
67 Correct 46 ms 16736 KB Output is correct
68 Execution timed out 4008 ms 4888 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4019 ms 8696 KB Time limit exceeded
2 Halted 0 ms 0 KB -