Many TLE.
This commit is contained in:
35
2023206/main.cpp
Normal file
35
2023206/main.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
int* stairs = NULL;
|
||||||
|
bool* visited = NULL;
|
||||||
|
int M, K, H;
|
||||||
|
long long total = 0;
|
||||||
|
|
||||||
|
int dfs(int start) {
|
||||||
|
if (visited[start]) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
visited[start] = true;
|
||||||
|
for (int i = 1; start + i < M && i <= K; i++) {
|
||||||
|
if (((stairs[start + i] - stairs[start]) < 0 ? stairs[start] - stairs[start + i] : stairs[start + i] - stairs[start]) <= H) {
|
||||||
|
total++;
|
||||||
|
dfs(start + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
scanf("%d %d %d", &M , &K, &H);
|
||||||
|
stairs = new int[M];
|
||||||
|
visited = new bool[M];
|
||||||
|
for (int i = 0; i < M ; i++) {
|
||||||
|
scanf("%d", &stairs[i]);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < M; i++) {
|
||||||
|
if (!visited[i]) {
|
||||||
|
dfs(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%lld", total);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user