Submission #305105

# Submission time Handle Problem Language Result Execution time Memory
305105 2020-09-22T15:13:32 Z Bench0310 Stations (IOI20_stations) C++17
100 / 100
1166 ms 1120 KB
#include <bits/stdc++.h>
#include "stations.h"

using namespace std;
typedef long long ll;

const int N=1000;
vector<int> v[N];
vector<int> depth(N,0);
vector<int> tin(N,0);
vector<int> tout(N,0);
int tcnt=0;

void dfs(int a,int p=-1)
{
    if(p!=-1) depth[a]=depth[p]+1;
    tin[a]=tcnt++;
    for(int to:v[a])
    {
        if(to==p) continue;
        dfs(to,a);
    }
    tout[a]=tcnt-1;
}

vector<int> label(int n,int k,vector<int> a,vector<int> b)
{
    for(int i=0;i<n;i++)
    {
        v[i].clear();
        depth[i]=tin[i]=tout[i]=0;
    }
    tcnt=0;
    for(int i=0;i<n-1;i++)
    {
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }
    dfs(0);
    vector<int> res(n,0);
    vector<array<int,3>> z(n);
    for(int i=0;i<n;i++) z[i]={((depth[i]%2)==0?tin[i]:tout[i]),depth[i],i};
    sort(z.begin(),z.end(),[](array<int,3> x,array<int,3> y)->bool{return (x[0]<y[0]||(x[0]==y[0]&&x[1]>y[1]));});
    for(int i=0;i<n;i++) res[z[i][2]]=i;
    return res;
}

int find_next_station(int s,int t,vector<int> c)
{
    if(c.size()==1) return c[0];
    if(s==0)
    {
        for(int a:c) if(t<=a) return a;
    }
    else if(s<c[0]) //tin
    {
        if(!(s<=t&&t<=c[c.size()-2])) return c.back();
        for(int a:c) if(t<=a) return a;
    }
    else //tout
    {
        if(!(c[1]<=t&&t<=s)) return c[0];
        reverse(c.begin(),c.end());
        for(int a:c) if(a<=t) return a;
    }
}

//int main()
//{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
//    
//    return 0;
//}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
   66 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 646 ms 912 KB Output is correct
2 Correct 533 ms 832 KB Output is correct
3 Correct 1071 ms 768 KB Output is correct
4 Correct 826 ms 776 KB Output is correct
5 Correct 729 ms 768 KB Output is correct
6 Correct 539 ms 816 KB Output is correct
7 Correct 600 ms 768 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 768 KB Output is correct
2 Correct 640 ms 768 KB Output is correct
3 Correct 1061 ms 768 KB Output is correct
4 Correct 889 ms 672 KB Output is correct
5 Correct 705 ms 800 KB Output is correct
6 Correct 638 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 626 ms 1008 KB Output is correct
2 Correct 457 ms 824 KB Output is correct
3 Correct 901 ms 868 KB Output is correct
4 Correct 967 ms 780 KB Output is correct
5 Correct 713 ms 896 KB Output is correct
6 Correct 660 ms 816 KB Output is correct
7 Correct 603 ms 816 KB Output is correct
8 Correct 3 ms 868 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
11 Correct 916 ms 896 KB Output is correct
12 Correct 555 ms 1024 KB Output is correct
13 Correct 579 ms 912 KB Output is correct
14 Correct 509 ms 832 KB Output is correct
15 Correct 76 ms 896 KB Output is correct
16 Correct 88 ms 768 KB Output is correct
17 Correct 161 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1160 ms 1008 KB Output is correct
2 Correct 771 ms 800 KB Output is correct
3 Correct 654 ms 896 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 715 ms 896 KB Output is correct
8 Correct 1166 ms 792 KB Output is correct
9 Correct 898 ms 768 KB Output is correct
10 Correct 760 ms 768 KB Output is correct
11 Correct 7 ms 776 KB Output is correct
12 Correct 7 ms 896 KB Output is correct
13 Correct 3 ms 896 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 666 ms 768 KB Output is correct
17 Correct 684 ms 768 KB Output is correct
18 Correct 730 ms 896 KB Output is correct
19 Correct 562 ms 816 KB Output is correct
20 Correct 603 ms 1008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 699 ms 1024 KB Output is correct
2 Correct 510 ms 1016 KB Output is correct
3 Correct 1041 ms 904 KB Output is correct
4 Correct 877 ms 808 KB Output is correct
5 Correct 790 ms 768 KB Output is correct
6 Correct 637 ms 1008 KB Output is correct
7 Correct 548 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 780 KB Output is correct
11 Correct 530 ms 768 KB Output is correct
12 Correct 609 ms 768 KB Output is correct
13 Correct 1019 ms 768 KB Output is correct
14 Correct 925 ms 896 KB Output is correct
15 Correct 762 ms 808 KB Output is correct
16 Correct 505 ms 880 KB Output is correct
17 Correct 748 ms 896 KB Output is correct
18 Correct 656 ms 916 KB Output is correct
19 Correct 663 ms 992 KB Output is correct
20 Correct 560 ms 896 KB Output is correct
21 Correct 61 ms 768 KB Output is correct
22 Correct 78 ms 884 KB Output is correct
23 Correct 134 ms 896 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 5 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 2 ms 868 KB Output is correct
29 Correct 639 ms 768 KB Output is correct
30 Correct 552 ms 768 KB Output is correct
31 Correct 780 ms 896 KB Output is correct
32 Correct 573 ms 816 KB Output is correct
33 Correct 627 ms 780 KB Output is correct
34 Correct 403 ms 1024 KB Output is correct
35 Correct 492 ms 1120 KB Output is correct
36 Correct 626 ms 1112 KB Output is correct
37 Correct 565 ms 824 KB Output is correct
38 Correct 519 ms 840 KB Output is correct
39 Correct 454 ms 1008 KB Output is correct
40 Correct 510 ms 1016 KB Output is correct
41 Correct 569 ms 1024 KB Output is correct
42 Correct 78 ms 768 KB Output is correct
43 Correct 131 ms 768 KB Output is correct
44 Correct 151 ms 1024 KB Output is correct
45 Correct 179 ms 1024 KB Output is correct
46 Correct 495 ms 768 KB Output is correct
47 Correct 463 ms 768 KB Output is correct
48 Correct 78 ms 1024 KB Output is correct
49 Correct 74 ms 1024 KB Output is correct