Submission #832482

# Submission time Handle Problem Language Result Execution time Memory
832482 2023-08-21T10:48:02 Z fatemetmhr Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 5984 KB
// komak!

#include "towers.h"
#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
#define mp       make_pair
#define pb       push_back

typedef long long ll;

const ll mod   = 1e9 + 7;
const int maxn5 = 1e5 + 10;

int mxid, h[maxn5];
int n, dp[maxn5], dp2[maxn5];
pair <int, int> per[maxn5];

void solve(int l, int r, int d){
    if(r <= l)
        return;
    int mid = l;
    for(int i = l + 1; i < r; i++)
        if(h[i] > h[mid])
            mid = i;
    solve(l, mid, d);
    solve(mid + 1, r, d);
    for(int i = l; i < r; i++)
        per[i] = {h[i], i};
    sort(per + l, per + r);
    int mx1 = 0, mx2 = 0;
    for(int i = l; i < r; i++){
        if(per[i].se < mid)
            mx1 = max(mx1, dp[per[i].se]);
        if(per[i].se > mid)
            mx2 = max(mx2, dp[per[i].se]);
        dp2[i] = max(mx1, mx2);
        if(per[i].fi + d <= per[r - 1].fi)
            dp2[i] = mx1 + mx2;
    }
    dp2[r - 1] = max(dp2[r - 1], 1);
    for(int i = l; i < r; i++){
        h[i] = per[i].fi;
        dp[i] = dp2[i];
    }
}

void init(int N, std::vector<int> H) {

    mxid = 0;
    n = N;
    for(int i = 0; i < n; i++){
        h[i] = H[i];
        if(h[i] > h[mxid])
            mxid = i;
    }

}

int max_towers(int l, int r, int d) {

    solve(l, r + 1, d);
    return (*max_element(dp, dp + n));

}
# Verdict Execution time Memory Grader output
1 Execution timed out 4041 ms 3276 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 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 1 ms 368 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 25 ms 532 KB Output is correct
24 Correct 24 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 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 336 KB Output is correct
32 Correct 28 ms 464 KB Output is correct
33 Correct 27 ms 536 KB Output is correct
34 Correct 24 ms 484 KB Output is correct
35 Correct 23 ms 532 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 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 1 ms 368 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 25 ms 532 KB Output is correct
24 Correct 24 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 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 336 KB Output is correct
32 Correct 28 ms 464 KB Output is correct
33 Correct 27 ms 536 KB Output is correct
34 Correct 24 ms 484 KB Output is correct
35 Correct 23 ms 532 KB Output is correct
36 Correct 20 ms 1104 KB Output is correct
37 Correct 31 ms 1596 KB Output is correct
38 Correct 19 ms 1456 KB Output is correct
39 Correct 35 ms 1484 KB Output is correct
40 Correct 15 ms 1444 KB Output is correct
41 Correct 72 ms 2340 KB Output is correct
42 Correct 9 ms 1464 KB Output is correct
43 Execution timed out 4054 ms 5984 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4054 ms 5092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4073 ms 3164 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 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 1 ms 368 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 25 ms 532 KB Output is correct
24 Correct 24 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 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 336 KB Output is correct
32 Correct 28 ms 464 KB Output is correct
33 Correct 27 ms 536 KB Output is correct
34 Correct 24 ms 484 KB Output is correct
35 Correct 23 ms 532 KB Output is correct
36 Correct 20 ms 1104 KB Output is correct
37 Correct 31 ms 1596 KB Output is correct
38 Correct 19 ms 1456 KB Output is correct
39 Correct 35 ms 1484 KB Output is correct
40 Correct 15 ms 1444 KB Output is correct
41 Correct 72 ms 2340 KB Output is correct
42 Correct 9 ms 1464 KB Output is correct
43 Execution timed out 4054 ms 5984 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4041 ms 3276 KB Time limit exceeded
2 Halted 0 ms 0 KB -