diff --git a/2023206/correct.cpp b/2023206/correct.cpp index f2196ce..c921c5c 100644 --- a/2023206/correct.cpp +++ b/2023206/correct.cpp @@ -1,33 +1,19 @@ #include 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); + for (int j = i + 1; j <= i + K && j < M; j++) { + if (stairs[j] <= stairs[i] + H && stairs[j] >= stairs[i] - H) { + total++; + } } } printf("%lld", total);