#include <bits/stdc++.h>
#include "race.h"
using namespace std;
const int INF = 1e9;
const int NN = 2e5 + 5;
int ans = INF, k;
vector < pair < int, int > > g[NN];
inline void dfs(int v, int sum = 0, int p = -1, int h = 0) {
if (sum > k || h > ans)
return;
if (sum == k) {
ans = min(ans, h);
return;
}
for (auto node : g[v]) {
int to = node.first, len = node.second;
if (to == p)
continue;
dfs(to, sum + len, v, h + 1);
}
}
int best_path(int N, int K, int H[][2], int L[]){
k = K;
for (int i = 0; i < N; ++i) {
// int v = H[i][0], u = H[i][1];
// g[v].push_back({u, L[i]});
// g[u].push_back({v, L[i]});
}
for (int l = 0; l < N; ++l) {
int sum = 0;
for (int r = l; r < N; ++r) {
sum += L[r];
if (sum == K) {
ans = min(ans, r - l + 1);
}
if (sum > K)
break;
}
}
// for (int i = 0; i < N; ++i)
// dfs(i);
if (ans == INF)
ans = -1;
return ans;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
5 ms |
4984 KB |
Output is correct |
9 |
Correct |
5 ms |
4984 KB |
Output is correct |
10 |
Correct |
5 ms |
4984 KB |
Output is correct |
11 |
Correct |
5 ms |
4984 KB |
Output is correct |
12 |
Correct |
5 ms |
4984 KB |
Output is correct |
13 |
Correct |
5 ms |
4984 KB |
Output is correct |
14 |
Correct |
5 ms |
4984 KB |
Output is correct |
15 |
Correct |
5 ms |
4984 KB |
Output is correct |
16 |
Correct |
5 ms |
4984 KB |
Output is correct |
17 |
Correct |
5 ms |
4984 KB |
Output is correct |
18 |
Correct |
5 ms |
4984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
5 ms |
4984 KB |
Output is correct |
9 |
Correct |
5 ms |
4984 KB |
Output is correct |
10 |
Correct |
5 ms |
4984 KB |
Output is correct |
11 |
Correct |
5 ms |
4984 KB |
Output is correct |
12 |
Correct |
5 ms |
4984 KB |
Output is correct |
13 |
Correct |
5 ms |
4984 KB |
Output is correct |
14 |
Correct |
5 ms |
4984 KB |
Output is correct |
15 |
Correct |
5 ms |
4984 KB |
Output is correct |
16 |
Correct |
5 ms |
4984 KB |
Output is correct |
17 |
Correct |
5 ms |
4984 KB |
Output is correct |
18 |
Correct |
5 ms |
4984 KB |
Output is correct |
19 |
Correct |
5 ms |
4984 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Incorrect |
5 ms |
5112 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
5 ms |
4984 KB |
Output is correct |
9 |
Correct |
5 ms |
4984 KB |
Output is correct |
10 |
Correct |
5 ms |
4984 KB |
Output is correct |
11 |
Correct |
5 ms |
4984 KB |
Output is correct |
12 |
Correct |
5 ms |
4984 KB |
Output is correct |
13 |
Correct |
5 ms |
4984 KB |
Output is correct |
14 |
Correct |
5 ms |
4984 KB |
Output is correct |
15 |
Correct |
5 ms |
4984 KB |
Output is correct |
16 |
Correct |
5 ms |
4984 KB |
Output is correct |
17 |
Correct |
5 ms |
4984 KB |
Output is correct |
18 |
Correct |
5 ms |
4984 KB |
Output is correct |
19 |
Incorrect |
35 ms |
7672 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
5 ms |
4984 KB |
Output is correct |
9 |
Correct |
5 ms |
4984 KB |
Output is correct |
10 |
Correct |
5 ms |
4984 KB |
Output is correct |
11 |
Correct |
5 ms |
4984 KB |
Output is correct |
12 |
Correct |
5 ms |
4984 KB |
Output is correct |
13 |
Correct |
5 ms |
4984 KB |
Output is correct |
14 |
Correct |
5 ms |
4984 KB |
Output is correct |
15 |
Correct |
5 ms |
4984 KB |
Output is correct |
16 |
Correct |
5 ms |
4984 KB |
Output is correct |
17 |
Correct |
5 ms |
4984 KB |
Output is correct |
18 |
Correct |
5 ms |
4984 KB |
Output is correct |
19 |
Correct |
5 ms |
4984 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Incorrect |
5 ms |
5112 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |