Submission #366146

# Submission time Handle Problem Language Result Execution time Memory
366146 2021-02-13T10:18:46 Z 79brue Stations (IOI20_stations) C++14
100 / 100
1067 ms 1244 KB
#include <bits/stdc++.h>
#include "stations.h"

using namespace std;

typedef long long ll;

vector<int> link[1002];
bool visited[1002];
int arr[1002];
int sz[1002];

void szd(int x, int par=-1){
    sz[x] = 1;
    for(auto y: link[x]){
        if(y == par) continue;
        szd(y, x);
        sz[x] += sz[y];
    }
}

void dfs(int x, int l, int r, bool chk){
    visited[x] = 1;
    if(chk) arr[x] = l++;
    else arr[x] = r--;
    for(auto y: link[x]){
        if(visited[y]) continue;
        if(chk){
            dfs(y, r-sz[y]+1, r, !chk);
            r -= sz[y];
        }
        else{
            dfs(y, l, l+sz[y]-1, !chk);
            l += sz[y];
        }
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    fill(visited, visited+n, 0);
    fill(arr, arr+n, 0);
    fill(sz, sz+n, 0);
    for(int i=0; i<n; i++) link[i].clear();
    for(int i=0; i<n-1; i++) link[u[i]].push_back(v[i]), link[v[i]].push_back(u[i]);

    szd(0);
    dfs(0, 0, n-1, 1);

    return vector<int> (arr, arr+n);
}

int find_next_station(int s, int t, vector<int> c) {
    if(s == 0){ /// 루트
        sort(c.begin(), c.end());
        for(auto x: c){
            if(t <= x) return x;
        }
        exit(1);
    }
	else if(c[0] > s){ /// 작은 정점
        sort(c.begin(), c.end());
        if(t < s) return c.back();
        for(auto x: c){
            if(t <= x) return x;
        }
        return c.back();
	}
	else{ /// 큰 정점
        sort(c.rbegin(), c.rend());
        if(t > s) return c.back();
        for(auto x: c){
            if(t >= x) return x;
        }
        return c.back();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 731 ms 1136 KB Output is correct
2 Correct 625 ms 1036 KB Output is correct
3 Correct 988 ms 736 KB Output is correct
4 Correct 771 ms 1108 KB Output is correct
5 Correct 663 ms 944 KB Output is correct
6 Correct 477 ms 1020 KB Output is correct
7 Correct 467 ms 896 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 6 ms 864 KB Output is correct
10 Correct 2 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 616 ms 968 KB Output is correct
2 Correct 549 ms 1028 KB Output is correct
3 Correct 1067 ms 992 KB Output is correct
4 Correct 830 ms 992 KB Output is correct
5 Correct 677 ms 864 KB Output is correct
6 Correct 528 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 992 KB Output is correct
2 Correct 563 ms 876 KB Output is correct
3 Correct 927 ms 736 KB Output is correct
4 Correct 723 ms 944 KB Output is correct
5 Correct 696 ms 736 KB Output is correct
6 Correct 493 ms 992 KB Output is correct
7 Correct 449 ms 896 KB Output is correct
8 Correct 3 ms 952 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 1 ms 952 KB Output is correct
11 Correct 599 ms 864 KB Output is correct
12 Correct 497 ms 1196 KB Output is correct
13 Correct 489 ms 1000 KB Output is correct
14 Correct 540 ms 864 KB Output is correct
15 Correct 54 ms 736 KB Output is correct
16 Correct 72 ms 924 KB Output is correct
17 Correct 112 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 925 ms 944 KB Output is correct
2 Correct 822 ms 1072 KB Output is correct
3 Correct 565 ms 992 KB Output is correct
4 Correct 3 ms 864 KB Output is correct
5 Correct 5 ms 864 KB Output is correct
6 Correct 2 ms 864 KB Output is correct
7 Correct 686 ms 944 KB Output is correct
8 Correct 1035 ms 992 KB Output is correct
9 Correct 717 ms 864 KB Output is correct
10 Correct 714 ms 864 KB Output is correct
11 Correct 4 ms 736 KB Output is correct
12 Correct 5 ms 736 KB Output is correct
13 Correct 4 ms 736 KB Output is correct
14 Correct 3 ms 736 KB Output is correct
15 Correct 2 ms 864 KB Output is correct
16 Correct 591 ms 864 KB Output is correct
17 Correct 626 ms 952 KB Output is correct
18 Correct 488 ms 864 KB Output is correct
19 Correct 542 ms 952 KB Output is correct
20 Correct 610 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 576 ms 992 KB Output is correct
2 Correct 520 ms 1076 KB Output is correct
3 Correct 945 ms 1072 KB Output is correct
4 Correct 775 ms 736 KB Output is correct
5 Correct 616 ms 992 KB Output is correct
6 Correct 537 ms 876 KB Output is correct
7 Correct 554 ms 1120 KB Output is correct
8 Correct 2 ms 952 KB Output is correct
9 Correct 4 ms 864 KB Output is correct
10 Correct 2 ms 736 KB Output is correct
11 Correct 461 ms 736 KB Output is correct
12 Correct 598 ms 888 KB Output is correct
13 Correct 990 ms 864 KB Output is correct
14 Correct 660 ms 864 KB Output is correct
15 Correct 621 ms 836 KB Output is correct
16 Correct 521 ms 864 KB Output is correct
17 Correct 594 ms 864 KB Output is correct
18 Correct 425 ms 1096 KB Output is correct
19 Correct 546 ms 1120 KB Output is correct
20 Correct 465 ms 904 KB Output is correct
21 Correct 68 ms 944 KB Output is correct
22 Correct 70 ms 864 KB Output is correct
23 Correct 108 ms 992 KB Output is correct
24 Correct 6 ms 736 KB Output is correct
25 Correct 7 ms 736 KB Output is correct
26 Correct 6 ms 736 KB Output is correct
27 Correct 5 ms 864 KB Output is correct
28 Correct 2 ms 864 KB Output is correct
29 Correct 482 ms 736 KB Output is correct
30 Correct 640 ms 736 KB Output is correct
31 Correct 476 ms 736 KB Output is correct
32 Correct 631 ms 992 KB Output is correct
33 Correct 572 ms 944 KB Output is correct
34 Correct 372 ms 1088 KB Output is correct
35 Correct 503 ms 1012 KB Output is correct
36 Correct 573 ms 992 KB Output is correct
37 Correct 450 ms 1244 KB Output is correct
38 Correct 524 ms 1108 KB Output is correct
39 Correct 498 ms 1100 KB Output is correct
40 Correct 504 ms 1064 KB Output is correct
41 Correct 541 ms 1120 KB Output is correct
42 Correct 77 ms 900 KB Output is correct
43 Correct 123 ms 888 KB Output is correct
44 Correct 139 ms 864 KB Output is correct
45 Correct 210 ms 992 KB Output is correct
46 Correct 337 ms 736 KB Output is correct
47 Correct 334 ms 992 KB Output is correct
48 Correct 80 ms 1096 KB Output is correct
49 Correct 61 ms 1084 KB Output is correct