답안 #367304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367304 2021-02-16T20:19:23 Z PurpleCrayon 기지국 (IOI20_stations) C++17
100 / 100
1148 ms 1368 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

#define sz(v) int(v.size())

int tt;
vector<int> ans;
vector<vector<int>> adj;

void dfs(int c=0, int p=-1, bool b=0){
    if (!b) ans[c] = tt++;
    for (auto nxt : adj[c]) if (nxt != p) dfs(nxt, c, b^1);
    if (b) ans[c] = tt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    ans.assign(n, -1), adj.assign(n, vector<int>()), tt=0;
    for (int i = 0; i < n-1; i++) 
        adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);
    dfs();
    return ans;
}

int find_next_station(int s, int t, vector<int> c) {
    if (s == 0){ //ans for the root
        for (auto nxt : c) if (nxt >= t) return nxt;
        assert(false);
    }
    bool b=s>c[0];

    if (b){ //i'm postorder
        int p = c[0];
        if (sz(c) == 1 || t < c[1] || t > s)
            return p; 
        
        int ans=-1;
        for (auto nxt : c) if (nxt != p) {
            if (nxt <= t) ans = nxt;
        }
        if (ans == -1) return p;
        return ans;

    } else { //i'm preorder
        int p = c[sz(c)-1];
        if (sz(c) == 1 || t < s || t >= c[sz(c)-1]) 
            return p;

        int ans=-1;
        for (auto nxt : c) if (nxt != p) {
            if (nxt >= t){
                return nxt;
            }
        }
        return p;
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:13: warning: unused variable 'ans' [-Wunused-variable]
   48 |         int ans=-1;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 606 ms 1224 KB Output is correct
2 Correct 464 ms 952 KB Output is correct
3 Correct 1047 ms 756 KB Output is correct
4 Correct 660 ms 996 KB Output is correct
5 Correct 665 ms 868 KB Output is correct
6 Correct 520 ms 980 KB Output is correct
7 Correct 547 ms 996 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 5 ms 736 KB Output is correct
10 Correct 1 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 515 ms 884 KB Output is correct
2 Correct 690 ms 904 KB Output is correct
3 Correct 965 ms 868 KB Output is correct
4 Correct 733 ms 996 KB Output is correct
5 Correct 653 ms 868 KB Output is correct
6 Correct 582 ms 1012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 653 ms 1368 KB Output is correct
2 Correct 488 ms 864 KB Output is correct
3 Correct 1148 ms 736 KB Output is correct
4 Correct 785 ms 868 KB Output is correct
5 Correct 691 ms 868 KB Output is correct
6 Correct 455 ms 864 KB Output is correct
7 Correct 475 ms 992 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 5 ms 756 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
11 Correct 627 ms 984 KB Output is correct
12 Correct 500 ms 1272 KB Output is correct
13 Correct 509 ms 884 KB Output is correct
14 Correct 531 ms 756 KB Output is correct
15 Correct 62 ms 860 KB Output is correct
16 Correct 73 ms 872 KB Output is correct
17 Correct 106 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 836 ms 868 KB Output is correct
2 Correct 737 ms 736 KB Output is correct
3 Correct 593 ms 868 KB Output is correct
4 Correct 3 ms 756 KB Output is correct
5 Correct 4 ms 736 KB Output is correct
6 Correct 1 ms 736 KB Output is correct
7 Correct 613 ms 736 KB Output is correct
8 Correct 876 ms 1012 KB Output is correct
9 Correct 779 ms 868 KB Output is correct
10 Correct 594 ms 736 KB Output is correct
11 Correct 7 ms 916 KB Output is correct
12 Correct 6 ms 756 KB Output is correct
13 Correct 4 ms 868 KB Output is correct
14 Correct 5 ms 992 KB Output is correct
15 Correct 2 ms 868 KB Output is correct
16 Correct 515 ms 756 KB Output is correct
17 Correct 457 ms 868 KB Output is correct
18 Correct 678 ms 868 KB Output is correct
19 Correct 561 ms 736 KB Output is correct
20 Correct 601 ms 864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 604 ms 920 KB Output is correct
2 Correct 574 ms 952 KB Output is correct
3 Correct 1000 ms 736 KB Output is correct
4 Correct 764 ms 756 KB Output is correct
5 Correct 693 ms 756 KB Output is correct
6 Correct 525 ms 972 KB Output is correct
7 Correct 525 ms 864 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 5 ms 860 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
11 Correct 455 ms 884 KB Output is correct
12 Correct 630 ms 756 KB Output is correct
13 Correct 1015 ms 876 KB Output is correct
14 Correct 577 ms 868 KB Output is correct
15 Correct 560 ms 864 KB Output is correct
16 Correct 436 ms 756 KB Output is correct
17 Correct 664 ms 868 KB Output is correct
18 Correct 482 ms 1120 KB Output is correct
19 Correct 533 ms 1204 KB Output is correct
20 Correct 477 ms 736 KB Output is correct
21 Correct 71 ms 756 KB Output is correct
22 Correct 68 ms 820 KB Output is correct
23 Correct 111 ms 1004 KB Output is correct
24 Correct 6 ms 756 KB Output is correct
25 Correct 6 ms 756 KB Output is correct
26 Correct 5 ms 736 KB Output is correct
27 Correct 5 ms 868 KB Output is correct
28 Correct 2 ms 916 KB Output is correct
29 Correct 535 ms 864 KB Output is correct
30 Correct 495 ms 756 KB Output is correct
31 Correct 561 ms 876 KB Output is correct
32 Correct 537 ms 868 KB Output is correct
33 Correct 550 ms 884 KB Output is correct
34 Correct 341 ms 936 KB Output is correct
35 Correct 458 ms 1064 KB Output is correct
36 Correct 470 ms 1068 KB Output is correct
37 Correct 500 ms 1248 KB Output is correct
38 Correct 479 ms 884 KB Output is correct
39 Correct 574 ms 1076 KB Output is correct
40 Correct 513 ms 1204 KB Output is correct
41 Correct 496 ms 996 KB Output is correct
42 Correct 78 ms 804 KB Output is correct
43 Correct 107 ms 756 KB Output is correct
44 Correct 125 ms 872 KB Output is correct
45 Correct 206 ms 756 KB Output is correct
46 Correct 337 ms 736 KB Output is correct
47 Correct 299 ms 756 KB Output is correct
48 Correct 75 ms 988 KB Output is correct
49 Correct 73 ms 908 KB Output is correct