Submission #625587

# Submission time Handle Problem Language Result Execution time Memory
625587 2022-08-10T15:24:38 Z d4xn Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 2240 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

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

int n;
vi v;

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

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());

  vi ok(n, 0);
  int ans = 0;
  for (int i = 0; i < r-l+1; i++) {
    int h = s[i].first;
    int idx = s[i].second;
    if (ok[idx] == ans) {
      ans++;

      int mx;
      if (idx+1 < n) mx = v[idx+1];
      for (int j = idx+2; j <= r; j++) {
        if (max(h, v[j]) + d <= mx) ok[j]++;
        mx = max(mx, v[j]);
      }

      if (idx-1 >= 0) mx = v[idx-1];
      for (int j = idx-2; j >= l; j--) {
        if (max(h, v[j]) + d <= mx) ok[j]++;
        mx = max(mx, v[j]);
      }
    }
  }
  return ans;
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:38:11: warning: 'mx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |       int mx;
      |           ^~
# Verdict Execution time Memory Grader output
1 Execution timed out 4045 ms 1456 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 3 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 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 4 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 2 ms 208 KB Output is correct
27 Correct 3 ms 208 KB Output is correct
28 Correct 3 ms 336 KB Output is correct
29 Correct 2 ms 208 KB Output is correct
30 Correct 2 ms 208 KB Output is correct
31 Correct 2 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 3 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 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 4 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 2 ms 208 KB Output is correct
27 Correct 3 ms 208 KB Output is correct
28 Correct 3 ms 336 KB Output is correct
29 Correct 2 ms 208 KB Output is correct
30 Correct 2 ms 208 KB Output is correct
31 Correct 2 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 205 ms 1196 KB Output is correct
37 Correct 385 ms 1716 KB Output is correct
38 Correct 170 ms 1556 KB Output is correct
39 Correct 48 ms 1688 KB Output is correct
40 Correct 224 ms 1440 KB Output is correct
41 Correct 2101 ms 2064 KB Output is correct
42 Correct 20 ms 1440 KB Output is correct
43 Correct 13 ms 1812 KB Output is correct
44 Correct 10 ms 1560 KB Output is correct
45 Correct 11 ms 1440 KB Output is correct
46 Correct 14 ms 1448 KB Output is correct
47 Correct 554 ms 1744 KB Output is correct
48 Correct 301 ms 1712 KB Output is correct
49 Correct 57 ms 1436 KB Output is correct
50 Correct 10 ms 1580 KB Output is correct
51 Correct 19 ms 1700 KB Output is correct
52 Execution timed out 4033 ms 2240 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4072 ms 1892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 820 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 3 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 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 4 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 2 ms 208 KB Output is correct
27 Correct 3 ms 208 KB Output is correct
28 Correct 3 ms 336 KB Output is correct
29 Correct 2 ms 208 KB Output is correct
30 Correct 2 ms 208 KB Output is correct
31 Correct 2 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 205 ms 1196 KB Output is correct
37 Correct 385 ms 1716 KB Output is correct
38 Correct 170 ms 1556 KB Output is correct
39 Correct 48 ms 1688 KB Output is correct
40 Correct 224 ms 1440 KB Output is correct
41 Correct 2101 ms 2064 KB Output is correct
42 Correct 20 ms 1440 KB Output is correct
43 Correct 13 ms 1812 KB Output is correct
44 Correct 10 ms 1560 KB Output is correct
45 Correct 11 ms 1440 KB Output is correct
46 Correct 14 ms 1448 KB Output is correct
47 Correct 554 ms 1744 KB Output is correct
48 Correct 301 ms 1712 KB Output is correct
49 Correct 57 ms 1436 KB Output is correct
50 Correct 10 ms 1580 KB Output is correct
51 Correct 19 ms 1700 KB Output is correct
52 Execution timed out 4033 ms 2240 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4045 ms 1456 KB Time limit exceeded
2 Halted 0 ms 0 KB -