Submission #395997

# Submission time Handle Problem Language Result Execution time Memory
395997 2021-04-29T10:40:01 Z benedict0724 Stations (IOI20_stations) C++17
100 / 100
1101 ms 756 KB
#include "stations.h"
#include <vector>
#include <algorithm>

using namespace std;
vector<int> adj[1000];
vector<int> labels;
int sub[1000];

void dfs1(int x, int p)
{
    sub[x] = 1;
    for(int i : adj[x])
    {
        if(i == p) continue;
        dfs1(i, x);
        sub[x] += sub[i];
    }
}

void dfs2(int x, int p, int d, int l, int r){
    if(d == 0) labels[x] = l;
    else labels[x] = r;

    int tmp = l;
    if(d == 0) tmp = l + 1;
    for(int i : adj[x])
    {
        if(i == p) continue;
        dfs2(i, x, !d, tmp, tmp + sub[i] - 1);
        tmp += sub[i];
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    labels.resize(n);
    for(int i=0;i<n;i++) adj[i].clear();
	for(int i=0;i<n-1;i++){
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
	}
	dfs1(0, -1);
	dfs2(0, -1, 0, 0, n-1);
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    int k = c.size() - 1;
    int m = c[0], M = c[k];

    if(m > s)
    {
        if(t < s) return M;
        for(int i=0;i<k;i++)
        {
            if(t <= c[i]) return c[i];
        }

        return M;
    }

    if(t > s) return m;
    for(int i=k;i>0;i--)
    {
        if(t >= c[i]) return c[i];
    }

    return m;
}
# Verdict Execution time Memory Grader output
1 Correct 641 ms 656 KB Output is correct
2 Correct 438 ms 612 KB Output is correct
3 Correct 1101 ms 400 KB Output is correct
4 Correct 759 ms 532 KB Output is correct
5 Correct 615 ms 400 KB Output is correct
6 Correct 552 ms 528 KB Output is correct
7 Correct 630 ms 528 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 6 ms 500 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 576 ms 572 KB Output is correct
2 Correct 622 ms 528 KB Output is correct
3 Correct 1041 ms 488 KB Output is correct
4 Correct 745 ms 400 KB Output is correct
5 Correct 716 ms 404 KB Output is correct
6 Correct 514 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 666 ms 644 KB Output is correct
2 Correct 551 ms 628 KB Output is correct
3 Correct 1037 ms 492 KB Output is correct
4 Correct 726 ms 400 KB Output is correct
5 Correct 591 ms 508 KB Output is correct
6 Correct 501 ms 532 KB Output is correct
7 Correct 487 ms 624 KB Output is correct
8 Correct 2 ms 480 KB Output is correct
9 Correct 5 ms 472 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 770 ms 520 KB Output is correct
12 Correct 601 ms 756 KB Output is correct
13 Correct 532 ms 496 KB Output is correct
14 Correct 599 ms 528 KB Output is correct
15 Correct 61 ms 456 KB Output is correct
16 Correct 86 ms 588 KB Output is correct
17 Correct 108 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 945 ms 508 KB Output is correct
2 Correct 877 ms 400 KB Output is correct
3 Correct 692 ms 400 KB Output is correct
4 Correct 3 ms 472 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 581 ms 400 KB Output is correct
8 Correct 908 ms 400 KB Output is correct
9 Correct 795 ms 400 KB Output is correct
10 Correct 652 ms 540 KB Output is correct
11 Correct 6 ms 480 KB Output is correct
12 Correct 5 ms 472 KB Output is correct
13 Correct 4 ms 472 KB Output is correct
14 Correct 5 ms 476 KB Output is correct
15 Correct 2 ms 472 KB Output is correct
16 Correct 695 ms 400 KB Output is correct
17 Correct 525 ms 400 KB Output is correct
18 Correct 548 ms 400 KB Output is correct
19 Correct 569 ms 528 KB Output is correct
20 Correct 540 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 618 ms 668 KB Output is correct
2 Correct 499 ms 632 KB Output is correct
3 Correct 913 ms 400 KB Output is correct
4 Correct 736 ms 504 KB Output is correct
5 Correct 737 ms 628 KB Output is correct
6 Correct 514 ms 632 KB Output is correct
7 Correct 537 ms 524 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 5 ms 472 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 506 ms 656 KB Output is correct
12 Correct 589 ms 656 KB Output is correct
13 Correct 867 ms 400 KB Output is correct
14 Correct 780 ms 528 KB Output is correct
15 Correct 598 ms 672 KB Output is correct
16 Correct 464 ms 504 KB Output is correct
17 Correct 788 ms 400 KB Output is correct
18 Correct 622 ms 632 KB Output is correct
19 Correct 571 ms 616 KB Output is correct
20 Correct 524 ms 528 KB Output is correct
21 Correct 60 ms 424 KB Output is correct
22 Correct 78 ms 528 KB Output is correct
23 Correct 144 ms 536 KB Output is correct
24 Correct 7 ms 472 KB Output is correct
25 Correct 5 ms 472 KB Output is correct
26 Correct 5 ms 472 KB Output is correct
27 Correct 4 ms 472 KB Output is correct
28 Correct 2 ms 472 KB Output is correct
29 Correct 628 ms 508 KB Output is correct
30 Correct 587 ms 400 KB Output is correct
31 Correct 543 ms 508 KB Output is correct
32 Correct 575 ms 508 KB Output is correct
33 Correct 563 ms 520 KB Output is correct
34 Correct 371 ms 528 KB Output is correct
35 Correct 458 ms 636 KB Output is correct
36 Correct 512 ms 528 KB Output is correct
37 Correct 490 ms 624 KB Output is correct
38 Correct 484 ms 628 KB Output is correct
39 Correct 528 ms 752 KB Output is correct
40 Correct 472 ms 636 KB Output is correct
41 Correct 471 ms 608 KB Output is correct
42 Correct 67 ms 548 KB Output is correct
43 Correct 135 ms 532 KB Output is correct
44 Correct 114 ms 528 KB Output is correct
45 Correct 192 ms 556 KB Output is correct
46 Correct 329 ms 528 KB Output is correct
47 Correct 301 ms 508 KB Output is correct
48 Correct 71 ms 544 KB Output is correct
49 Correct 66 ms 656 KB Output is correct