답안 #804962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804962 2023-08-03T12:11:41 Z PixelCat 기지국 (IOI20_stations) C++14
100 / 100
802 ms 804 KB
#include "stations.h"

#ifdef NYAOWO
#include "stub.cpp"
#endif

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 1000;

vector<int> adj[MAXN + 10];
int ids[MAXN + 10];
int siz[MAXN + 10];
int cur_id;

void dfs1(int n, int p, int d) {
    if(d) {
        ids[n] = cur_id;
        cur_id++;
    }
    siz[n] = 0;
    for(auto &i:adj[n]) if(i != p) {
        dfs1(i, n, 1 - d);
        siz[n] += siz[i] + 1;
    }
    if(!d) {
        ids[n] = cur_id;
        cur_id++;
    }
}

int encode(int id, int sz) {
    return id * MAXN + sz;
}
int encode(pii p) {
    return encode(p.F, p.S);
}
pii decode(int x) {
    return pii(x / MAXN, x % MAXN);
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    For(i, 0, n - 1) {
        adj[i].clear();
    }
    int m = sz(u);
    For(i, 0, m - 1) {
        adj[u[i]].eb(v[i]);
        adj[v[i]].eb(u[i]);
    }
    cur_id = 0;
    dfs1(0, 0, 0);
    vector<int> labels(n);
    For(i, 0, n - 1) labels[i] = ids[i];
    return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if(sz(c) == 1) return c[0];
    int n = sz(c);
    if(s < c[0]) {
        int p = c.back();
        if(t <= s || t >= p) return p;
        for(auto &i:c) if(t <= i) return i;
    } else {
        reverse(all(c));
        int p = c.back();
        if(t <= p || t >= s) return p;
        for(auto &i:c) if(t >= i) return i;
    }
    return -1;
}

/*

1
5 10
0 1
1 2
1 3
2 4
2
2 0 1
1 3 3

*/

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:72:9: warning: unused variable 'n' [-Wunused-variable]
   72 |     int n = sz(c);
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 392 ms 548 KB Output is correct
2 Correct 403 ms 668 KB Output is correct
3 Correct 725 ms 532 KB Output is correct
4 Correct 533 ms 616 KB Output is correct
5 Correct 371 ms 524 KB Output is correct
6 Correct 306 ms 668 KB Output is correct
7 Correct 321 ms 536 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 528 KB Output is correct
2 Correct 335 ms 536 KB Output is correct
3 Correct 719 ms 532 KB Output is correct
4 Correct 545 ms 528 KB Output is correct
5 Correct 412 ms 724 KB Output is correct
6 Correct 366 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 664 KB Output is correct
2 Correct 469 ms 672 KB Output is correct
3 Correct 710 ms 532 KB Output is correct
4 Correct 461 ms 536 KB Output is correct
5 Correct 552 ms 596 KB Output is correct
6 Correct 428 ms 660 KB Output is correct
7 Correct 304 ms 544 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 1 ms 628 KB Output is correct
11 Correct 454 ms 436 KB Output is correct
12 Correct 306 ms 780 KB Output is correct
13 Correct 278 ms 652 KB Output is correct
14 Correct 436 ms 548 KB Output is correct
15 Correct 41 ms 620 KB Output is correct
16 Correct 48 ms 620 KB Output is correct
17 Correct 90 ms 804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 763 ms 532 KB Output is correct
2 Correct 620 ms 532 KB Output is correct
3 Correct 575 ms 532 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 567 ms 532 KB Output is correct
8 Correct 802 ms 532 KB Output is correct
9 Correct 588 ms 536 KB Output is correct
10 Correct 490 ms 544 KB Output is correct
11 Correct 5 ms 624 KB Output is correct
12 Correct 3 ms 496 KB Output is correct
13 Correct 4 ms 572 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 500 ms 416 KB Output is correct
17 Correct 349 ms 532 KB Output is correct
18 Correct 433 ms 536 KB Output is correct
19 Correct 517 ms 416 KB Output is correct
20 Correct 530 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 656 KB Output is correct
2 Correct 327 ms 692 KB Output is correct
3 Correct 691 ms 528 KB Output is correct
4 Correct 430 ms 536 KB Output is correct
5 Correct 384 ms 612 KB Output is correct
6 Correct 336 ms 676 KB Output is correct
7 Correct 325 ms 536 KB Output is correct
8 Correct 1 ms 488 KB Output is correct
9 Correct 3 ms 684 KB Output is correct
10 Correct 0 ms 624 KB Output is correct
11 Correct 397 ms 600 KB Output is correct
12 Correct 419 ms 544 KB Output is correct
13 Correct 742 ms 528 KB Output is correct
14 Correct 528 ms 528 KB Output is correct
15 Correct 437 ms 532 KB Output is correct
16 Correct 418 ms 528 KB Output is correct
17 Correct 477 ms 536 KB Output is correct
18 Correct 293 ms 644 KB Output is correct
19 Correct 409 ms 652 KB Output is correct
20 Correct 329 ms 548 KB Output is correct
21 Correct 52 ms 544 KB Output is correct
22 Correct 48 ms 600 KB Output is correct
23 Correct 77 ms 556 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 0 ms 492 KB Output is correct
29 Correct 383 ms 528 KB Output is correct
30 Correct 427 ms 416 KB Output is correct
31 Correct 403 ms 528 KB Output is correct
32 Correct 344 ms 420 KB Output is correct
33 Correct 480 ms 536 KB Output is correct
34 Correct 290 ms 544 KB Output is correct
35 Correct 391 ms 764 KB Output is correct
36 Correct 324 ms 668 KB Output is correct
37 Correct 321 ms 648 KB Output is correct
38 Correct 405 ms 720 KB Output is correct
39 Correct 244 ms 644 KB Output is correct
40 Correct 322 ms 656 KB Output is correct
41 Correct 429 ms 644 KB Output is correct
42 Correct 48 ms 600 KB Output is correct
43 Correct 67 ms 556 KB Output is correct
44 Correct 91 ms 612 KB Output is correct
45 Correct 104 ms 536 KB Output is correct
46 Correct 239 ms 532 KB Output is correct
47 Correct 285 ms 532 KB Output is correct
48 Correct 47 ms 704 KB Output is correct
49 Correct 51 ms 736 KB Output is correct