Submission #781800

# Submission time Handle Problem Language Result Execution time Memory
781800 2023-07-13T11:04:07 Z jasmin Stations (IOI20_stations) C++17
100 / 100
775 ms 776 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

int ind=0;
void dfs(int v, int p, int h, vector<vector<int> >& adi, vector<int>& lab){

    if(h%2==0){
        lab[v]=ind;
    }
    ind++;

    for(auto u: adi[v]){
        if(u==p) continue;

        dfs(u, v, h+1, adi, lab);
    }

    if(h%2==1){
        lab[v]=ind;
    }
    ind++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {

    vector<vector<int> > adi(n);
    for(int i=0; i<n-1; i++){
        adi[v[i]].push_back(u[i]);
        adi[u[i]].push_back(v[i]);
    }

    ind=0;
    vector<int> lab(n, -1);
    dfs(0, -1, 0, adi, lab);

    //compression
    vector<pair<int,int> > comp;
    for(int i=0; i<n; i++){
        comp.push_back({lab[i], i});
    }
    sort(comp.begin(), comp.end());

    for(int i=0; i<n; i++){
        lab[comp[i].second]=i;
    }
    
    return lab;
}




int find_next_station(int s, int t, vector<int> c) {
    if(c.size()==1){
        return c[0];
    }

    
    int p=-1;
    vector<int> children;
    if(c[0]<s){
        
        p = c[0];
        for(int i=1; i<(int)c.size(); i++){
            children.push_back(c[i]);
        }

    }
    else{
        
        p = c.back();
        for(int i=0; i<(int)c.size()-1; i++){
            children.push_back(c[i]);
        }

    }

    if(s==0){
        p=-1;
        children = c;
    }

    if((c[0]<s && (t<children[0] || s<t)) || (s<c[0] && (t<s || children.back()<t))){
        return p;
    }

    int next=-1;
    if(c[0] < s){

        next=children[0];
        for(auto e: children){
            if(e<=t){
                next=e;
            }
        }

    }
    else{

        next=children.back();
        for(int i=children.size()-1; i>=0; i--){
            if(t<=children[i]){
                next=children[i];
            }
        }

    }
    return next;
}

int find_next_station2(int s, int t, vector<int> c) {
    if(c.size()==1){
        return c[0];
    }


    int p=-1;
    vector<int> children;
    if(c[0]<s){
        
        p = c[0];
        for(int i=1; i<(int)c.size(); i++){
            children.push_back(c[i]);
        }

        if(t<s || children.back()<t){
            return p;
        }
        int next=-1;
        for(int i=children.size(); i>=0; i--){
            if(t<=children[i]){
                next=children[i];
            }
        }
        return next;
   }
    else{
        
        p = c.back();
        for(int i=0; i<(int)c.size()-1; i++){
            children.push_back(c[i]);
        }

        if(t<children[0] || s<t){
            return p;
        }
        int next=-1;
        for(int i=0; i<(int)children.size(); i++){
            if(children[i]<=t){
                next=children[i];
            }
        }
    }

    return -1;
}

Compilation message

stations.cpp: In function 'int find_next_station2(int, int, std::vector<int>)':
stations.cpp:148:13: warning: variable 'next' set but not used [-Wunused-but-set-variable]
  148 |         int next=-1;
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 447 ms 676 KB Output is correct
2 Correct 300 ms 672 KB Output is correct
3 Correct 615 ms 416 KB Output is correct
4 Correct 500 ms 504 KB Output is correct
5 Correct 482 ms 420 KB Output is correct
6 Correct 382 ms 760 KB Output is correct
7 Correct 420 ms 676 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 496 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 516 KB Output is correct
2 Correct 419 ms 544 KB Output is correct
3 Correct 754 ms 420 KB Output is correct
4 Correct 524 ms 504 KB Output is correct
5 Correct 480 ms 508 KB Output is correct
6 Correct 389 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 672 KB Output is correct
2 Correct 300 ms 548 KB Output is correct
3 Correct 679 ms 416 KB Output is correct
4 Correct 524 ms 504 KB Output is correct
5 Correct 524 ms 508 KB Output is correct
6 Correct 387 ms 700 KB Output is correct
7 Correct 337 ms 628 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
11 Correct 510 ms 504 KB Output is correct
12 Correct 308 ms 712 KB Output is correct
13 Correct 370 ms 720 KB Output is correct
14 Correct 449 ms 508 KB Output is correct
15 Correct 49 ms 492 KB Output is correct
16 Correct 48 ms 592 KB Output is correct
17 Correct 80 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 690 ms 508 KB Output is correct
2 Correct 656 ms 544 KB Output is correct
3 Correct 575 ms 512 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 310 ms 508 KB Output is correct
8 Correct 691 ms 416 KB Output is correct
9 Correct 635 ms 416 KB Output is correct
10 Correct 568 ms 420 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 3 ms 500 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 474 ms 416 KB Output is correct
17 Correct 402 ms 420 KB Output is correct
18 Correct 383 ms 504 KB Output is correct
19 Correct 378 ms 420 KB Output is correct
20 Correct 378 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 414 ms 676 KB Output is correct
2 Correct 353 ms 776 KB Output is correct
3 Correct 775 ms 416 KB Output is correct
4 Correct 508 ms 420 KB Output is correct
5 Correct 493 ms 504 KB Output is correct
6 Correct 403 ms 680 KB Output is correct
7 Correct 258 ms 628 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 338 ms 548 KB Output is correct
12 Correct 456 ms 544 KB Output is correct
13 Correct 650 ms 508 KB Output is correct
14 Correct 530 ms 508 KB Output is correct
15 Correct 472 ms 508 KB Output is correct
16 Correct 313 ms 504 KB Output is correct
17 Correct 490 ms 420 KB Output is correct
18 Correct 339 ms 548 KB Output is correct
19 Correct 448 ms 752 KB Output is correct
20 Correct 337 ms 548 KB Output is correct
21 Correct 49 ms 488 KB Output is correct
22 Correct 65 ms 600 KB Output is correct
23 Correct 78 ms 544 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 4 ms 492 KB Output is correct
26 Correct 3 ms 500 KB Output is correct
27 Correct 3 ms 500 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 480 ms 500 KB Output is correct
30 Correct 409 ms 420 KB Output is correct
31 Correct 328 ms 500 KB Output is correct
32 Correct 356 ms 420 KB Output is correct
33 Correct 456 ms 500 KB Output is correct
34 Correct 240 ms 544 KB Output is correct
35 Correct 383 ms 736 KB Output is correct
36 Correct 405 ms 716 KB Output is correct
37 Correct 409 ms 544 KB Output is correct
38 Correct 331 ms 760 KB Output is correct
39 Correct 324 ms 548 KB Output is correct
40 Correct 340 ms 664 KB Output is correct
41 Correct 267 ms 712 KB Output is correct
42 Correct 56 ms 600 KB Output is correct
43 Correct 62 ms 544 KB Output is correct
44 Correct 128 ms 504 KB Output is correct
45 Correct 104 ms 548 KB Output is correct
46 Correct 251 ms 548 KB Output is correct
47 Correct 312 ms 632 KB Output is correct
48 Correct 41 ms 652 KB Output is correct
49 Correct 50 ms 568 KB Output is correct