Submission #956842

# Submission time Handle Problem Language Result Execution time Memory
956842 2024-04-02T14:26:16 Z 12345678 Stations (IOI20_stations) C++17
10 / 100
595 ms 940 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=2e3+5;
int in[nx], out[nx], lvl[nx], cnt, pa, t1;
vector<int> res, d[nx];
vector<pair<int, int>> mp[nx];

void dfs(int u, int p)
{
    in[u]=++cnt;
    lvl[u]=lvl[p]+1;
    for (auto v:d[u]) if (v!=p) dfs(v, u);
    out[u]=++cnt;
    if (lvl[u]%2) mp[in[u]].push_back({u, 0});
    else mp[out[u]].push_back({u, 1});
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    cnt=-1;
    t1=0;
    for (int i=0; i<n; i++) d[i].clear();
    for (int i=0; i<1000; i++) mp[i].clear();
    res.resize(n);
    for (int i=0; i<n-1; i++) d[u[i]].push_back(v[i]), d[v[i]].push_back(u[i]);
    lvl[0]=0;
    dfs(0, 0);
    for (int i=0; i<1000; i++)
    {
        if (!mp[i].empty())
        {
            for (auto [x, y]:mp[i]) res[x]=t1+y*1000;
            t1++;
        }
    }
	return res;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if (c.size()==1) return c[0];
    if (t>=1000) t-=1000;
    if (s<1000)
    {
        for (auto &x:c) x-=1000;
        if (s==0) for (auto x:c) if (t<=x) return x+1000;
        pa=c.back();
        for (int i=0; i<c.size()-1; i++) if (s<=t&&t<=c[i]) return c[i]+1000;
        return pa+1000;
    }
    else
    {
        s-=1000;
        pa=c.front();
        for (int i=c.size()-1; i>0; i--) if (c[i]<=t&&t<=s) return c[i];
        return pa;
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int i=0; i<c.size()-1; i++) if (s<=t&&t<=c[i]) return c[i]+1000;
      |                       ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 728 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1007
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 692 KB Invalid labels (duplicates values). scenario=0, label=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 744 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 595 ms 940 KB Output is correct
2 Correct 464 ms 684 KB Output is correct
3 Correct 382 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 372 ms 936 KB Output is correct
8 Correct 565 ms 688 KB Output is correct
9 Correct 413 ms 684 KB Output is correct
10 Correct 371 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 3 ms 764 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 300 ms 684 KB Output is correct
17 Correct 296 ms 684 KB Output is correct
18 Correct 352 ms 688 KB Output is correct
19 Correct 314 ms 684 KB Output is correct
20 Correct 329 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 752 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -