Submission #415674

# Submission time Handle Problem Language Result Execution time Memory
415674 2021-06-01T11:02:53 Z Odavey Stations (IOI20_stations) C++14
100 / 100
1390 ms 796 KB
//
// ~oisín~ C++ Template
//

#include                <bits/stdc++.h>
#define MX_N            1005
#define mp              make_pair
#define mod7            1000000007
#define modpi           314159
#define PI              3.141592653589793238
#define pb              push_back
#define FastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define All(a)          a.begin(),a.end()
#define fi              first
#define se              second
#define ll              long long int
#define ull             unsigned long long int

int kx[8]  =            {+2, +2, -2, -2, +1, +1, -1, -1};
int ky[8]  =            {+1, -1, +1, -1, +2, -2, +2, -2};
int d9x[9] =            {+1, +1, +1, +0, +0, +0, -1, -1, -1};
int d9y[9] =            {+1, +0, -1, +1, +0, -1, +1, +0, -1};
int dx4[4] =            {+0, +0, +1, -1};
int dy4[4] =            {+1, -1, +0, +0};

ll gcd(ull a, ull b){
    return (a==0)?b:gcd(b%a,a);
}

ll lcm(ull a, ull b){
    return a*(b/gcd(a,b));
}

const long long INF = 1e18;

using namespace std;

vector<int> adj[MX_N];
int glit = 0;
int in[MX_N], out[MX_N];
int p[MX_N];
int l[MX_N];

void fill(int at, int d){
    in[at] = glit++;
    for(int to : adj[at]){
        if(p[at] == to){
            continue;
        }
        p[to] = at;
        fill(to, d+1);
    }
    out[at] = glit++;
    l[at] = (d%2)?out[at]:in[at];
    return;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){
    for(int i=0;i<n;++i){
        adj[i] = {};
    }
    for(int i=0;i<n-1;++i){
        adj[u[i]].pb(v[i]);
        adj[v[i]].pb(u[i]);
    }
    fill(0, 0);
    int tmp[n];
    int rank[glit+1];
    memcpy(tmp, l, sizeof(tmp));
    sort(tmp, tmp+n);
    for(int i=0;i<n;++i){
        rank[tmp[i]] = i;
    }
    vector<int> ans;
    for(int i=0;i<n;++i){
        ans.pb(rank[l[i]]);
    }
    return ans;
}

int find_next_station(int s, int t, vector<int> c){
    if(s < c.front()){
        if(t < s){
            return c.back();
        }else{
            int lo = 0;
            int hi = c.size()-1;
            while(lo < hi){
                int mid = lo + (hi-lo)/2;
                if(t <= c[mid]){
                    hi = mid;
                }else{
                    lo = mid+1;
                }
            }
            return c[lo];
        }
    }else{
        if(t > s){
            return c.front();
        }else{
            int lo = 0;
            int hi = c.size()-1;
            while(lo < hi){
                int mid = lo + (hi-lo+1)/2;
                if(t >= c[mid]){
                    lo = mid;
                }else{
                    hi = mid-1;
                }
            }
            return c[lo];
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 616 ms 636 KB Output is correct
2 Correct 423 ms 636 KB Output is correct
3 Correct 1008 ms 508 KB Output is correct
4 Correct 791 ms 520 KB Output is correct
5 Correct 994 ms 516 KB Output is correct
6 Correct 545 ms 636 KB Output is correct
7 Correct 464 ms 516 KB Output is correct
8 Correct 5 ms 576 KB Output is correct
9 Correct 10 ms 548 KB Output is correct
10 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 708 ms 660 KB Output is correct
2 Correct 893 ms 516 KB Output is correct
3 Correct 1390 ms 528 KB Output is correct
4 Correct 859 ms 516 KB Output is correct
5 Correct 741 ms 508 KB Output is correct
6 Correct 659 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 928 ms 636 KB Output is correct
2 Correct 588 ms 656 KB Output is correct
3 Correct 1033 ms 500 KB Output is correct
4 Correct 593 ms 680 KB Output is correct
5 Correct 770 ms 520 KB Output is correct
6 Correct 564 ms 640 KB Output is correct
7 Correct 607 ms 528 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 3 ms 528 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 808 ms 508 KB Output is correct
12 Correct 597 ms 752 KB Output is correct
13 Correct 573 ms 748 KB Output is correct
14 Correct 705 ms 532 KB Output is correct
15 Correct 56 ms 548 KB Output is correct
16 Correct 78 ms 528 KB Output is correct
17 Correct 155 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1151 ms 500 KB Output is correct
2 Correct 1111 ms 492 KB Output is correct
3 Correct 651 ms 528 KB Output is correct
4 Correct 6 ms 596 KB Output is correct
5 Correct 6 ms 576 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 689 ms 712 KB Output is correct
8 Correct 1106 ms 512 KB Output is correct
9 Correct 913 ms 508 KB Output is correct
10 Correct 884 ms 512 KB Output is correct
11 Correct 9 ms 528 KB Output is correct
12 Correct 12 ms 596 KB Output is correct
13 Correct 6 ms 616 KB Output is correct
14 Correct 6 ms 548 KB Output is correct
15 Correct 4 ms 652 KB Output is correct
16 Correct 720 ms 644 KB Output is correct
17 Correct 586 ms 512 KB Output is correct
18 Correct 771 ms 516 KB Output is correct
19 Correct 670 ms 528 KB Output is correct
20 Correct 843 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 660 ms 644 KB Output is correct
2 Correct 635 ms 620 KB Output is correct
3 Correct 1020 ms 496 KB Output is correct
4 Correct 839 ms 496 KB Output is correct
5 Correct 812 ms 512 KB Output is correct
6 Correct 600 ms 648 KB Output is correct
7 Correct 580 ms 528 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 6 ms 560 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 450 ms 576 KB Output is correct
12 Correct 897 ms 560 KB Output is correct
13 Correct 834 ms 708 KB Output is correct
14 Correct 931 ms 516 KB Output is correct
15 Correct 716 ms 600 KB Output is correct
16 Correct 648 ms 576 KB Output is correct
17 Correct 704 ms 492 KB Output is correct
18 Correct 560 ms 740 KB Output is correct
19 Correct 666 ms 748 KB Output is correct
20 Correct 538 ms 508 KB Output is correct
21 Correct 52 ms 560 KB Output is correct
22 Correct 69 ms 516 KB Output is correct
23 Correct 132 ms 772 KB Output is correct
24 Correct 7 ms 632 KB Output is correct
25 Correct 6 ms 596 KB Output is correct
26 Correct 7 ms 576 KB Output is correct
27 Correct 9 ms 588 KB Output is correct
28 Correct 2 ms 744 KB Output is correct
29 Correct 765 ms 516 KB Output is correct
30 Correct 671 ms 528 KB Output is correct
31 Correct 478 ms 516 KB Output is correct
32 Correct 599 ms 528 KB Output is correct
33 Correct 618 ms 512 KB Output is correct
34 Correct 307 ms 640 KB Output is correct
35 Correct 714 ms 764 KB Output is correct
36 Correct 673 ms 748 KB Output is correct
37 Correct 666 ms 752 KB Output is correct
38 Correct 488 ms 736 KB Output is correct
39 Correct 656 ms 772 KB Output is correct
40 Correct 702 ms 748 KB Output is correct
41 Correct 438 ms 744 KB Output is correct
42 Correct 107 ms 648 KB Output is correct
43 Correct 154 ms 644 KB Output is correct
44 Correct 185 ms 652 KB Output is correct
45 Correct 257 ms 620 KB Output is correct
46 Correct 643 ms 604 KB Output is correct
47 Correct 403 ms 620 KB Output is correct
48 Correct 102 ms 784 KB Output is correct
49 Correct 56 ms 796 KB Output is correct