Submission #701178

# Submission time Handle Problem Language Result Execution time Memory
701178 2023-02-20T11:27:44 Z boris_mihov Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 1568 KB
#include "towers.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

const int MAXN = 100000 + 10;
const int INF  = 1e9;

int n;
int h[MAXN];
int perm[MAXN];

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

bool used[MAXN];
int max_towers(int l, int r, int d) 
{
    l++; r++;
    std::iota(perm + l, perm + r + 1, l);
    std::sort(perm + l, perm + r + 1, [&](int x, int y)
    {
        return h[x] < h[y];
    });

    int ans = 0;
    for (int i = l ; i <= r ; ++i)
    {
        int max = -1;
        bool can = true;
        int pos = perm[i];
        for (int j = pos - 1 ; j >= l && can ; --j)
        {
            if (used[j])
            {
                if (max - d < std::max(h[j], h[pos]))
                {
                    can = false;
                } else
                {
                    break;
                }
            }

            max = std::max(max, h[j]);
        }

        max = -1;
        for (int j = pos + 1 ; j <= r && can ; ++j)
        {
            if (used[j])
            {
                if (max - d < std::max(h[j], h[pos]))
                {
                    can = false;
                } else
                {
                    break;
                }
            }

            max = std::max(max, h[j]);
        }

        if (can)
        {
            ans++;
            used[pos] = true;
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4096 ms 1144 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 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 220 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 208 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 208 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 208 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 208 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 5 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 304 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 2 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 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 220 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 208 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 208 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 208 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 208 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 5 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 304 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 12 ms 968 KB Output is correct
37 Correct 17 ms 1452 KB Output is correct
38 Correct 12 ms 1440 KB Output is correct
39 Correct 14 ms 1440 KB Output is correct
40 Correct 11 ms 1448 KB Output is correct
41 Correct 20 ms 1472 KB Output is correct
42 Correct 14 ms 1436 KB Output is correct
43 Correct 1287 ms 1444 KB Output is correct
44 Correct 204 ms 1488 KB Output is correct
45 Correct 14 ms 1444 KB Output is correct
46 Correct 12 ms 1412 KB Output is correct
47 Correct 14 ms 1360 KB Output is correct
48 Correct 12 ms 1444 KB Output is correct
49 Correct 11 ms 1448 KB Output is correct
50 Correct 468 ms 1464 KB Output is correct
51 Correct 383 ms 1444 KB Output is correct
52 Correct 22 ms 1564 KB Output is correct
53 Correct 29 ms 1548 KB Output is correct
54 Correct 21 ms 1568 KB Output is correct
55 Execution timed out 4014 ms 1480 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 1476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 720 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 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 220 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 208 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 208 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 208 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 208 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 5 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 304 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 12 ms 968 KB Output is correct
37 Correct 17 ms 1452 KB Output is correct
38 Correct 12 ms 1440 KB Output is correct
39 Correct 14 ms 1440 KB Output is correct
40 Correct 11 ms 1448 KB Output is correct
41 Correct 20 ms 1472 KB Output is correct
42 Correct 14 ms 1436 KB Output is correct
43 Correct 1287 ms 1444 KB Output is correct
44 Correct 204 ms 1488 KB Output is correct
45 Correct 14 ms 1444 KB Output is correct
46 Correct 12 ms 1412 KB Output is correct
47 Correct 14 ms 1360 KB Output is correct
48 Correct 12 ms 1444 KB Output is correct
49 Correct 11 ms 1448 KB Output is correct
50 Correct 468 ms 1464 KB Output is correct
51 Correct 383 ms 1444 KB Output is correct
52 Correct 22 ms 1564 KB Output is correct
53 Correct 29 ms 1548 KB Output is correct
54 Correct 21 ms 1568 KB Output is correct
55 Execution timed out 4014 ms 1480 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4096 ms 1144 KB Time limit exceeded
2 Halted 0 ms 0 KB -