Submission #1073545

# Submission time Handle Problem Language Result Execution time Memory
1073545 2024-08-24T15:56:57 Z fv3 Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 2000 KB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;
const int INF = 1 << 30;

int N;
vector<int> H;

void init(int N_, vector<int> H_)
{
  N = N_;
  H = H_;
}

int max_towers(int L, int R, int D) 
{
  // You should always lease the smallest tower
  // No two adjacent towers can be leased

  int res = 0;
  vector<int> leased(N);
  vector<int> taken(N);
  while (true)
  {
    int mn = INF;
    int mn_index = -1;
 
    for (int i = L; i <= R; i++)
    {
      if (!leased[i] && !taken[i] && H[i] < mn)
      {
        mn = H[i];
        mn_index = i;
      }
    }
    if (mn == INF) break;
 
    bool ok = true;
    int mx = mn;
    for (int i = mn_index + 1; i <= R; i++)
    {
      if (leased[i])
      {
        if (mx - mn < D) 
        {
          taken[mn_index] = 1;
          ok = false;
        }
        break;
      }
      else
      {
        mx = max(mx, H[i]);
      }
    }
    if (!ok)
      continue;
 
    mx = mn;
    for (int i = mn_index - 1; i >= L; i--)
    {
      if (leased[i])
      {
        if (mx - mn < D)
        {
          taken[mn_index] = 1;
          ok = false;
        }
        break;
      }
      else
      {
        mx = max(mx, H[i]);
      }
    }
    if (!ok) continue;
 
    res++;
    leased[mn_index] = 1;
    if (mn_index > L) taken[mn_index-1] = 1;
    if (mn_index < R) taken[mn_index+1] = 1;
  }

  return res;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 1316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 3 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 4 ms 460 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
29 Correct 4 ms 344 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 4 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 3 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 4 ms 460 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
29 Correct 4 ms 344 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 4 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
36 Correct 274 ms 1364 KB Output is correct
37 Correct 2901 ms 2000 KB Output is correct
38 Correct 179 ms 2000 KB Output is correct
39 Correct 1824 ms 2000 KB Output is correct
40 Correct 121 ms 1980 KB Output is correct
41 Execution timed out 4062 ms 2000 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4054 ms 1980 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4070 ms 872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 3 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 4 ms 460 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
29 Correct 4 ms 344 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 4 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
36 Correct 274 ms 1364 KB Output is correct
37 Correct 2901 ms 2000 KB Output is correct
38 Correct 179 ms 2000 KB Output is correct
39 Correct 1824 ms 2000 KB Output is correct
40 Correct 121 ms 1980 KB Output is correct
41 Execution timed out 4062 ms 2000 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 1316 KB Time limit exceeded
2 Halted 0 ms 0 KB -