Submission #420359

# Submission time Handle Problem Language Result Execution time Memory
420359 2021-06-08T10:09:12 Z NintsiChkhaidze Stations (IOI20_stations) C++14
100 / 100
1341 ms 900 KB
#include "stations.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
vector <int> vec[1005],labels;
int cnt = 0,in[1005],out[1005],mp[1005];
void dfs(int x,int p,int t){
    in[x] = cnt++;
    if (t%2) labels[x] = in[x];
    
    for (int j=0;j<vec[x].size();j++){
        int to = vec[x][j];
        if (to == p) continue;
        dfs(to,x,t + 1);
    }
    out[x] = cnt++;
    if (!labels[x]) labels[x] = out[x];
}
 
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    for (int i=0;i<1001;i++){
        vec[i].clear();
        in[i] = out[i] = mp[i] = 0;
    }
    for (int i=0;i<u.size();i++){
        vec[u[i]].pb(v[i]);
        vec[v[i]].pb(u[i]);
    }
    
    cnt=0;
    labels.clear();
    for (int i=0;i<n;i++)
        labels.pb(0);

    dfs(0,0,0);
    vector <int> vec = labels;
    
    sort(vec.begin(),vec.end());
    for (int i=0;i<vec.size();i++)
        mp[vec[i]] = i;
    
    for (int i=0;i<labels.size();i++)
        labels[i] = mp[labels[i]];
    
    return labels;
}
int find_next_station(int s, int t, vector<int> c) {
    sort(c.begin(),c.end());
    if (s > c[0]){
        //s - out
        for (int i = 1; i<c.size();i++){
            int l = c[i],r = s - 1;
            if (i!=c.size() - 1) r = c[i + 1] - 1;
            
            if (l <= t && t <= r) return c[i];
        }
        return c[0];
    }
    else{
        //s - in
        for (int i = 0; i<c.size() - 1; i++){
            int l = s + 1,r = c[i];
            if (i) l = c[i - 1] + 1;
            
            if (l <= t && t <= r) return c[i];
        }
        return c.back();
    }
}

Compilation message

stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int j=0;j<vec[x].size();j++){
      |                  ~^~~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i=0;i<u.size();i++){
      |                  ~^~~~~~~~~
stations.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i=0;i<vec.size();i++)
      |                  ~^~~~~~~~~~~
stations.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i=0;i<labels.size();i++)
      |                  ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int i = 1; i<c.size();i++){
      |                         ~^~~~~~~~~
stations.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if (i!=c.size() - 1) r = c[i + 1] - 1;
      |                 ~^~~~~~~~~~~~~~
stations.cpp:61:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int i = 0; i<c.size() - 1; i++){
      |                         ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 565 ms 648 KB Output is correct
2 Correct 663 ms 636 KB Output is correct
3 Correct 1341 ms 504 KB Output is correct
4 Correct 968 ms 516 KB Output is correct
5 Correct 734 ms 400 KB Output is correct
6 Correct 572 ms 656 KB Output is correct
7 Correct 567 ms 504 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 580 KB Output is correct
2 Correct 668 ms 684 KB Output is correct
3 Correct 1170 ms 508 KB Output is correct
4 Correct 863 ms 528 KB Output is correct
5 Correct 714 ms 528 KB Output is correct
6 Correct 456 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 633 ms 840 KB Output is correct
2 Correct 478 ms 656 KB Output is correct
3 Correct 1144 ms 512 KB Output is correct
4 Correct 770 ms 508 KB Output is correct
5 Correct 657 ms 400 KB Output is correct
6 Correct 547 ms 624 KB Output is correct
7 Correct 456 ms 528 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 687 ms 400 KB Output is correct
12 Correct 603 ms 756 KB Output is correct
13 Correct 566 ms 768 KB Output is correct
14 Correct 472 ms 516 KB Output is correct
15 Correct 57 ms 548 KB Output is correct
16 Correct 67 ms 528 KB Output is correct
17 Correct 131 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 974 ms 528 KB Output is correct
2 Correct 736 ms 656 KB Output is correct
3 Correct 651 ms 516 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 602 ms 516 KB Output is correct
8 Correct 1103 ms 516 KB Output is correct
9 Correct 682 ms 656 KB Output is correct
10 Correct 641 ms 400 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 5 ms 604 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 610 ms 516 KB Output is correct
17 Correct 522 ms 556 KB Output is correct
18 Correct 628 ms 404 KB Output is correct
19 Correct 685 ms 464 KB Output is correct
20 Correct 627 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 701 ms 836 KB Output is correct
2 Correct 565 ms 528 KB Output is correct
3 Correct 1156 ms 516 KB Output is correct
4 Correct 807 ms 528 KB Output is correct
5 Correct 736 ms 596 KB Output is correct
6 Correct 719 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 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 654 ms 508 KB Output is correct
12 Correct 630 ms 516 KB Output is correct
13 Correct 1069 ms 496 KB Output is correct
14 Correct 722 ms 552 KB Output is correct
15 Correct 691 ms 524 KB Output is correct
16 Correct 526 ms 520 KB Output is correct
17 Correct 639 ms 400 KB Output is correct
18 Correct 537 ms 636 KB Output is correct
19 Correct 466 ms 900 KB Output is correct
20 Correct 505 ms 516 KB Output is correct
21 Correct 49 ms 528 KB Output is correct
22 Correct 79 ms 580 KB Output is correct
23 Correct 135 ms 656 KB Output is correct
24 Correct 6 ms 468 KB Output is correct
25 Correct 8 ms 596 KB Output is correct
26 Correct 6 ms 596 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 537 ms 400 KB Output is correct
30 Correct 533 ms 500 KB Output is correct
31 Correct 675 ms 528 KB Output is correct
32 Correct 721 ms 400 KB Output is correct
33 Correct 527 ms 516 KB Output is correct
34 Correct 312 ms 528 KB Output is correct
35 Correct 651 ms 780 KB Output is correct
36 Correct 598 ms 760 KB Output is correct
37 Correct 577 ms 516 KB Output is correct
38 Correct 570 ms 688 KB Output is correct
39 Correct 527 ms 612 KB Output is correct
40 Correct 463 ms 624 KB Output is correct
41 Correct 580 ms 640 KB Output is correct
42 Correct 76 ms 532 KB Output is correct
43 Correct 145 ms 724 KB Output is correct
44 Correct 187 ms 528 KB Output is correct
45 Correct 143 ms 512 KB Output is correct
46 Correct 314 ms 516 KB Output is correct
47 Correct 331 ms 528 KB Output is correct
48 Correct 85 ms 656 KB Output is correct
49 Correct 74 ms 784 KB Output is correct