Submission #830721

# Submission time Handle Problem Language Result Execution time Memory
830721 2023-08-19T09:48:53 Z NeroZein Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 3504 KB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;

struct SegTree {
  int n;
  vector<int> seg;
  void init (int n_) {
    n = n_; 
    seg.resize(n * 2 - 1);
    build(); 
  }
  void build(int nd, int l, int r) {
    seg[nd] = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    int rs = nd + ((mid - l + 1) << 1);
    build(nd + 1, l, mid);
    build(rs, mid + 1, r); 
  }
  void build() {
    build(0, 0, n - 1); 
  }
  void upd (int nd, int l, int r, int p, int v) {
    if (l == r) {
      seg[nd] = v;
      return;
    }
    int mid = (l + r) >> 1;
    int rs = nd + ((mid - l + 1) << 1);
    if (p <= mid) {
      upd(nd + 1, l, mid, p, v);
    } else {
      upd(rs, mid + 1, r, p, v); 
    }
    seg[nd] = max(seg[nd + 1], seg[rs]); 
  }
  void upd(int p, int v) {
    upd(0, 0, n - 1, p, v); 
  }
  int qry (int nd, int l, int r, int s, int e) {
    if (l >= s && r <= e) return seg[nd];
    int mid = (l + r) >> 1;
    int rs = nd + ((mid - l + 1) << 1);
    if (mid >= e) {
      return qry(nd + 1, l, mid, s, e);
    } else {
      if (mid < s) {
        return qry(rs, mid + 1, r, s, e);
      } else {
        return max(qry(nd + 1, l, mid, s, e), qry(rs, mid + 1, r, s, e)); 
      }
    }
  }
  int qry(int s, int e) {
    return qry(0, 0, n - 1, s, e); 
  }
};

vector<int> a; 
vector<int> b; 
SegTree not_matched;
SegTree not_complete;

void init(int N, std::vector<int> H) {
  a = b = H; 
  sort(b.begin(), b.end()); 
  not_matched.init(N); 
  not_complete.init(N); 
}

int get_ind(int value) {
  return upper_bound(b.begin(), b.end(), value) - b.begin() - 1;
}

int get_ind2(int value) {
  return lower_bound(b.begin(), b.end(), value) - b.begin(); 
}

bool f;
int max_towers(int L, int R, int D) {
  if ((L != 0 || R != (int) a.size() - 1) || !f) {
    f = true;
    not_complete.build();
    not_matched.build();
    for (int i = L; i <= R; ++i) {
      int match = get_ind(a[i] - D); 
      if (match >= 0) {
        assert(match < (int) a.size()); 
        int best = not_matched.qry(0, match);
        not_complete.upd(get_ind(a[i]), best); 
      }
      int complete = get_ind2(a[i] + D);
      int best = 0;
      if (complete < (int) a.size()) {
        best = not_complete.qry(complete, (int) a.size() - 1); 
      }
      not_matched.upd(get_ind(a[i]), best + 1); 
    }
  }
  return not_matched.seg[0];
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4009 ms 2128 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 336 KB Output is correct
7 Correct 1 ms 336 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 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 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 336 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 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 336 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 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 336 KB Output is correct
7 Correct 1 ms 336 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 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 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 336 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 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 336 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 2344 KB Output is correct
37 Correct 32 ms 3380 KB Output is correct
38 Correct 31 ms 3392 KB Output is correct
39 Correct 25 ms 3380 KB Output is correct
40 Correct 32 ms 3400 KB Output is correct
41 Correct 65 ms 3376 KB Output is correct
42 Correct 18 ms 3360 KB Output is correct
43 Correct 30 ms 3356 KB Output is correct
44 Correct 17 ms 3408 KB Output is correct
45 Correct 18 ms 3384 KB Output is correct
46 Correct 12 ms 3504 KB Output is correct
47 Correct 47 ms 3356 KB Output is correct
48 Correct 32 ms 3396 KB Output is correct
49 Correct 22 ms 3404 KB Output is correct
50 Correct 20 ms 3356 KB Output is correct
51 Correct 29 ms 3364 KB Output is correct
52 Correct 96 ms 3408 KB Output is correct
53 Correct 93 ms 3356 KB Output is correct
54 Correct 92 ms 3376 KB Output is correct
55 Correct 51 ms 3360 KB Output is correct
56 Correct 55 ms 3388 KB Output is correct
57 Correct 59 ms 3228 KB Output is correct
58 Correct 71 ms 3408 KB Output is correct
59 Correct 88 ms 3376 KB Output is correct
60 Correct 94 ms 3408 KB Output is correct
61 Correct 83 ms 3384 KB Output is correct
62 Correct 73 ms 3356 KB Output is correct
63 Correct 84 ms 3404 KB Output is correct
64 Correct 40 ms 3488 KB Output is correct
65 Correct 36 ms 3380 KB Output is correct
66 Correct 44 ms 3400 KB Output is correct
67 Correct 43 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4018 ms 3356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 1036 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
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 336 KB Output is correct
7 Correct 1 ms 336 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 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 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 336 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 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 336 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 2344 KB Output is correct
37 Correct 32 ms 3380 KB Output is correct
38 Correct 31 ms 3392 KB Output is correct
39 Correct 25 ms 3380 KB Output is correct
40 Correct 32 ms 3400 KB Output is correct
41 Correct 65 ms 3376 KB Output is correct
42 Correct 18 ms 3360 KB Output is correct
43 Correct 30 ms 3356 KB Output is correct
44 Correct 17 ms 3408 KB Output is correct
45 Correct 18 ms 3384 KB Output is correct
46 Correct 12 ms 3504 KB Output is correct
47 Correct 47 ms 3356 KB Output is correct
48 Correct 32 ms 3396 KB Output is correct
49 Correct 22 ms 3404 KB Output is correct
50 Correct 20 ms 3356 KB Output is correct
51 Correct 29 ms 3364 KB Output is correct
52 Correct 96 ms 3408 KB Output is correct
53 Correct 93 ms 3356 KB Output is correct
54 Correct 92 ms 3376 KB Output is correct
55 Correct 51 ms 3360 KB Output is correct
56 Correct 55 ms 3388 KB Output is correct
57 Correct 59 ms 3228 KB Output is correct
58 Correct 71 ms 3408 KB Output is correct
59 Correct 88 ms 3376 KB Output is correct
60 Correct 94 ms 3408 KB Output is correct
61 Correct 83 ms 3384 KB Output is correct
62 Correct 73 ms 3356 KB Output is correct
63 Correct 84 ms 3404 KB Output is correct
64 Correct 40 ms 3488 KB Output is correct
65 Correct 36 ms 3380 KB Output is correct
66 Correct 44 ms 3400 KB Output is correct
67 Correct 43 ms 3408 KB Output is correct
68 Execution timed out 4018 ms 3356 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4009 ms 2128 KB Time limit exceeded
2 Halted 0 ms 0 KB -