답안 #531477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531477 2022-02-28T19:31:13 Z sliviu 기지국 (IOI20_stations) C++17
100 / 100
947 ms 736 KB
#include <bits/stdc++.h>
#include <stations.h>

using namespace std;

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    int t = -1;
    vector<vector<int>> G(n);
    vector<int> sol(n);
    for (int i = 0; i < n - 1; ++i) {
        G[u[i]].emplace_back(v[i]);
        G[v[i]].emplace_back(u[i]);
    }
    function<void(int, int, int)> dfs = [&](int node, int last, int lvl) {
        if (!lvl)
            sol[node] = ++t;
        for (auto x : G[node])
            if (x != last)
                dfs(x, node, lvl ^ 1);
        if (lvl)
            sol[node] = ++t;
    };
    dfs(0, -1, 0);
    return sol;
}

int find_next_station(int s, int f, vector<int> adj) {
    int tins, touts, ft,mini=INT_MAX,maxi=0;
    int isin = 1;
    for (auto x : adj) {
        if (x < s)
            isin = 0;
        mini = min(mini, x);
        maxi = max(maxi, x);
    }
    if (isin)
        tins = s, ft = maxi, touts = ft - 1;
    else
        touts = s, ft = mini, tins = ft + 1;
    //cerr << ft << '\n';
    if (tins <= f && f <= touts) {
        int last = s;
        if (isin)
            sort(adj.begin(), adj.end());
        else
            sort(adj.begin(), adj.end(), greater<int>());
        for (auto x : adj)
            if (x != ft) {
                int curtin, curtout;
                if (isin)
                    curtout = x, curtin = last + 1, last = x;
                else
                    curtin = x, curtout = last - 1, last = x;
                //cerr << curtin << ' ' << curtout << '\n';
                if (curtin <= f && f <= curtout)
                    return x;
            }
    }
    return ft;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 562 ms 648 KB Output is correct
2 Correct 416 ms 608 KB Output is correct
3 Correct 908 ms 400 KB Output is correct
4 Correct 709 ms 428 KB Output is correct
5 Correct 598 ms 400 KB Output is correct
6 Correct 490 ms 520 KB Output is correct
7 Correct 415 ms 608 KB Output is correct
8 Correct 3 ms 556 KB Output is correct
9 Correct 3 ms 480 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 513 ms 492 KB Output is correct
2 Correct 465 ms 480 KB Output is correct
3 Correct 847 ms 468 KB Output is correct
4 Correct 572 ms 400 KB Output is correct
5 Correct 588 ms 488 KB Output is correct
6 Correct 435 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 496 ms 660 KB Output is correct
2 Correct 385 ms 600 KB Output is correct
3 Correct 843 ms 456 KB Output is correct
4 Correct 728 ms 404 KB Output is correct
5 Correct 544 ms 404 KB Output is correct
6 Correct 370 ms 628 KB Output is correct
7 Correct 425 ms 612 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 617 ms 488 KB Output is correct
12 Correct 445 ms 652 KB Output is correct
13 Correct 473 ms 520 KB Output is correct
14 Correct 447 ms 520 KB Output is correct
15 Correct 50 ms 524 KB Output is correct
16 Correct 73 ms 528 KB Output is correct
17 Correct 114 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 785 ms 476 KB Output is correct
2 Correct 651 ms 400 KB Output is correct
3 Correct 531 ms 464 KB Output is correct
4 Correct 3 ms 472 KB Output is correct
5 Correct 5 ms 476 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 580 ms 400 KB Output is correct
8 Correct 947 ms 404 KB Output is correct
9 Correct 684 ms 400 KB Output is correct
10 Correct 600 ms 400 KB Output is correct
11 Correct 4 ms 472 KB Output is correct
12 Correct 5 ms 536 KB Output is correct
13 Correct 4 ms 476 KB Output is correct
14 Correct 4 ms 476 KB Output is correct
15 Correct 1 ms 476 KB Output is correct
16 Correct 558 ms 488 KB Output is correct
17 Correct 481 ms 400 KB Output is correct
18 Correct 472 ms 464 KB Output is correct
19 Correct 487 ms 400 KB Output is correct
20 Correct 498 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 485 ms 664 KB Output is correct
2 Correct 489 ms 520 KB Output is correct
3 Correct 805 ms 404 KB Output is correct
4 Correct 614 ms 400 KB Output is correct
5 Correct 538 ms 400 KB Output is correct
6 Correct 423 ms 648 KB Output is correct
7 Correct 416 ms 484 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 3 ms 464 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 322 ms 532 KB Output is correct
12 Correct 559 ms 532 KB Output is correct
13 Correct 858 ms 404 KB Output is correct
14 Correct 630 ms 488 KB Output is correct
15 Correct 560 ms 484 KB Output is correct
16 Correct 421 ms 520 KB Output is correct
17 Correct 589 ms 404 KB Output is correct
18 Correct 466 ms 520 KB Output is correct
19 Correct 466 ms 736 KB Output is correct
20 Correct 484 ms 488 KB Output is correct
21 Correct 52 ms 420 KB Output is correct
22 Correct 71 ms 528 KB Output is correct
23 Correct 97 ms 552 KB Output is correct
24 Correct 8 ms 468 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 4 ms 476 KB Output is correct
27 Correct 3 ms 476 KB Output is correct
28 Correct 1 ms 472 KB Output is correct
29 Correct 528 ms 532 KB Output is correct
30 Correct 513 ms 400 KB Output is correct
31 Correct 449 ms 404 KB Output is correct
32 Correct 455 ms 404 KB Output is correct
33 Correct 489 ms 428 KB Output is correct
34 Correct 307 ms 700 KB Output is correct
35 Correct 468 ms 656 KB Output is correct
36 Correct 468 ms 684 KB Output is correct
37 Correct 504 ms 680 KB Output is correct
38 Correct 429 ms 548 KB Output is correct
39 Correct 431 ms 564 KB Output is correct
40 Correct 431 ms 732 KB Output is correct
41 Correct 441 ms 568 KB Output is correct
42 Correct 57 ms 544 KB Output is correct
43 Correct 121 ms 528 KB Output is correct
44 Correct 124 ms 532 KB Output is correct
45 Correct 129 ms 544 KB Output is correct
46 Correct 275 ms 488 KB Output is correct
47 Correct 291 ms 668 KB Output is correct
48 Correct 53 ms 532 KB Output is correct
49 Correct 49 ms 656 KB Output is correct