Submission #1090649

# Submission time Handle Problem Language Result Execution time Memory
1090649 2024-09-18T14:57:18 Z onlk97 Stations (IOI20_stations) C++14
100 / 100
636 ms 1300 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

vector <int> g[1010];
int in[1010],out[1010],dep[1010],tme;
void dfs(int cur,int prv){
    if (prv==-1) dep[cur]=0;
    else dep[cur]=dep[prv]+1;
    in[cur]=++tme;
    for (int i:g[cur]){
        if (i==prv) continue;
        dfs(i,cur);
    }
    out[cur]=++tme;
}
vector <int> label(int n,int k,vector <int> u,vector <int> v){
    for (int i=0; i<n; i++) g[i].clear();
    tme=-1;
    for (int i=0; i<n-1; i++){
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    dfs(0,-1);
    vector <int> ret(n);
    for (int i=0; i<n; i++){
        if (dep[i]%2==0) ret[i]=in[i];
        else ret[i]=out[i];
    }
    vector <int> cpy=ret;
    sort(cpy.begin(),cpy.end());
    for (int i=0; i<n; i++) ret[i]=lower_bound(cpy.begin(),cpy.end(),ret[i])-cpy.begin();
    return ret;
}

int find_next_station(int s,int t,vector <int> c){
    if (c.size()==1) return c[0];
    if (binary_search(c.begin(),c.end(),t)) return t;
    if (s>*max_element(c.begin(),c.end())){
        for (int i=1; i+1<c.size(); i++){
            if (c[i]<=t&&t<c[i+1]) return c[i];
        }
        if (t>s||t<c[1]) return c.front();
        return c.back();
    }
    if (!s){
        for (int i=0; i<c.size(); i++){
            if (t<=c[i]) return c[i];
        }
    }
    for (int i=1; i+1<c.size(); i++){
        if (c[i-1]<t&&t<=c[i]) return c[i];
    }
    if (t<s||t>c[c.size()-2]) return c.back();
    return c.front();
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int i=1; i+1<c.size(); i++){
      |                       ~~~^~~~~~~~~
stations.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for (int i=0; i<c.size(); i++){
      |                       ~^~~~~~~~~
stations.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i=1; i+1<c.size(); i++){
      |                   ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 403 ms 684 KB Output is correct
2 Correct 292 ms 708 KB Output is correct
3 Correct 636 ms 684 KB Output is correct
4 Correct 442 ms 684 KB Output is correct
5 Correct 396 ms 684 KB Output is correct
6 Correct 329 ms 684 KB Output is correct
7 Correct 306 ms 684 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 688 KB Output is correct
2 Correct 363 ms 684 KB Output is correct
3 Correct 613 ms 684 KB Output is correct
4 Correct 447 ms 684 KB Output is correct
5 Correct 366 ms 684 KB Output is correct
6 Correct 290 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 696 KB Output is correct
2 Correct 311 ms 684 KB Output is correct
3 Correct 619 ms 684 KB Output is correct
4 Correct 461 ms 684 KB Output is correct
5 Correct 401 ms 684 KB Output is correct
6 Correct 301 ms 684 KB Output is correct
7 Correct 299 ms 684 KB Output is correct
8 Correct 2 ms 776 KB Output is correct
9 Correct 1 ms 776 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 396 ms 684 KB Output is correct
12 Correct 300 ms 1040 KB Output is correct
13 Correct 300 ms 1300 KB Output is correct
14 Correct 288 ms 684 KB Output is correct
15 Correct 24 ms 768 KB Output is correct
16 Correct 32 ms 768 KB Output is correct
17 Correct 54 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 609 ms 684 KB Output is correct
2 Correct 388 ms 684 KB Output is correct
3 Correct 381 ms 684 KB Output is correct
4 Correct 1 ms 772 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 422 ms 684 KB Output is correct
8 Correct 570 ms 684 KB Output is correct
9 Correct 397 ms 684 KB Output is correct
10 Correct 401 ms 684 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 3 ms 776 KB Output is correct
13 Correct 3 ms 776 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 324 ms 684 KB Output is correct
17 Correct 331 ms 684 KB Output is correct
18 Correct 351 ms 684 KB Output is correct
19 Correct 357 ms 684 KB Output is correct
20 Correct 347 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 684 KB Output is correct
2 Correct 319 ms 680 KB Output is correct
3 Correct 555 ms 684 KB Output is correct
4 Correct 402 ms 684 KB Output is correct
5 Correct 404 ms 684 KB Output is correct
6 Correct 306 ms 684 KB Output is correct
7 Correct 306 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 297 ms 684 KB Output is correct
12 Correct 398 ms 684 KB Output is correct
13 Correct 606 ms 684 KB Output is correct
14 Correct 475 ms 684 KB Output is correct
15 Correct 435 ms 684 KB Output is correct
16 Correct 335 ms 684 KB Output is correct
17 Correct 389 ms 684 KB Output is correct
18 Correct 299 ms 792 KB Output is correct
19 Correct 326 ms 788 KB Output is correct
20 Correct 316 ms 684 KB Output is correct
21 Correct 35 ms 768 KB Output is correct
22 Correct 50 ms 768 KB Output is correct
23 Correct 62 ms 684 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 3 ms 776 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 1 ms 764 KB Output is correct
29 Correct 337 ms 684 KB Output is correct
30 Correct 361 ms 684 KB Output is correct
31 Correct 335 ms 684 KB Output is correct
32 Correct 345 ms 684 KB Output is correct
33 Correct 368 ms 684 KB Output is correct
34 Correct 210 ms 940 KB Output is correct
35 Correct 304 ms 684 KB Output is correct
36 Correct 340 ms 684 KB Output is correct
37 Correct 362 ms 684 KB Output is correct
38 Correct 309 ms 932 KB Output is correct
39 Correct 327 ms 940 KB Output is correct
40 Correct 300 ms 792 KB Output is correct
41 Correct 325 ms 796 KB Output is correct
42 Correct 41 ms 768 KB Output is correct
43 Correct 65 ms 684 KB Output is correct
44 Correct 79 ms 768 KB Output is correct
45 Correct 99 ms 716 KB Output is correct
46 Correct 217 ms 680 KB Output is correct
47 Correct 208 ms 684 KB Output is correct
48 Correct 32 ms 772 KB Output is correct
49 Correct 30 ms 768 KB Output is correct