답안 #625612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625612 2022-08-10T15:51:16 Z d4xn 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 5892 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>

const int inf = INT_MAX;

int n;
vi v, seg;

void build(int p=1, int l=0, int r=n-1) {
  if (l > r) return;
  if (l == r) {
    seg[p] = v[l];
    return;
  }

  int mid = (l+r)/2;
  build(p*2, l, mid);
  build(p*2+1, mid+1, r);
  seg[p] = max(seg[p*2], seg[p*2+1]);
}

int query(int a, int b, int p=1, int l=0, int r=n-1) {
  if (l > r || a > b || a > r || b < l) return -inf;
  if (a <= l && r <= b) {
    return seg[p];   
  }

  int mid = (l+r)/2;
  int x = query(a, b, p*2, l, mid);
  int y = query(a, b, p*2+1, mid+1, r);
  return max(x, y);
}

void init(int N, std::vector<int> H) {
  n = N;
  seg.resize(n*4);
  v.resize(n);
  for (int i = 0; i < n; i++) v[i] = H[i];
  build();
}

int max_towers(int L, int R, int D) {
  int l = L;
  int r = R;
  int d = D;

  vii s(r-l+1);
  for (int i = l; i <= r; i++) {
    s[i-l] = make_pair(v[i], i);
  }
  sort(s.begin(), s.end());

  set<int> taken;
  for (int i = 0; i < r-l+1; i++) {
    int h = s[i].first;
    int idx = s[i].second;
    
    auto it = taken.upper_bound(idx);
    bool ok = 0;
    if (it != taken.end()) {
      int hi = *it;
      if (h + d <= query(idx+1, hi-1)) ok = 1;
    }
    else ok = 1;

    if (!ok) continue;

    ok = 0;
    if (it != taken.begin() && !taken.empty()) {
      --it;
      int lo = *it;
      if (h + d <= query(lo+1, idx-1)) ok = 1;
    }
    else ok = 1;

    if (ok) taken.insert(idx);
  }
  return taken.size();
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 2616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 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 1 ms 336 KB Output is correct
22 Correct 1 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 368 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 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 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 1 ms 336 KB Output is correct
22 Correct 1 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 368 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 2 ms 336 KB Output is correct
36 Correct 16 ms 2200 KB Output is correct
37 Correct 35 ms 2992 KB Output is correct
38 Correct 18 ms 2972 KB Output is correct
39 Correct 24 ms 3000 KB Output is correct
40 Correct 17 ms 2980 KB Output is correct
41 Correct 52 ms 4156 KB Output is correct
42 Correct 13 ms 2972 KB Output is correct
43 Correct 31 ms 2976 KB Output is correct
44 Correct 15 ms 2976 KB Output is correct
45 Correct 12 ms 2972 KB Output is correct
46 Correct 12 ms 2984 KB Output is correct
47 Correct 33 ms 3372 KB Output is correct
48 Correct 21 ms 3244 KB Output is correct
49 Correct 27 ms 3108 KB Output is correct
50 Correct 18 ms 2972 KB Output is correct
51 Correct 30 ms 2976 KB Output is correct
52 Correct 69 ms 4928 KB Output is correct
53 Correct 65 ms 5652 KB Output is correct
54 Correct 64 ms 5892 KB Output is correct
55 Correct 38 ms 3420 KB Output is correct
56 Correct 51 ms 3424 KB Output is correct
57 Correct 58 ms 3868 KB Output is correct
58 Correct 60 ms 4272 KB Output is correct
59 Correct 70 ms 4484 KB Output is correct
60 Correct 79 ms 5776 KB Output is correct
61 Correct 76 ms 5380 KB Output is correct
62 Correct 62 ms 4808 KB Output is correct
63 Correct 64 ms 5332 KB Output is correct
64 Correct 36 ms 3364 KB Output is correct
65 Correct 43 ms 3372 KB Output is correct
66 Correct 38 ms 3356 KB Output is correct
67 Correct 48 ms 3348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4010 ms 5084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4019 ms 1764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 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 1 ms 336 KB Output is correct
22 Correct 1 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 368 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 2 ms 336 KB Output is correct
36 Correct 16 ms 2200 KB Output is correct
37 Correct 35 ms 2992 KB Output is correct
38 Correct 18 ms 2972 KB Output is correct
39 Correct 24 ms 3000 KB Output is correct
40 Correct 17 ms 2980 KB Output is correct
41 Correct 52 ms 4156 KB Output is correct
42 Correct 13 ms 2972 KB Output is correct
43 Correct 31 ms 2976 KB Output is correct
44 Correct 15 ms 2976 KB Output is correct
45 Correct 12 ms 2972 KB Output is correct
46 Correct 12 ms 2984 KB Output is correct
47 Correct 33 ms 3372 KB Output is correct
48 Correct 21 ms 3244 KB Output is correct
49 Correct 27 ms 3108 KB Output is correct
50 Correct 18 ms 2972 KB Output is correct
51 Correct 30 ms 2976 KB Output is correct
52 Correct 69 ms 4928 KB Output is correct
53 Correct 65 ms 5652 KB Output is correct
54 Correct 64 ms 5892 KB Output is correct
55 Correct 38 ms 3420 KB Output is correct
56 Correct 51 ms 3424 KB Output is correct
57 Correct 58 ms 3868 KB Output is correct
58 Correct 60 ms 4272 KB Output is correct
59 Correct 70 ms 4484 KB Output is correct
60 Correct 79 ms 5776 KB Output is correct
61 Correct 76 ms 5380 KB Output is correct
62 Correct 62 ms 4808 KB Output is correct
63 Correct 64 ms 5332 KB Output is correct
64 Correct 36 ms 3364 KB Output is correct
65 Correct 43 ms 3372 KB Output is correct
66 Correct 38 ms 3356 KB Output is correct
67 Correct 48 ms 3348 KB Output is correct
68 Execution timed out 4010 ms 5084 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 2616 KB Time limit exceeded
2 Halted 0 ms 0 KB -