답안 #620780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
620780 2022-08-03T09:05:50 Z wiwiho 기지국 (IOI20_stations) C++14
100 / 100
874 ms 796 KB
#include "stations.h"

#include <bits/stdc++.h>

#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
#define eb emplace_back
#define ef emplace_front
#define pob pop_back()
#define pof pop_front()
#define mp make_pair
#define F first
#define S second
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) { \
    for(auto pv : a) b << pv << " "; \
    b << "\n"; \
}

using namespace std;

typedef long long ll;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {

    vector<vector<int>> g(n);
    vector<int> ans(n);
    int ts = -1;

    function<void(int, int, int)> dfs = [&](int now, int p, int d){
        if(d % 2 == 0) ans[now] = ++ts;
        for(int i : g[now]){
            if(i == p) continue;
            dfs(i, now, d + 1);
        }
        if(d % 2 == 1) ans[now] = ++ts;
    };

    for(int i = 0; i < n - 1; i++){
        g[u[i]].eb(v[i]);
        g[v[i]].eb(u[i]);
    }
    for(int i = 0; i < n; i++){
        if(g[i].size() > 1) continue;
        dfs(i, i, 0);
        break;
    }

    //cerr << "label ";
    //printv(ans, cerr);

    return ans;
}

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

    int ty;
    if(s < c[0]) ty = 0;
    else ty = 1;
    //cerr << "find " << s << " -> " << t << "\n";
    //cerr << "ty " << ty << "\n";
    // 0:in 1:out

    if(ty == 0){
        // c.back(): parent
        int lst = s;
        for(int i = 0; i + 1 < (int)c.size(); i++){
            //cerr << "range " << c[i] << " : " << lst << " " << c[i] << "\n";
            if(lst < t && t <= c[i]) return c[i];
            lst = c[i];
        }
        return c.back();
    }
    else{
        // c[0]: parent
        int lst = s;
        for(int i = (int)c.size() - 1; i > 0; i--){
            //cerr << "range " << c[i] << " : " << lst << " " << c[i] << "\n";
            if(c[i] <= t && t < lst) return c[i];
            lst = c[i];
        }
        return c[0];
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 495 ms 672 KB Output is correct
2 Correct 483 ms 628 KB Output is correct
3 Correct 612 ms 468 KB Output is correct
4 Correct 690 ms 508 KB Output is correct
5 Correct 550 ms 508 KB Output is correct
6 Correct 409 ms 676 KB Output is correct
7 Correct 427 ms 676 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 500 KB Output is correct
2 Correct 454 ms 508 KB Output is correct
3 Correct 832 ms 416 KB Output is correct
4 Correct 624 ms 416 KB Output is correct
5 Correct 585 ms 420 KB Output is correct
6 Correct 416 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 544 ms 672 KB Output is correct
2 Correct 424 ms 676 KB Output is correct
3 Correct 874 ms 416 KB Output is correct
4 Correct 715 ms 500 KB Output is correct
5 Correct 552 ms 416 KB Output is correct
6 Correct 456 ms 696 KB Output is correct
7 Correct 464 ms 632 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 496 KB Output is correct
10 Correct 2 ms 524 KB Output is correct
11 Correct 539 ms 496 KB Output is correct
12 Correct 381 ms 752 KB Output is correct
13 Correct 460 ms 672 KB Output is correct
14 Correct 376 ms 508 KB Output is correct
15 Correct 38 ms 492 KB Output is correct
16 Correct 60 ms 544 KB Output is correct
17 Correct 106 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 849 ms 504 KB Output is correct
2 Correct 644 ms 500 KB Output is correct
3 Correct 545 ms 420 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 527 ms 416 KB Output is correct
8 Correct 866 ms 496 KB Output is correct
9 Correct 662 ms 420 KB Output is correct
10 Correct 613 ms 416 KB Output is correct
11 Correct 4 ms 492 KB Output is correct
12 Correct 5 ms 500 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 3 ms 488 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 488 ms 508 KB Output is correct
17 Correct 451 ms 420 KB Output is correct
18 Correct 544 ms 504 KB Output is correct
19 Correct 513 ms 508 KB Output is correct
20 Correct 507 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 542 ms 672 KB Output is correct
2 Correct 476 ms 696 KB Output is correct
3 Correct 822 ms 416 KB Output is correct
4 Correct 582 ms 420 KB Output is correct
5 Correct 511 ms 416 KB Output is correct
6 Correct 408 ms 632 KB Output is correct
7 Correct 423 ms 648 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 487 ms 544 KB Output is correct
12 Correct 570 ms 512 KB Output is correct
13 Correct 838 ms 468 KB Output is correct
14 Correct 660 ms 416 KB Output is correct
15 Correct 660 ms 484 KB Output is correct
16 Correct 572 ms 544 KB Output is correct
17 Correct 551 ms 500 KB Output is correct
18 Correct 481 ms 752 KB Output is correct
19 Correct 665 ms 712 KB Output is correct
20 Correct 413 ms 504 KB Output is correct
21 Correct 59 ms 440 KB Output is correct
22 Correct 63 ms 624 KB Output is correct
23 Correct 122 ms 560 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 488 KB Output is correct
26 Correct 4 ms 492 KB Output is correct
27 Correct 4 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 465 ms 416 KB Output is correct
30 Correct 520 ms 420 KB Output is correct
31 Correct 504 ms 416 KB Output is correct
32 Correct 447 ms 420 KB Output is correct
33 Correct 529 ms 420 KB Output is correct
34 Correct 305 ms 636 KB Output is correct
35 Correct 391 ms 632 KB Output is correct
36 Correct 414 ms 752 KB Output is correct
37 Correct 449 ms 776 KB Output is correct
38 Correct 403 ms 588 KB Output is correct
39 Correct 443 ms 632 KB Output is correct
40 Correct 398 ms 796 KB Output is correct
41 Correct 405 ms 620 KB Output is correct
42 Correct 80 ms 596 KB Output is correct
43 Correct 103 ms 676 KB Output is correct
44 Correct 123 ms 508 KB Output is correct
45 Correct 159 ms 548 KB Output is correct
46 Correct 334 ms 504 KB Output is correct
47 Correct 288 ms 548 KB Output is correct
48 Correct 56 ms 548 KB Output is correct
49 Correct 68 ms 544 KB Output is correct