Submission #554873

# Submission time Handle Problem Language Result Execution time Memory
554873 2022-04-29T14:09:12 Z status_coding Stations (IOI20_stations) C++14
100 / 100
825 ms 932 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

int t=0;
int d[1005], in[1005], out[5005];
vector<int> v[1005];

void dfs(int p, int par)
{
    t++;
    in[p] = t;

    if(par == -1)
        d[p] = 0;
    else
        d[p] = d[par] + 1;

    for(int it : v[p])
    {
        if(it == par)
            continue;

        dfs(it, p);
    }

    t++;
    out[p] = t;
}

void norm(vector<int> &v)
{
    map<int, int> fr;

    for(int it : v)
        fr[it] = 1;

    int nr = -1;
    for(auto &it : fr)
    {
        nr++;
        it.second = nr;
    }

    for(int &it : v)
        it = fr[it];
}

vector<int> label(int n, int k, vector<int> x, vector<int> y)
{
    for(int i=0; i<n; i++)
        v[i].clear();

    for(int i=0; i<(int)x.size(); i++)
    {
        v[ x[i] ].push_back( y[i] );
        v[ y[i] ].push_back( x[i] );
    }

    dfs(0, -1);

    vector<int> ans;
    for(int i=0; i<n; i++)
    {
        if(d[i] % 2 == 0)
            ans.push_back(in[i]);
        else
            ans.push_back(out[i]);
    }

    norm(ans);
    return ans;
}

int find_next_station(int s, int t, vector<int> v)
{
    if(v.size() == 1)
        return v[0];

    sort(v.begin(), v.end());

    if(s == 0)
    {
        for(int i=1; i<(int)v.size(); i++)
            if(v[i] >= t && v[i-1] < t)
                return v[i];

        return v[0];
    }

    if(s < v[0])
    {
        /// is in

        int l = s;
        int r = v[(int)v.size() - 2];

        if(l <= t && t <= r)
        {
            for(int i=0; i<(int)v.size()-1 ; i++)
                if(v[i] >= t)
                    return v[i];
        }
        else
            return v.back();
    }
    else
    {
        /// is out

        int l = v[1];
        int r = s;

        if(l <= t && t<=r)
        {
            for(int i=(int)v.size()-1; i>=1; i--)
                if(v[i] <= t)
                    return v[i];
        }
        else
            return v[0];
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:124:1: warning: control reaches end of non-void function [-Wreturn-type]
  124 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 463 ms 652 KB Output is correct
2 Correct 390 ms 668 KB Output is correct
3 Correct 765 ms 520 KB Output is correct
4 Correct 532 ms 528 KB Output is correct
5 Correct 519 ms 420 KB Output is correct
6 Correct 362 ms 660 KB Output is correct
7 Correct 420 ms 672 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 387 ms 544 KB Output is correct
2 Correct 449 ms 536 KB Output is correct
3 Correct 821 ms 524 KB Output is correct
4 Correct 565 ms 524 KB Output is correct
5 Correct 462 ms 544 KB Output is correct
6 Correct 392 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 461 ms 656 KB Output is correct
2 Correct 407 ms 664 KB Output is correct
3 Correct 735 ms 516 KB Output is correct
4 Correct 534 ms 544 KB Output is correct
5 Correct 400 ms 544 KB Output is correct
6 Correct 355 ms 668 KB Output is correct
7 Correct 385 ms 676 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 5 ms 628 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 541 ms 524 KB Output is correct
12 Correct 416 ms 660 KB Output is correct
13 Correct 373 ms 780 KB Output is correct
14 Correct 359 ms 548 KB Output is correct
15 Correct 47 ms 620 KB Output is correct
16 Correct 53 ms 604 KB Output is correct
17 Correct 86 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 698 ms 552 KB Output is correct
2 Correct 553 ms 416 KB Output is correct
3 Correct 480 ms 544 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 476 ms 608 KB Output is correct
8 Correct 731 ms 416 KB Output is correct
9 Correct 578 ms 520 KB Output is correct
10 Correct 492 ms 528 KB Output is correct
11 Correct 6 ms 488 KB Output is correct
12 Correct 6 ms 500 KB Output is correct
13 Correct 4 ms 500 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 4 ms 628 KB Output is correct
16 Correct 447 ms 524 KB Output is correct
17 Correct 446 ms 544 KB Output is correct
18 Correct 441 ms 420 KB Output is correct
19 Correct 409 ms 540 KB Output is correct
20 Correct 413 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 443 ms 656 KB Output is correct
2 Correct 404 ms 672 KB Output is correct
3 Correct 765 ms 652 KB Output is correct
4 Correct 589 ms 548 KB Output is correct
5 Correct 545 ms 528 KB Output is correct
6 Correct 349 ms 676 KB Output is correct
7 Correct 403 ms 636 KB Output is correct
8 Correct 3 ms 496 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 2 ms 628 KB Output is correct
11 Correct 411 ms 532 KB Output is correct
12 Correct 476 ms 544 KB Output is correct
13 Correct 825 ms 520 KB Output is correct
14 Correct 496 ms 548 KB Output is correct
15 Correct 536 ms 544 KB Output is correct
16 Correct 407 ms 548 KB Output is correct
17 Correct 562 ms 532 KB Output is correct
18 Correct 407 ms 788 KB Output is correct
19 Correct 345 ms 760 KB Output is correct
20 Correct 375 ms 544 KB Output is correct
21 Correct 57 ms 612 KB Output is correct
22 Correct 65 ms 700 KB Output is correct
23 Correct 95 ms 548 KB Output is correct
24 Correct 4 ms 500 KB Output is correct
25 Correct 6 ms 628 KB Output is correct
26 Correct 5 ms 628 KB Output is correct
27 Correct 4 ms 492 KB Output is correct
28 Correct 2 ms 628 KB Output is correct
29 Correct 438 ms 528 KB Output is correct
30 Correct 471 ms 416 KB Output is correct
31 Correct 467 ms 532 KB Output is correct
32 Correct 475 ms 528 KB Output is correct
33 Correct 494 ms 548 KB Output is correct
34 Correct 277 ms 660 KB Output is correct
35 Correct 402 ms 772 KB Output is correct
36 Correct 379 ms 764 KB Output is correct
37 Correct 418 ms 768 KB Output is correct
38 Correct 411 ms 776 KB Output is correct
39 Correct 430 ms 656 KB Output is correct
40 Correct 379 ms 780 KB Output is correct
41 Correct 395 ms 896 KB Output is correct
42 Correct 54 ms 600 KB Output is correct
43 Correct 102 ms 652 KB Output is correct
44 Correct 115 ms 548 KB Output is correct
45 Correct 152 ms 664 KB Output is correct
46 Correct 270 ms 528 KB Output is correct
47 Correct 283 ms 544 KB Output is correct
48 Correct 57 ms 932 KB Output is correct
49 Correct 59 ms 832 KB Output is correct