Submission #1060547

# Submission time Handle Problem Language Result Execution time Memory
1060547 2024-08-15T17:07:47 Z ArthuroWich Stations (IOI20_stations) C++17
100 / 100
629 ms 1444 KB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[1005];
int timer = 0, st[1005], en[1005], l[1005];
void dfs(int i, int p, int d) {
    st[i] = timer;
    timer++;
    if (d % 2 == 0) {
        l[i] = st[i];
    }
    for (int j : adj[i]) {
        if (j == p) {
            continue;
        }
        dfs(j, i, d+1);
    }
    en[i] = timer;
    timer++;
    if (d % 2 == 1) {
        l[i] = en[i];
    }
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    vector<int> labels(n);
    timer = 0;
    for (int i = 0; i <= n; i++) {
        adj[i].clear();
        en[i] = 0;
    }
    int leaf = 0;
    for (int i = 0; i < n-1; i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    for (int i = 0; i < n; i++) {
        sort(adj[i].begin(), adj[i].end());
        if (adj[i].size() == 1) {
            leaf = i;
        }
    }
    dfs(leaf, -1, 0);
    vector<int> ind;
    for (int i = 0; i < n; i++) {
        ind.push_back(l[i]);
    }
    sort(ind.begin(), ind.end());
    for (int i = 0; i < n; i++) {
        labels[i] = lower_bound(ind.begin(), ind.end(), l[i]) - ind.begin();
    }
    return labels;
}
int find_next_station(int s, int t, vector<int> c) {
    int ins = -1, outs = -1;
    if (c.size() == 1) {
        return c.back();
    }
    if (s == t) {
        return s;
    }
    for (int i : c) {
        if (i == t) {
            return t;
        }
    }
    if (s == 0) {
        vector<int> in(c.size()), out(c.size());
        ins = s;
        outs = c.back()+1;
        for (int i = 0; i < c.size(); i++) {
            out[i] = c[i];
            if (i == 0) {
                in[i] = ins+1;
            } else {
                in[i] = out[i-1]+1;
            }
        }
        for (int i = 0; i < c.size(); i++) {
            if (in[i] < t && t < out[i]) {
                return c[i];
            }
        }
        return c.back();
    } else {
        int inp = -1, outp = -1;
        vector<int> in(c.size()-1), out(c.size()-1);
        if (s < c.front()) {
            inp = s-1;
            outp = c.back();
            c.pop_back();
            ins = s;
            outs = c.back()+1;
            for (int i = 0; i < c.size(); i++) {
                out[i] = c[i];
                if (i == 0) {
                    in[i] = ins;
                } else {
                    in[i] = out[i-1];
                }
            }
            for (int i = 0; i < c.size(); i++) {
                if (in[i] < t && t < out[i]) {
                    return c[i];
                }
            }
            return outp;
        } else {
            inp = c.front();
            outp = s+1;
            c.erase(c.begin());
            ins = c.front()-1;
            outs = s;
            for (int i = c.size()-1; i >= 0; i--) {
                in[i] = c[i];
                if (i == c.size()-1) {
                    out[i] = outs;
                } else {
                    out[i] = in[i+1];
                }
            }
            for (int i = 0; i < c.size(); i++) {
                if (in[i] < t && t < out[i]) {
                    return c[i];
                }
            }
            return inp;
        }
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for (int i = 0; i < c.size(); i++) {
      |                         ~~^~~~~~~~~~
stations.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int i = 0; i < c.size(); i++) {
      |                         ~~^~~~~~~~~~
stations.cpp:93:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |             for (int i = 0; i < c.size(); i++) {
      |                             ~~^~~~~~~~~~
stations.cpp:101:31: 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 < c.size(); i++) {
      |                             ~~^~~~~~~~~~
stations.cpp:115:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |                 if (i == c.size()-1) {
      |                     ~~^~~~~~~~~~~~~
stations.cpp:121:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |             for (int i = 0; i < c.size(); i++) {
      |                             ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 411 ms 940 KB Output is correct
2 Correct 302 ms 940 KB Output is correct
3 Correct 626 ms 684 KB Output is correct
4 Correct 462 ms 684 KB Output is correct
5 Correct 380 ms 684 KB Output is correct
6 Correct 308 ms 940 KB Output is correct
7 Correct 292 ms 940 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 776 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 284 ms 684 KB Output is correct
2 Correct 348 ms 684 KB Output is correct
3 Correct 596 ms 684 KB Output is correct
4 Correct 411 ms 684 KB Output is correct
5 Correct 402 ms 684 KB Output is correct
6 Correct 280 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 349 ms 940 KB Output is correct
2 Correct 292 ms 940 KB Output is correct
3 Correct 601 ms 684 KB Output is correct
4 Correct 416 ms 684 KB Output is correct
5 Correct 394 ms 944 KB Output is correct
6 Correct 267 ms 940 KB Output is correct
7 Correct 294 ms 940 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 776 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
11 Correct 413 ms 684 KB Output is correct
12 Correct 295 ms 1044 KB Output is correct
13 Correct 317 ms 940 KB Output is correct
14 Correct 327 ms 684 KB Output is correct
15 Correct 36 ms 768 KB Output is correct
16 Correct 39 ms 768 KB Output is correct
17 Correct 60 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 629 ms 684 KB Output is correct
2 Correct 449 ms 684 KB Output is correct
3 Correct 364 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 433 ms 684 KB Output is correct
8 Correct 572 ms 684 KB Output is correct
9 Correct 365 ms 684 KB Output is correct
10 Correct 321 ms 800 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 324 ms 684 KB Output is correct
17 Correct 335 ms 684 KB Output is correct
18 Correct 362 ms 684 KB Output is correct
19 Correct 331 ms 684 KB Output is correct
20 Correct 349 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 940 KB Output is correct
2 Correct 285 ms 940 KB Output is correct
3 Correct 609 ms 688 KB Output is correct
4 Correct 469 ms 684 KB Output is correct
5 Correct 399 ms 684 KB Output is correct
6 Correct 296 ms 940 KB Output is correct
7 Correct 299 ms 940 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 301 ms 940 KB Output is correct
12 Correct 373 ms 684 KB Output is correct
13 Correct 551 ms 684 KB Output is correct
14 Correct 450 ms 684 KB Output is correct
15 Correct 411 ms 684 KB Output is correct
16 Correct 318 ms 684 KB Output is correct
17 Correct 406 ms 684 KB Output is correct
18 Correct 290 ms 1192 KB Output is correct
19 Correct 309 ms 1444 KB Output is correct
20 Correct 294 ms 684 KB Output is correct
21 Correct 32 ms 768 KB Output is correct
22 Correct 35 ms 768 KB Output is correct
23 Correct 60 ms 716 KB Output is correct
24 Correct 3 ms 764 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 1 ms 764 KB Output is correct
28 Correct 0 ms 784 KB Output is correct
29 Correct 320 ms 684 KB Output is correct
30 Correct 347 ms 684 KB Output is correct
31 Correct 308 ms 684 KB Output is correct
32 Correct 362 ms 684 KB Output is correct
33 Correct 350 ms 684 KB Output is correct
34 Correct 189 ms 940 KB Output is correct
35 Correct 284 ms 1312 KB Output is correct
36 Correct 319 ms 1300 KB Output is correct
37 Correct 324 ms 804 KB Output is correct
38 Correct 291 ms 1048 KB Output is correct
39 Correct 306 ms 1056 KB Output is correct
40 Correct 295 ms 1312 KB Output is correct
41 Correct 293 ms 940 KB Output is correct
42 Correct 31 ms 768 KB Output is correct
43 Correct 55 ms 684 KB Output is correct
44 Correct 68 ms 684 KB Output is correct
45 Correct 88 ms 768 KB Output is correct
46 Correct 208 ms 684 KB Output is correct
47 Correct 206 ms 684 KB Output is correct
48 Correct 32 ms 768 KB Output is correct
49 Correct 37 ms 980 KB Output is correct