답안 #850942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850942 2023-09-18T00:48:43 Z olnyfcxwps 송신탑 (IOI22_towers) C++17
15 / 100
4000 ms 2552 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 special_case(){
    while (k < tower_cnt-1 and height[k] < height[k+1]){
        k += 1;
    }
    ok = true;
    for (int i = k;i < tower_cnt-1;i++){
        if (height[i] <= height[i+1]){
            ok = false;
        }
    }
}
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;
    }
    special_case();
}

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

int max_towers(int L, int R, int D) {
    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 260 ms 1456 KB Output is correct
2 Correct 571 ms 2536 KB Output is correct
3 Correct 547 ms 2376 KB Output is correct
4 Correct 590 ms 2552 KB Output is correct
5 Correct 575 ms 2380 KB Output is correct
6 Correct 560 ms 2392 KB Output is correct
7 Correct 540 ms 2380 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 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 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 4 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 340 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 5 ms 488 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 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 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 4 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 340 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 5 ms 488 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 317 ms 1732 KB Output is correct
37 Correct 222 ms 2380 KB Output is correct
38 Correct 110 ms 2380 KB Output is correct
39 Correct 55 ms 2384 KB Output is correct
40 Correct 123 ms 2384 KB Output is correct
41 Execution timed out 4027 ms 2376 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4073 ms 2368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4042 ms 924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 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 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 4 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 340 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 5 ms 488 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 317 ms 1732 KB Output is correct
37 Correct 222 ms 2380 KB Output is correct
38 Correct 110 ms 2380 KB Output is correct
39 Correct 55 ms 2384 KB Output is correct
40 Correct 123 ms 2384 KB Output is correct
41 Execution timed out 4027 ms 2376 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 1456 KB Output is correct
2 Correct 571 ms 2536 KB Output is correct
3 Correct 547 ms 2376 KB Output is correct
4 Correct 590 ms 2552 KB Output is correct
5 Correct 575 ms 2380 KB Output is correct
6 Correct 560 ms 2392 KB Output is correct
7 Correct 540 ms 2380 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 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 1 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 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 3 ms 344 KB Output is correct
31 Correct 3 ms 344 KB Output is correct
32 Correct 4 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 3 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 2 ms 344 KB Output is correct
38 Correct 2 ms 344 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 0 ms 596 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 5 ms 488 KB Output is correct
45 Correct 3 ms 344 KB Output is correct
46 Correct 317 ms 1732 KB Output is correct
47 Correct 222 ms 2380 KB Output is correct
48 Correct 110 ms 2380 KB Output is correct
49 Correct 55 ms 2384 KB Output is correct
50 Correct 123 ms 2384 KB Output is correct
51 Execution timed out 4027 ms 2376 KB Time limit exceeded
52 Halted 0 ms 0 KB -