# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
609196 |
2022-07-27T12:46:11 Z |
Mher |
Stations (IOI20_stations) |
C++14 |
|
1059 ms |
916 KB |
#include <bits/stdc++.h>
#include "stations.h"
#include <vector>
using namespace std;
int sz;
vector<vector<int>> g;
vector<int> labels;
int cnt = 0;
void dfs(int v, int p)
{
int tin = cnt++;
for (int to : g[v])
{
if (to == p)
continue;
dfs(to, v);
}
int tout = cnt++;
labels[v] = (tin % 2 == 0 ? tin : tout) / 2;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
labels = vector<int>(n);
sz = n;
g = vector<vector<int>>(n);
cnt = 0;
for (int i = 0; i < n - 1; i++)
{
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(0, -1);
return labels;
}
bool check(double tin, double tout, int m)
{
return tin <= m && tout >= m;
}
int find_next_station(int s, int t, vector<int> c) {
if (s == 0)
{
for (int i = 1; i < c.size(); i++)
{
if (check(c[i - 1] + .5, c[i], t))
return c[i];
}
return c[0];
}
else if (s > c[0])
{
if (!check(c[1] - .5, s, t))
return c[0];
for (int i = 1; i < c.size() - 1; i++)
{
if (check(c[i], c[i + 1] - .5, t))
return c[i];
}
return c[c.size() - 1];
}
else
{
if (!check(s, c[c.size() - 2] + .5, t))
return c[c.size() - 1];
for (int i = 1; i < c.size() - .5; i++)
{
if (check(c[i - 1] + .5, c[i], t))
return c[i];
}
return c[0];
}
}
/*
1
5 10
0 1
1 2
1 3
2 4
2
2 0 1
1 3 3
*/
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 1; i < c.size(); i++)
| ~~^~~~~~~~~~
stations.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i = 1; i < c.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
521 ms |
652 KB |
Output is correct |
2 |
Correct |
493 ms |
680 KB |
Output is correct |
3 |
Correct |
784 ms |
420 KB |
Output is correct |
4 |
Correct |
685 ms |
420 KB |
Output is correct |
5 |
Correct |
601 ms |
508 KB |
Output is correct |
6 |
Correct |
483 ms |
640 KB |
Output is correct |
7 |
Correct |
376 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
411 ms |
620 KB |
Output is correct |
2 |
Correct |
613 ms |
596 KB |
Output is correct |
3 |
Correct |
1059 ms |
416 KB |
Output is correct |
4 |
Correct |
573 ms |
504 KB |
Output is correct |
5 |
Correct |
464 ms |
492 KB |
Output is correct |
6 |
Correct |
479 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
538 ms |
632 KB |
Output is correct |
2 |
Correct |
478 ms |
672 KB |
Output is correct |
3 |
Correct |
993 ms |
504 KB |
Output is correct |
4 |
Correct |
601 ms |
420 KB |
Output is correct |
5 |
Correct |
627 ms |
420 KB |
Output is correct |
6 |
Correct |
572 ms |
620 KB |
Output is correct |
7 |
Correct |
503 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
472 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
658 ms |
568 KB |
Output is correct |
12 |
Correct |
445 ms |
748 KB |
Output is correct |
13 |
Correct |
491 ms |
916 KB |
Output is correct |
14 |
Correct |
429 ms |
504 KB |
Output is correct |
15 |
Correct |
56 ms |
468 KB |
Output is correct |
16 |
Correct |
51 ms |
720 KB |
Output is correct |
17 |
Correct |
116 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
904 ms |
416 KB |
Output is correct |
2 |
Correct |
658 ms |
416 KB |
Output is correct |
3 |
Correct |
522 ms |
416 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
4 ms |
500 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
554 ms |
508 KB |
Output is correct |
8 |
Correct |
828 ms |
500 KB |
Output is correct |
9 |
Correct |
619 ms |
504 KB |
Output is correct |
10 |
Correct |
600 ms |
416 KB |
Output is correct |
11 |
Correct |
6 ms |
500 KB |
Output is correct |
12 |
Correct |
5 ms |
492 KB |
Output is correct |
13 |
Correct |
3 ms |
500 KB |
Output is correct |
14 |
Correct |
4 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
507 ms |
508 KB |
Output is correct |
17 |
Correct |
515 ms |
500 KB |
Output is correct |
18 |
Correct |
559 ms |
416 KB |
Output is correct |
19 |
Correct |
418 ms |
508 KB |
Output is correct |
20 |
Correct |
500 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
474 ms |
656 KB |
Output is correct |
2 |
Correct |
420 ms |
616 KB |
Output is correct |
3 |
Correct |
869 ms |
444 KB |
Output is correct |
4 |
Correct |
635 ms |
508 KB |
Output is correct |
5 |
Correct |
606 ms |
504 KB |
Output is correct |
6 |
Correct |
428 ms |
548 KB |
Output is correct |
7 |
Correct |
477 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
544 KB |
Output is correct |
10 |
Correct |
0 ms |
504 KB |
Output is correct |
11 |
Correct |
435 ms |
688 KB |
Output is correct |
12 |
Correct |
471 ms |
544 KB |
Output is correct |
13 |
Correct |
870 ms |
420 KB |
Output is correct |
14 |
Correct |
692 ms |
508 KB |
Output is correct |
15 |
Correct |
595 ms |
416 KB |
Output is correct |
16 |
Correct |
453 ms |
508 KB |
Output is correct |
17 |
Correct |
492 ms |
416 KB |
Output is correct |
18 |
Correct |
465 ms |
740 KB |
Output is correct |
19 |
Correct |
476 ms |
708 KB |
Output is correct |
20 |
Correct |
332 ms |
500 KB |
Output is correct |
21 |
Correct |
59 ms |
436 KB |
Output is correct |
22 |
Correct |
95 ms |
564 KB |
Output is correct |
23 |
Correct |
97 ms |
620 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
7 ms |
472 KB |
Output is correct |
27 |
Correct |
5 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
642 ms |
416 KB |
Output is correct |
30 |
Correct |
675 ms |
500 KB |
Output is correct |
31 |
Correct |
679 ms |
552 KB |
Output is correct |
32 |
Correct |
631 ms |
420 KB |
Output is correct |
33 |
Correct |
535 ms |
416 KB |
Output is correct |
34 |
Correct |
301 ms |
628 KB |
Output is correct |
35 |
Correct |
540 ms |
812 KB |
Output is correct |
36 |
Correct |
427 ms |
788 KB |
Output is correct |
37 |
Correct |
413 ms |
628 KB |
Output is correct |
38 |
Correct |
437 ms |
704 KB |
Output is correct |
39 |
Correct |
451 ms |
752 KB |
Output is correct |
40 |
Correct |
436 ms |
720 KB |
Output is correct |
41 |
Correct |
438 ms |
840 KB |
Output is correct |
42 |
Correct |
66 ms |
720 KB |
Output is correct |
43 |
Correct |
91 ms |
572 KB |
Output is correct |
44 |
Correct |
126 ms |
716 KB |
Output is correct |
45 |
Correct |
144 ms |
592 KB |
Output is correct |
46 |
Correct |
286 ms |
504 KB |
Output is correct |
47 |
Correct |
269 ms |
544 KB |
Output is correct |
48 |
Correct |
46 ms |
600 KB |
Output is correct |
49 |
Correct |
61 ms |
664 KB |
Output is correct |