Submission #432333

# Submission time Handle Problem Language Result Execution time Memory
432333 2021-06-18T08:11:36 Z idk321 Stations (IOI20_stations) C++17
0 / 100
943 ms 512 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++;
}



array<int, 2> getInAndOut(int num)
{
    int cur = 0;
    for (int i = 0; i < 1000; i++)
    {
        if (cur + 1000 - i < num)
        {
            cur += 1000 - i;
            continue;
        }
        for (int j = i; j < 1000; j++)
        {
            if (cur == num)
            {
                return {i, j};
            }
            cur++;
        }
    }
}

int getLabel(int nin, int nout)
{
    int cur = 0;
    for (int i = 0; i < 1000; i++)
    {
        if (i < nin)
        {
            cur += (1000 - i);
            continue;
        }

        for (int j = i; j < 1000; j++)
        {
            if (i == nin && j == nout)
            {
                return cur;
            }
            cur++;
        }
    }
    return -1;
}

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] + 1000;
        else labels[i] = out[i];
    }
    return labels;
}



int find_next_station(int s, int t, std::vector<int> c) {
    if (t >= 1000) t -= 1000;
    if (s >= 1000)
    {
        s -= 1000;
        int par = -1;
        int most = -1;
        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)
        {

            next -= 1000;
            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);
        }


        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] + 1000;


    }






    return c[0];
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for (int i = 0; i < u.size(); i++)
      |                     ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:130:13: warning: unused variable 'most' [-Wunused-variable]
  130 |         int most = -1;
      |             ^~~~
stations.cpp:175:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |         for (int i = 0; i < children.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
stations.cpp: In function 'std::array<int, 2> getInAndOut(int)':
stations.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
   68 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 460 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=2, label=1004
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 316 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1022
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 292 KB Invalid labels (duplicates values). scenario=1, label=1300
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 943 ms 512 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 296 KB Invalid labels (duplicates values). scenario=1, label=1834
2 Halted 0 ms 0 KB -