Submission #956867

# Submission time Handle Problem Language Result Execution time Memory
956867 2024-04-02T15:08:45 Z 12345678 Stations (IOI20_stations) C++17
100 / 100
601 ms 1712 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<2000; 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<2000; i++)
    {
        if (!mp[i].empty())
        {
            for (auto [x, y]:mp[i]) res[x]=t1;
            t1++;
        }
    }
	return res;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if (c.size()==1) return c[0];
    if (s<c[0])
    {
        if (s==0) for (auto x:c) if (t<=x) return x;
        pa=c.back();
        for (int i=0; i<c.size()-1; i++) if (s<=t&&t<=c[i]) return c[i];
        return pa;
    }
    else
    {
        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:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i=0; i<c.size()-1; i++) if (s<=t&&t<=c[i]) return c[i];
      |                       ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 365 ms 1044 KB Output is correct
2 Correct 270 ms 1056 KB Output is correct
3 Correct 580 ms 868 KB Output is correct
4 Correct 439 ms 684 KB Output is correct
5 Correct 339 ms 940 KB Output is correct
6 Correct 312 ms 1044 KB Output is correct
7 Correct 296 ms 940 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 1020 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 1248 KB Output is correct
2 Correct 348 ms 1152 KB Output is correct
3 Correct 589 ms 684 KB Output is correct
4 Correct 406 ms 684 KB Output is correct
5 Correct 357 ms 684 KB Output is correct
6 Correct 297 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 1064 KB Output is correct
2 Correct 308 ms 1068 KB Output is correct
3 Correct 548 ms 684 KB Output is correct
4 Correct 448 ms 684 KB Output is correct
5 Correct 411 ms 684 KB Output is correct
6 Correct 244 ms 1048 KB Output is correct
7 Correct 289 ms 940 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 378 ms 684 KB Output is correct
12 Correct 257 ms 1176 KB Output is correct
13 Correct 306 ms 1304 KB Output is correct
14 Correct 271 ms 940 KB Output is correct
15 Correct 30 ms 768 KB Output is correct
16 Correct 39 ms 976 KB Output is correct
17 Correct 59 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 567 ms 940 KB Output is correct
2 Correct 413 ms 684 KB Output is correct
3 Correct 391 ms 684 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 366 ms 684 KB Output is correct
8 Correct 505 ms 684 KB Output is correct
9 Correct 383 ms 684 KB Output is correct
10 Correct 390 ms 688 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 964 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 357 ms 936 KB Output is correct
17 Correct 341 ms 876 KB Output is correct
18 Correct 324 ms 684 KB Output is correct
19 Correct 355 ms 684 KB Output is correct
20 Correct 321 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 340 ms 1224 KB Output is correct
2 Correct 281 ms 1312 KB Output is correct
3 Correct 601 ms 684 KB Output is correct
4 Correct 392 ms 684 KB Output is correct
5 Correct 361 ms 684 KB Output is correct
6 Correct 277 ms 1052 KB Output is correct
7 Correct 324 ms 940 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 269 ms 1240 KB Output is correct
12 Correct 409 ms 952 KB Output is correct
13 Correct 563 ms 684 KB Output is correct
14 Correct 413 ms 684 KB Output is correct
15 Correct 346 ms 684 KB Output is correct
16 Correct 283 ms 940 KB Output is correct
17 Correct 390 ms 684 KB Output is correct
18 Correct 320 ms 1212 KB Output is correct
19 Correct 319 ms 1480 KB Output is correct
20 Correct 264 ms 940 KB Output is correct
21 Correct 34 ms 768 KB Output is correct
22 Correct 40 ms 1204 KB Output is correct
23 Correct 55 ms 1048 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 3 ms 772 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 326 ms 684 KB Output is correct
30 Correct 347 ms 684 KB Output is correct
31 Correct 312 ms 684 KB Output is correct
32 Correct 306 ms 684 KB Output is correct
33 Correct 321 ms 936 KB Output is correct
34 Correct 207 ms 1036 KB Output is correct
35 Correct 303 ms 1324 KB Output is correct
36 Correct 276 ms 1236 KB Output is correct
37 Correct 315 ms 1228 KB Output is correct
38 Correct 279 ms 1204 KB Output is correct
39 Correct 294 ms 1488 KB Output is correct
40 Correct 269 ms 1284 KB Output is correct
41 Correct 328 ms 1712 KB Output is correct
42 Correct 32 ms 1032 KB Output is correct
43 Correct 70 ms 1032 KB Output is correct
44 Correct 94 ms 1008 KB Output is correct
45 Correct 112 ms 1012 KB Output is correct
46 Correct 202 ms 980 KB Output is correct
47 Correct 188 ms 1016 KB Output is correct
48 Correct 44 ms 1560 KB Output is correct
49 Correct 47 ms 1344 KB Output is correct