# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034563 |
2024-07-25T14:53:47 Z |
raphaelp |
Race (IOI11_race) |
C++14 |
|
350 ms |
93268 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
void dfs(long long x, long long p, vector<vector<pair<long long, long long>>> &AR, map<long long, long long> &dp, long long K, long long prof, long long prof2, long long &best)
{
map<long long, long long> M;
M[prof] = prof2;
for (long long i = 0; i < AR[x].size(); i++)
{
if (AR[x][i].first == p)
continue;
dfs(AR[x][i].first, x, AR, dp, K, prof + AR[x][i].second, prof2 + 1, best);
if (dp.size() > M.size())
swap(dp, M);
for (auto j : dp)
{
if (M.count(K - j.first + 2 * prof))
best = min(best, M[K - j.first + 2 * prof] + j.second - 2 * prof2);
}
for (auto j : dp)
{
if (j.first - prof > K)
continue;
if (M[j.first] == 0)
M[j.first] = 100000000;
M[j.first] = min(M[j.first], j.second);
}
}
swap(dp, M);
}
int best_path(int N, int K, int H[][2], int L[])
{
vector<vector<pair<long long, long long>>> AR(N);
for (long long i = 0; i < N - 1; i++)
{
AR[H[i][0]].push_back({H[i][1], L[i]});
AR[H[i][1]].push_back({H[i][0], L[i]});
};
map<long long, long long> dp;
long long best = 100000000;
dfs(0, 0, AR, dp, K, 1, 1, best);
return ((best == 100000000) ? -1 : (int)best);
}
/*int main()
{
int N, K;
cin >> N >> K;
int L[N], H[N][2];
for (long long i = 0; i < N - 1; i++)
{
// cin >> H[i][0] >> H[i][1];
H[i][0] = i, H[i][1] = i + 1;
}
for (long long i = 0; i < N - 1; i++)
{
// cin >> L[i];
L[i] = 1000000;
}
cout << best_path(N, K, H, L);
}*/
Compilation message
race.cpp: In function 'void dfs(long long int, long long int, std::vector<std::vector<std::pair<long long int, long long int> > >&, std::map<long long int, long long int>&, long long int, long long int, long long int, long long int&)':
race.cpp:8:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (long long i = 0; i < AR[x].size(); i++)
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
62 ms |
9252 KB |
Output is correct |
20 |
Correct |
60 ms |
10064 KB |
Output is correct |
21 |
Correct |
63 ms |
9808 KB |
Output is correct |
22 |
Correct |
62 ms |
10328 KB |
Output is correct |
23 |
Correct |
46 ms |
10836 KB |
Output is correct |
24 |
Correct |
49 ms |
9788 KB |
Output is correct |
25 |
Correct |
58 ms |
29752 KB |
Output is correct |
26 |
Correct |
53 ms |
46932 KB |
Output is correct |
27 |
Correct |
97 ms |
19848 KB |
Output is correct |
28 |
Correct |
254 ms |
93268 KB |
Output is correct |
29 |
Correct |
232 ms |
89168 KB |
Output is correct |
30 |
Correct |
93 ms |
20564 KB |
Output is correct |
31 |
Correct |
107 ms |
20560 KB |
Output is correct |
32 |
Correct |
98 ms |
20560 KB |
Output is correct |
33 |
Correct |
113 ms |
20456 KB |
Output is correct |
34 |
Correct |
90 ms |
20256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
62 ms |
9252 KB |
Output is correct |
40 |
Correct |
60 ms |
10064 KB |
Output is correct |
41 |
Correct |
63 ms |
9808 KB |
Output is correct |
42 |
Correct |
62 ms |
10328 KB |
Output is correct |
43 |
Correct |
46 ms |
10836 KB |
Output is correct |
44 |
Correct |
49 ms |
9788 KB |
Output is correct |
45 |
Correct |
58 ms |
29752 KB |
Output is correct |
46 |
Correct |
53 ms |
46932 KB |
Output is correct |
47 |
Correct |
97 ms |
19848 KB |
Output is correct |
48 |
Correct |
254 ms |
93268 KB |
Output is correct |
49 |
Correct |
232 ms |
89168 KB |
Output is correct |
50 |
Correct |
93 ms |
20564 KB |
Output is correct |
51 |
Correct |
107 ms |
20560 KB |
Output is correct |
52 |
Correct |
98 ms |
20560 KB |
Output is correct |
53 |
Correct |
113 ms |
20456 KB |
Output is correct |
54 |
Correct |
90 ms |
20256 KB |
Output is correct |
55 |
Correct |
11 ms |
1628 KB |
Output is correct |
56 |
Correct |
4 ms |
1116 KB |
Output is correct |
57 |
Correct |
40 ms |
9652 KB |
Output is correct |
58 |
Correct |
30 ms |
9664 KB |
Output is correct |
59 |
Correct |
91 ms |
46928 KB |
Output is correct |
60 |
Correct |
268 ms |
91216 KB |
Output is correct |
61 |
Correct |
108 ms |
20164 KB |
Output is correct |
62 |
Correct |
107 ms |
20608 KB |
Output is correct |
63 |
Correct |
114 ms |
20748 KB |
Output is correct |
64 |
Correct |
350 ms |
27308 KB |
Output is correct |
65 |
Correct |
85 ms |
20820 KB |
Output is correct |
66 |
Correct |
244 ms |
76884 KB |
Output is correct |
67 |
Correct |
77 ms |
20156 KB |
Output is correct |
68 |
Correct |
207 ms |
29172 KB |
Output is correct |
69 |
Correct |
248 ms |
30320 KB |
Output is correct |
70 |
Correct |
200 ms |
28424 KB |
Output is correct |