답안 #432395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
432395 2021-06-18T09:10:14 Z idk321 기지국 (IOI20_stations) C++17
74.4576 / 100
913 ms 980 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 = 2000;


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]];
    }
    for (int i = 0;  i< labels.size(); i++)
    {
        if (type[i] == 0) labels[i] += add;
    }

    return labels;
}



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

            next -= add;
            if (next < par) par = next;
        }


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


        if (t <= par) return par + add;

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

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






    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:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for (int i = 0;  i< labels.size(); i++)
      |                      ~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:157:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |         for (int i = 0; i < children.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 492 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=2000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 440 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=2000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 581 ms 680 KB Output is correct
2 Correct 425 ms 636 KB Output is correct
3 Correct 876 ms 492 KB Output is correct
4 Correct 677 ms 400 KB Output is correct
5 Correct 566 ms 648 KB Output is correct
6 Correct 437 ms 900 KB Output is correct
7 Correct 438 ms 632 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 599 ms 400 KB Output is correct
12 Correct 476 ms 752 KB Output is correct
13 Correct 461 ms 768 KB Output is correct
14 Correct 447 ms 536 KB Output is correct
15 Correct 60 ms 592 KB Output is correct
16 Correct 63 ms 660 KB Output is correct
17 Correct 102 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 836 ms 528 KB Output is correct
2 Correct 668 ms 508 KB Output is correct
3 Correct 593 ms 512 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 599 ms 520 KB Output is correct
8 Correct 865 ms 400 KB Output is correct
9 Correct 700 ms 504 KB Output is correct
10 Correct 635 ms 640 KB Output is correct
11 Correct 6 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 5 ms 596 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 491 ms 512 KB Output is correct
17 Correct 527 ms 528 KB Output is correct
18 Correct 532 ms 656 KB Output is correct
19 Correct 546 ms 644 KB Output is correct
20 Correct 540 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 558 ms 756 KB Partially correct
2 Partially correct 449 ms 760 KB Partially correct
3 Partially correct 913 ms 556 KB Partially correct
4 Partially correct 731 ms 768 KB Partially correct
5 Partially correct 641 ms 528 KB Partially correct
6 Partially correct 423 ms 640 KB Partially correct
7 Partially correct 444 ms 736 KB Partially correct
8 Partially correct 3 ms 468 KB Partially correct
9 Partially correct 7 ms 596 KB Partially correct
10 Partially correct 2 ms 468 KB Partially correct
11 Partially correct 510 ms 892 KB Partially correct
12 Partially correct 511 ms 636 KB Partially correct
13 Partially correct 910 ms 496 KB Partially correct
14 Partially correct 647 ms 516 KB Partially correct
15 Partially correct 613 ms 640 KB Partially correct
16 Partially correct 399 ms 528 KB Partially correct
17 Partially correct 565 ms 400 KB Partially correct
18 Partially correct 482 ms 840 KB Partially correct
19 Partially correct 480 ms 788 KB Partially correct
20 Partially correct 466 ms 656 KB Partially correct
21 Partially correct 62 ms 528 KB Partially correct
22 Partially correct 84 ms 652 KB Partially correct
23 Partially correct 111 ms 736 KB Partially correct
24 Partially correct 5 ms 724 KB Partially correct
25 Partially correct 6 ms 596 KB Partially correct
26 Partially correct 7 ms 596 KB Partially correct
27 Partially correct 3 ms 596 KB Partially correct
28 Partially correct 2 ms 596 KB Partially correct
29 Partially correct 542 ms 652 KB Partially correct
30 Partially correct 560 ms 740 KB Partially correct
31 Partially correct 513 ms 520 KB Partially correct
32 Partially correct 506 ms 528 KB Partially correct
33 Partially correct 492 ms 512 KB Partially correct
34 Partially correct 307 ms 644 KB Partially correct
35 Partially correct 459 ms 772 KB Partially correct
36 Partially correct 443 ms 768 KB Partially correct
37 Partially correct 458 ms 764 KB Partially correct
38 Partially correct 486 ms 832 KB Partially correct
39 Partially correct 473 ms 904 KB Partially correct
40 Partially correct 496 ms 784 KB Partially correct
41 Partially correct 485 ms 892 KB Partially correct
42 Partially correct 76 ms 656 KB Partially correct
43 Partially correct 120 ms 656 KB Partially correct
44 Partially correct 134 ms 980 KB Partially correct
45 Partially correct 193 ms 696 KB Partially correct
46 Partially correct 307 ms 516 KB Partially correct
47 Partially correct 311 ms 664 KB Partially correct
48 Partially correct 74 ms 828 KB Partially correct
49 Partially correct 67 ms 908 KB Partially correct