Submission #432398

# Submission time Handle Problem Language Result Execution time Memory
432398 2021-06-18T09:14:04 Z idk321 Stations (IOI20_stations) C++17
100 / 100
926 ms 912 KB
#include "stations.h"
#include <vector>

using namespace std;
#include <bits/stdc++.h>

const int M = 1000000000;
const int N = 1000;
int in[N];
int out[N];
vector<int> adj[N];
vector<int> labels;

int n, k;

int timer;

int type[N];


void dfs2(int node, int par)
{
    if (par == -1)
    {
        type[node] = 0;

    } else
    {
        type[node] = !type[par];

    }


    in[node] = timer;
    timer++;

    for (int next : adj[node])
    {
        if (next == par) continue;
        dfs2(next, node);
    }

    out[node] = timer;
    timer++;
}


const int add = 1000;


std::vector<int> label(int n1, int k1, std::vector<int> u, std::vector<int> v) {
    n = n1;
    k = k1;

    labels.assign(n, 0);


    for (int i = 0; i < n; i++) adj[i].clear();
    for (int i = 0; i < u.size(); i++)
    {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }




    timer = 0;
    dfs2(0, -1);



    for (int i = 0; i < n; i++) {
        if (type[i] == 0) labels[i] = in[i];
        else labels[i] = out[i];
    }
    vector<int> numbers;
    for (int i : labels) numbers.push_back(i);
    sort(numbers.begin(), numbers.end());
    map<int, int> turnTo;
    int cur = 0;
    for (int i : numbers)
    {
        turnTo[i] = cur;
        cur++;
    }

    for (int i = 0; i < labels.size(); i++)
    {
        labels[i] = turnTo[labels[i]];
    }


    return labels;
}



int find_next_station(int s, int t, std::vector<int> c) {

    bool isIn = true;
    if (s == 0) isIn = true;
    else
    {
        for (int next : c)
        {
            if (next  < s) isIn = false;
        }
    }

    if (isIn)
    {

        int par = -1;
        if (s != 0)
        {
            for (int next : c)
            {
                if (par < next)
                {
                    par = next;
                }
            }
        }


        if (t < s) return par;

        int take = M;
        for (int next : c)
        {
            if (next == par) continue;
            if (next < take && next >= t)
            {
                take = next;
            }

        }
        if (take == M) return par;
        return take;
    } else
    {
        int par = M;
        for (int& next : c)
        {


            if (next < par) par = next;
        }


        if (t > s) return par;
        vector<int> children;
        for (int next : c)
        {
            if (next == par) continue;
            children.push_back(next);
        }


        if (t <= par) return par;

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

        if (take == -1) return par;
        return children[take];
    }






    return c[0];
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0; i < u.size(); i++)
      |                     ~~^~~~~~~~~~
stations.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for (int i = 0; i < labels.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:164:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  164 |         for (int i = 0; i < children.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 581 ms 628 KB Output is correct
2 Correct 518 ms 844 KB Output is correct
3 Correct 926 ms 400 KB Output is correct
4 Correct 660 ms 420 KB Output is correct
5 Correct 709 ms 516 KB Output is correct
6 Correct 490 ms 868 KB Output is correct
7 Correct 466 ms 672 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 504 KB Output is correct
2 Correct 567 ms 656 KB Output is correct
3 Correct 897 ms 680 KB Output is correct
4 Correct 664 ms 528 KB Output is correct
5 Correct 596 ms 508 KB Output is correct
6 Correct 498 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 606 ms 648 KB Output is correct
2 Correct 501 ms 772 KB Output is correct
3 Correct 903 ms 512 KB Output is correct
4 Correct 698 ms 516 KB Output is correct
5 Correct 570 ms 680 KB Output is correct
6 Correct 463 ms 660 KB Output is correct
7 Correct 476 ms 520 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 5 ms 608 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 566 ms 644 KB Output is correct
12 Correct 496 ms 748 KB Output is correct
13 Correct 452 ms 740 KB Output is correct
14 Correct 470 ms 656 KB Output is correct
15 Correct 60 ms 652 KB Output is correct
16 Correct 83 ms 656 KB Output is correct
17 Correct 133 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 876 ms 496 KB Output is correct
2 Correct 725 ms 608 KB Output is correct
3 Correct 769 ms 712 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 5 ms 796 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 763 ms 712 KB Output is correct
8 Correct 824 ms 720 KB Output is correct
9 Correct 675 ms 528 KB Output is correct
10 Correct 550 ms 568 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 4 ms 548 KB Output is correct
13 Correct 5 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 492 ms 516 KB Output is correct
17 Correct 514 ms 652 KB Output is correct
18 Correct 525 ms 784 KB Output is correct
19 Correct 508 ms 528 KB Output is correct
20 Correct 521 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 584 ms 648 KB Output is correct
2 Correct 467 ms 656 KB Output is correct
3 Correct 897 ms 512 KB Output is correct
4 Correct 703 ms 512 KB Output is correct
5 Correct 526 ms 400 KB Output is correct
6 Correct 501 ms 656 KB Output is correct
7 Correct 482 ms 656 KB Output is correct
8 Correct 4 ms 732 KB Output is correct
9 Correct 5 ms 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 472 ms 532 KB Output is correct
12 Correct 592 ms 528 KB Output is correct
13 Correct 913 ms 400 KB Output is correct
14 Correct 655 ms 512 KB Output is correct
15 Correct 571 ms 508 KB Output is correct
16 Correct 449 ms 528 KB Output is correct
17 Correct 561 ms 564 KB Output is correct
18 Correct 454 ms 764 KB Output is correct
19 Correct 495 ms 740 KB Output is correct
20 Correct 465 ms 656 KB Output is correct
21 Correct 58 ms 528 KB Output is correct
22 Correct 77 ms 656 KB Output is correct
23 Correct 111 ms 656 KB Output is correct
24 Correct 5 ms 448 KB Output is correct
25 Correct 5 ms 596 KB Output is correct
26 Correct 5 ms 596 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 1 ms 476 KB Output is correct
29 Correct 486 ms 528 KB Output is correct
30 Correct 492 ms 556 KB Output is correct
31 Correct 479 ms 520 KB Output is correct
32 Correct 493 ms 528 KB Output is correct
33 Correct 494 ms 400 KB Output is correct
34 Correct 299 ms 656 KB Output is correct
35 Correct 430 ms 836 KB Output is correct
36 Correct 459 ms 772 KB Output is correct
37 Correct 471 ms 792 KB Output is correct
38 Correct 467 ms 784 KB Output is correct
39 Correct 489 ms 776 KB Output is correct
40 Correct 466 ms 888 KB Output is correct
41 Correct 481 ms 776 KB Output is correct
42 Correct 65 ms 704 KB Output is correct
43 Correct 99 ms 840 KB Output is correct
44 Correct 132 ms 776 KB Output is correct
45 Correct 179 ms 660 KB Output is correct
46 Correct 306 ms 528 KB Output is correct
47 Correct 320 ms 528 KB Output is correct
48 Correct 72 ms 912 KB Output is correct
49 Correct 57 ms 784 KB Output is correct