#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e3+10;
int n, hx[N], mx[N][N];
void init(int _n, vector<int> _h) {
n=_n;
for (int i=1; i<=n; ++i) hx[i]=_h[i-1];
for (int i=1; i<=n; ++i) {
mx[i][i]=hx[i];
for (int j=i+1; j<=n; ++j) mx[i][j]=max(mx[i][j-1], hx[j]);
}
}
vector<int> G[N];
bool vis[N];
int dfs(int v) {
vis[v]=true;
int res=1;
for (auto u : G[v]) {
if (vis[u]) continue;
res+=dfs(u);
} return res;
}
int max_towers(int l, int r, int d) {
for (int i=0; i<=n; ++i) G[i].clear();
++l, ++r;
vector<pii> v;
for (int i=l; i<=r; ++i) v.push_back({hx[i], i});
sort(v.begin(), v.end());
bool us[n+1]={};
for (int i=l; i<=r; ++i) us[i]=true;
while (!v.empty()) {
pii x=v.back(); v.pop_back();
bool ok=true;
for (int i=l; i<=r; ++i) {
if (!us[i]) continue;
if (i == x.second) continue;
int j=x.second;
if (abs(i-j) == 1) ok=false;
if (i < j) {
if (max(hx[i], hx[j]) > mx[i+1][j-1]-d) ok=false;
} else {
if (max(hx[i], hx[j]) > mx[j+1][i-1]-d) ok=false;
}
}
if (!ok) us[x.second]=false;
}
int cnt=0;
for (int i=l; i<=r; ++i) cnt+=us[i];
return cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
1492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
8 ms |
15564 KB |
Output is correct |
3 |
Correct |
7 ms |
15448 KB |
Output is correct |
4 |
Correct |
6 ms |
15704 KB |
Output is correct |
5 |
Correct |
7 ms |
15704 KB |
Output is correct |
6 |
Correct |
5 ms |
15448 KB |
Output is correct |
7 |
Correct |
6 ms |
15448 KB |
Output is correct |
8 |
Correct |
5 ms |
15448 KB |
Output is correct |
9 |
Correct |
5 ms |
15692 KB |
Output is correct |
10 |
Correct |
4 ms |
15448 KB |
Output is correct |
11 |
Correct |
5 ms |
15448 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
15704 KB |
Output is correct |
14 |
Correct |
6 ms |
15704 KB |
Output is correct |
15 |
Correct |
5 ms |
15448 KB |
Output is correct |
16 |
Correct |
10 ms |
15956 KB |
Output is correct |
17 |
Correct |
5 ms |
15704 KB |
Output is correct |
18 |
Correct |
4 ms |
15532 KB |
Output is correct |
19 |
Correct |
5 ms |
15448 KB |
Output is correct |
20 |
Correct |
17 ms |
15704 KB |
Output is correct |
21 |
Correct |
15 ms |
15712 KB |
Output is correct |
22 |
Correct |
15 ms |
15704 KB |
Output is correct |
23 |
Correct |
10 ms |
15704 KB |
Output is correct |
24 |
Correct |
12 ms |
15704 KB |
Output is correct |
25 |
Correct |
3 ms |
8792 KB |
Output is correct |
26 |
Correct |
16 ms |
15716 KB |
Output is correct |
27 |
Correct |
14 ms |
15704 KB |
Output is correct |
28 |
Correct |
15 ms |
15712 KB |
Output is correct |
29 |
Correct |
14 ms |
15704 KB |
Output is correct |
30 |
Correct |
13 ms |
15704 KB |
Output is correct |
31 |
Correct |
15 ms |
15716 KB |
Output is correct |
32 |
Correct |
14 ms |
15704 KB |
Output is correct |
33 |
Correct |
11 ms |
15704 KB |
Output is correct |
34 |
Correct |
11 ms |
15704 KB |
Output is correct |
35 |
Correct |
11 ms |
15712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
8 ms |
15564 KB |
Output is correct |
3 |
Correct |
7 ms |
15448 KB |
Output is correct |
4 |
Correct |
6 ms |
15704 KB |
Output is correct |
5 |
Correct |
7 ms |
15704 KB |
Output is correct |
6 |
Correct |
5 ms |
15448 KB |
Output is correct |
7 |
Correct |
6 ms |
15448 KB |
Output is correct |
8 |
Correct |
5 ms |
15448 KB |
Output is correct |
9 |
Correct |
5 ms |
15692 KB |
Output is correct |
10 |
Correct |
4 ms |
15448 KB |
Output is correct |
11 |
Correct |
5 ms |
15448 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
15704 KB |
Output is correct |
14 |
Correct |
6 ms |
15704 KB |
Output is correct |
15 |
Correct |
5 ms |
15448 KB |
Output is correct |
16 |
Correct |
10 ms |
15956 KB |
Output is correct |
17 |
Correct |
5 ms |
15704 KB |
Output is correct |
18 |
Correct |
4 ms |
15532 KB |
Output is correct |
19 |
Correct |
5 ms |
15448 KB |
Output is correct |
20 |
Correct |
17 ms |
15704 KB |
Output is correct |
21 |
Correct |
15 ms |
15712 KB |
Output is correct |
22 |
Correct |
15 ms |
15704 KB |
Output is correct |
23 |
Correct |
10 ms |
15704 KB |
Output is correct |
24 |
Correct |
12 ms |
15704 KB |
Output is correct |
25 |
Correct |
3 ms |
8792 KB |
Output is correct |
26 |
Correct |
16 ms |
15716 KB |
Output is correct |
27 |
Correct |
14 ms |
15704 KB |
Output is correct |
28 |
Correct |
15 ms |
15712 KB |
Output is correct |
29 |
Correct |
14 ms |
15704 KB |
Output is correct |
30 |
Correct |
13 ms |
15704 KB |
Output is correct |
31 |
Correct |
15 ms |
15716 KB |
Output is correct |
32 |
Correct |
14 ms |
15704 KB |
Output is correct |
33 |
Correct |
11 ms |
15704 KB |
Output is correct |
34 |
Correct |
11 ms |
15704 KB |
Output is correct |
35 |
Correct |
11 ms |
15712 KB |
Output is correct |
36 |
Runtime error |
8 ms |
1624 KB |
Execution killed with signal 11 |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
2156 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
828 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
8 ms |
15564 KB |
Output is correct |
3 |
Correct |
7 ms |
15448 KB |
Output is correct |
4 |
Correct |
6 ms |
15704 KB |
Output is correct |
5 |
Correct |
7 ms |
15704 KB |
Output is correct |
6 |
Correct |
5 ms |
15448 KB |
Output is correct |
7 |
Correct |
6 ms |
15448 KB |
Output is correct |
8 |
Correct |
5 ms |
15448 KB |
Output is correct |
9 |
Correct |
5 ms |
15692 KB |
Output is correct |
10 |
Correct |
4 ms |
15448 KB |
Output is correct |
11 |
Correct |
5 ms |
15448 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
15704 KB |
Output is correct |
14 |
Correct |
6 ms |
15704 KB |
Output is correct |
15 |
Correct |
5 ms |
15448 KB |
Output is correct |
16 |
Correct |
10 ms |
15956 KB |
Output is correct |
17 |
Correct |
5 ms |
15704 KB |
Output is correct |
18 |
Correct |
4 ms |
15532 KB |
Output is correct |
19 |
Correct |
5 ms |
15448 KB |
Output is correct |
20 |
Correct |
17 ms |
15704 KB |
Output is correct |
21 |
Correct |
15 ms |
15712 KB |
Output is correct |
22 |
Correct |
15 ms |
15704 KB |
Output is correct |
23 |
Correct |
10 ms |
15704 KB |
Output is correct |
24 |
Correct |
12 ms |
15704 KB |
Output is correct |
25 |
Correct |
3 ms |
8792 KB |
Output is correct |
26 |
Correct |
16 ms |
15716 KB |
Output is correct |
27 |
Correct |
14 ms |
15704 KB |
Output is correct |
28 |
Correct |
15 ms |
15712 KB |
Output is correct |
29 |
Correct |
14 ms |
15704 KB |
Output is correct |
30 |
Correct |
13 ms |
15704 KB |
Output is correct |
31 |
Correct |
15 ms |
15716 KB |
Output is correct |
32 |
Correct |
14 ms |
15704 KB |
Output is correct |
33 |
Correct |
11 ms |
15704 KB |
Output is correct |
34 |
Correct |
11 ms |
15704 KB |
Output is correct |
35 |
Correct |
11 ms |
15712 KB |
Output is correct |
36 |
Runtime error |
8 ms |
1624 KB |
Execution killed with signal 11 |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
1492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |