답안 #850939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850939 2023-09-18T00:36:15 Z olnyfcxwps 송신탑 (IOI22_towers) C++17
11 / 100
4000 ms 2636 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 picked[100000];

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;
    }
}

bool cmp(struct Tower t1, struct Tower t2) {
    return t1.h < t2.h;
}

int max_towers(int L, int R, int D) {
    int k = 0;
    while (k < tower_cnt-1 and height[k] < height[k+1]){
        k += 1;
    }
    bool ok = true;
    for (int i = k;i < tower_cnt-1;i++){
        if (height[i] <= height[i+1]){
            ok = false;
        }
    }
    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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1983 ms 1456 KB Output is correct
2 Execution timed out 4006 ms 2384 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 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 0 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 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 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 1 ms 344 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 1 ms 344 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 596 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 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 0 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 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 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 1 ms 344 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 1 ms 344 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 596 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 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 319 ms 1624 KB Output is correct
37 Correct 228 ms 2544 KB Output is correct
38 Correct 111 ms 2636 KB Output is correct
39 Correct 56 ms 2376 KB Output is correct
40 Correct 125 ms 2392 KB Output is correct
41 Execution timed out 4043 ms 2164 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4009 ms 2392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4029 ms 920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 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 0 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 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 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 1 ms 344 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 1 ms 344 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 596 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 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 319 ms 1624 KB Output is correct
37 Correct 228 ms 2544 KB Output is correct
38 Correct 111 ms 2636 KB Output is correct
39 Correct 56 ms 2376 KB Output is correct
40 Correct 125 ms 2392 KB Output is correct
41 Execution timed out 4043 ms 2164 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1983 ms 1456 KB Output is correct
2 Execution timed out 4006 ms 2384 KB Time limit exceeded
3 Halted 0 ms 0 KB -