Submission #850940

# Submission time Handle Problem Language Result Execution time Memory
850940 2023-09-18T00:42:06 Z olnyfcxwps Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 2384 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Tower {
    int pos;
    int h;
}towers[100000];

int height[100000];
int tower_cnt;
bool ok;
bool picked[100000];
int k;

void init(int N, vector<int> H) {
    tower_cnt = N;
    for (int i = 0; i < N; i++) {
        height[i] = H[i];
        towers[i].h = H[i];
        towers[i].pos = i;
    }
}
void special_case(){
    while (k < tower_cnt-1 and height[k] < height[k+1]){
        k += 1;
    }
    for (int i = k;i < tower_cnt-1;i++){
        if (height[i] <= height[i+1]){
            ok = false;
        }
    }
}
bool cmp(struct Tower t1, struct Tower t2) {
    return t1.h < t2.h;
}

int max_towers(int L, int R, int D) {
    special_case();
    if (ok){
        if ((L <= k and R <= k) or (L >= k and R >= k)){
            return 1;
        }
        else if (height[L] <= height[k]-D and height[R] <= height[k]-D){
            return 2;
        }else{
            return 1;
        }
    }else {
        int ans = 0;
        sort(towers, towers + tower_cnt, cmp);
        /*for (int i = 0; i < tower_cnt; i++) {
            cout << towers[i].pos << "\n";
        }*/
        for (int i = 0; i < tower_cnt; i++) {
            int pos = towers[i].pos;
            if (pos < L || pos > R) {
                continue;
            }
            int h = towers[i].h;
            bool valid = true;

            int max_left = h;
            for (int j = pos - 1; j >= L; j--) {
                if (picked[j]) {
                    if (max_left - D < height[j] || max_left - D < h) {
                        valid = false;
                        break;
                    }
                }
                if (height[j] > max_left) {
                    max_left = height[j];
                }
            }

            int max_right = h;
            for (int j = pos + 1; j <= R; j++) {
                if (picked[j]) {
                    if (max_right - D < height[j] || max_right - D < h) {
                        valid = false;
                        break;
                    }
                }
                if (height[j] > max_right) {
                    max_right = height[j];
                }
            }

            if (valid) {
                picked[pos] = true;
                // cout << pos << "\n";
                ans += 1;
            }
        }
        return ans;
    }
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4032 ms 1644 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 1 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 344 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 596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 488 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 4 ms 596 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 1 ms 396 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 4 ms 488 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 3 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 1 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 344 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 596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 488 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 4 ms 596 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 1 ms 396 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 4 ms 488 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 321 ms 1728 KB Output is correct
37 Correct 220 ms 2376 KB Output is correct
38 Correct 113 ms 2312 KB Output is correct
39 Correct 58 ms 2376 KB Output is correct
40 Correct 131 ms 2384 KB Output is correct
41 Execution timed out 4006 ms 2380 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4051 ms 2372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4048 ms 924 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 1 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 344 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 596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 488 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 4 ms 596 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 1 ms 396 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 4 ms 488 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 321 ms 1728 KB Output is correct
37 Correct 220 ms 2376 KB Output is correct
38 Correct 113 ms 2312 KB Output is correct
39 Correct 58 ms 2376 KB Output is correct
40 Correct 131 ms 2384 KB Output is correct
41 Execution timed out 4006 ms 2380 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4032 ms 1644 KB Time limit exceeded
2 Halted 0 ms 0 KB -