답안 #546797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546797 2022-04-08T13:51:50 Z LucaDantas 기지국 (IOI20_stations) C++17
100 / 100
817 ms 868 KB
#include "stations.h"
#include <map>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>

constexpr int maxn = 1010;

std::vector<int> g[maxn];
int in[maxn], out[maxn], cor[maxn], t;

void dfs(int u, int p) {
    in[u] = t++;
    for(int v : g[u]) if(v != p) {
        cor[v] = cor[u]^1;
        dfs(v, u);
    }
    out[u] = t++;
}

void clear() {
    memset(in, 0, sizeof in);
    memset(out, 0, sizeof out);
    memset(cor, 0, sizeof cor);
    for(int i = 0; i < maxn; i++)
        g[i].clear();
    t = 0;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    clear();
    for(int i = 0; i < n-1; i++)
        g[u[i]].push_back(v[i]), g[v[i]].push_back(u[i]);
    dfs(0, 0);

    std::map<int,int> mp;
    int coord = 0;
    for(int i = 0; i < n; i++)
        mp[!cor[i] ? in[i] : out[i]] = 0;
    for(auto& it : mp)
        it.second = coord++;

    std::vector<int> labels;
    for(int i = 0; i < n; i++)
        labels.push_back(mp[!cor[i] ? in[i] : out[i]]);
    
    return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if(c[0] > s) {
        // sou in, todos os meus filhos são out
        if(t < s) return c.back();
        for(int x : c)
            if(t <= x) return x;
        return c.back();
    } else {
        // sou out, todos os meus filhos sao in
        std::reverse(c.begin(), c.end()); // comeco do meu ultimo filho
        if(t > s) return c.back(); // c.back() é o meu pai
        for(int x : c)
            if(t >= x) return x;
        return c.back();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 499 ms 668 KB Output is correct
2 Correct 346 ms 656 KB Output is correct
3 Correct 768 ms 508 KB Output is correct
4 Correct 568 ms 500 KB Output is correct
5 Correct 473 ms 512 KB Output is correct
6 Correct 425 ms 676 KB Output is correct
7 Correct 395 ms 672 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 4 ms 496 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 375 ms 520 KB Output is correct
2 Correct 434 ms 548 KB Output is correct
3 Correct 817 ms 512 KB Output is correct
4 Correct 533 ms 416 KB Output is correct
5 Correct 439 ms 416 KB Output is correct
6 Correct 402 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 392 ms 744 KB Output is correct
2 Correct 422 ms 648 KB Output is correct
3 Correct 765 ms 520 KB Output is correct
4 Correct 599 ms 520 KB Output is correct
5 Correct 502 ms 520 KB Output is correct
6 Correct 439 ms 656 KB Output is correct
7 Correct 441 ms 644 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 542 ms 524 KB Output is correct
12 Correct 466 ms 796 KB Output is correct
13 Correct 400 ms 736 KB Output is correct
14 Correct 377 ms 520 KB Output is correct
15 Correct 45 ms 444 KB Output is correct
16 Correct 58 ms 544 KB Output is correct
17 Correct 108 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 712 ms 520 KB Output is correct
2 Correct 626 ms 496 KB Output is correct
3 Correct 590 ms 544 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 4 ms 500 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 538 ms 416 KB Output is correct
8 Correct 718 ms 416 KB Output is correct
9 Correct 593 ms 420 KB Output is correct
10 Correct 462 ms 524 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 3 ms 524 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 463 ms 520 KB Output is correct
17 Correct 438 ms 420 KB Output is correct
18 Correct 490 ms 420 KB Output is correct
19 Correct 476 ms 516 KB Output is correct
20 Correct 433 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 485 ms 692 KB Output is correct
2 Correct 407 ms 676 KB Output is correct
3 Correct 811 ms 516 KB Output is correct
4 Correct 571 ms 520 KB Output is correct
5 Correct 467 ms 416 KB Output is correct
6 Correct 430 ms 640 KB Output is correct
7 Correct 403 ms 628 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 394 ms 640 KB Output is correct
12 Correct 484 ms 524 KB Output is correct
13 Correct 683 ms 416 KB Output is correct
14 Correct 519 ms 516 KB Output is correct
15 Correct 500 ms 416 KB Output is correct
16 Correct 381 ms 544 KB Output is correct
17 Correct 569 ms 484 KB Output is correct
18 Correct 410 ms 636 KB Output is correct
19 Correct 368 ms 756 KB Output is correct
20 Correct 418 ms 548 KB Output is correct
21 Correct 60 ms 548 KB Output is correct
22 Correct 61 ms 520 KB Output is correct
23 Correct 86 ms 572 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 6 ms 500 KB Output is correct
26 Correct 4 ms 496 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 486 ms 520 KB Output is correct
30 Correct 470 ms 524 KB Output is correct
31 Correct 465 ms 416 KB Output is correct
32 Correct 410 ms 524 KB Output is correct
33 Correct 426 ms 528 KB Output is correct
34 Correct 289 ms 672 KB Output is correct
35 Correct 394 ms 672 KB Output is correct
36 Correct 401 ms 648 KB Output is correct
37 Correct 365 ms 640 KB Output is correct
38 Correct 374 ms 648 KB Output is correct
39 Correct 348 ms 652 KB Output is correct
40 Correct 385 ms 868 KB Output is correct
41 Correct 375 ms 852 KB Output is correct
42 Correct 54 ms 544 KB Output is correct
43 Correct 93 ms 572 KB Output is correct
44 Correct 123 ms 644 KB Output is correct
45 Correct 149 ms 544 KB Output is correct
46 Correct 231 ms 552 KB Output is correct
47 Correct 275 ms 544 KB Output is correct
48 Correct 57 ms 728 KB Output is correct
49 Correct 53 ms 836 KB Output is correct