# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709934 | 2023-03-14T21:02:14 Z | raysh07 | Stations (IOI20_stations) | C++17 | 957 ms | 932 KB |
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define INF (int)1e9 const int N = 1005; int timer = 0; int tin[N], tout[N]; vector <int> adj[N]; int ans[N]; void dfs(int u, int par = -1, int dist = 0){ tin[u] = ++timer; for (int v: adj[u]){ if (v != par){ dfs(v, u, dist + 1); } } tout[u] = ++timer; if (dist & 1) ans[u] = tout[u]; else ans[u] = tin[u]; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { for (int i=0; i<n-1; i++){ adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(0); int ptr = -1; set <int> st; map <int, int> comp; for (int i=0; i<n; i++) st.insert(ans[i]); for (auto x: st) comp[x] = ++ptr; assert(st.size() == n); vector <int> lab; for (int i=0; i<n; i++) lab.push_back(comp[ans[i]]); for (int i=0; i<n; i++) adj[i].clear(); return lab; } int find_next_station(int s, int t, vector<int> c) { if (s==0){ //root for (auto x: c){ if (x >= t) return x; } assert(false); } if (c.size() == 1) return c[0]; //either s is tin time of u, in which case, rest all are tout times //tout of everything else shud be strictly larger //else s is tout time of u, in which case rest all are tin times //tin of everything else shud be strictly smaller if (s > c[0]){ //this is tout time //rest all are tin time //if t is not in range [c[1], s] its not in subtree if (t < c[1] || t > s) return c[0]; c.push_back(INF); for (int i=2; i<c.size(); i++){ if (c[i] > t) return c[i-1]; } } else { assert(s < c[0]); //now range is [s, c[c.size() - 2] if (t < s || t > c[c.size() - 2]) return c.back(); for (int i=0; i<c.size() - 1; i++){ if (t <= c[i]) return c[i]; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 624 ms | 752 KB | Output is correct |
2 | Correct | 488 ms | 668 KB | Output is correct |
3 | Correct | 864 ms | 428 KB | Output is correct |
4 | Correct | 732 ms | 664 KB | Output is correct |
5 | Correct | 667 ms | 672 KB | Output is correct |
6 | Correct | 409 ms | 676 KB | Output is correct |
7 | Correct | 462 ms | 656 KB | Output is correct |
8 | Correct | 2 ms | 628 KB | Output is correct |
9 | Correct | 4 ms | 628 KB | Output is correct |
10 | Correct | 1 ms | 612 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 475 ms | 664 KB | Output is correct |
2 | Correct | 568 ms | 664 KB | Output is correct |
3 | Correct | 957 ms | 508 KB | Output is correct |
4 | Correct | 717 ms | 548 KB | Output is correct |
5 | Correct | 573 ms | 548 KB | Output is correct |
6 | Correct | 383 ms | 652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 538 ms | 752 KB | Output is correct |
2 | Correct | 451 ms | 672 KB | Output is correct |
3 | Correct | 775 ms | 636 KB | Output is correct |
4 | Correct | 594 ms | 524 KB | Output is correct |
5 | Correct | 603 ms | 548 KB | Output is correct |
6 | Correct | 479 ms | 676 KB | Output is correct |
7 | Correct | 434 ms | 656 KB | Output is correct |
8 | Correct | 3 ms | 628 KB | Output is correct |
9 | Correct | 4 ms | 760 KB | Output is correct |
10 | Correct | 1 ms | 620 KB | Output is correct |
11 | Correct | 522 ms | 532 KB | Output is correct |
12 | Correct | 476 ms | 768 KB | Output is correct |
13 | Correct | 474 ms | 860 KB | Output is correct |
14 | Correct | 397 ms | 648 KB | Output is correct |
15 | Correct | 57 ms | 572 KB | Output is correct |
16 | Correct | 60 ms | 672 KB | Output is correct |
17 | Correct | 104 ms | 788 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 926 ms | 544 KB | Output is correct |
2 | Correct | 648 ms | 532 KB | Output is correct |
3 | Correct | 518 ms | 420 KB | Output is correct |
4 | Correct | 2 ms | 748 KB | Output is correct |
5 | Correct | 4 ms | 488 KB | Output is correct |
6 | Correct | 0 ms | 620 KB | Output is correct |
7 | Correct | 517 ms | 688 KB | Output is correct |
8 | Correct | 738 ms | 660 KB | Output is correct |
9 | Correct | 689 ms | 536 KB | Output is correct |
10 | Correct | 513 ms | 536 KB | Output is correct |
11 | Correct | 5 ms | 492 KB | Output is correct |
12 | Correct | 5 ms | 500 KB | Output is correct |
13 | Correct | 4 ms | 728 KB | Output is correct |
14 | Correct | 4 ms | 492 KB | Output is correct |
15 | Correct | 2 ms | 628 KB | Output is correct |
16 | Correct | 463 ms | 536 KB | Output is correct |
17 | Correct | 491 ms | 656 KB | Output is correct |
18 | Correct | 501 ms | 572 KB | Output is correct |
19 | Correct | 529 ms | 676 KB | Output is correct |
20 | Correct | 506 ms | 416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 471 ms | 660 KB | Output is correct |
2 | Correct | 420 ms | 664 KB | Output is correct |
3 | Correct | 737 ms | 656 KB | Output is correct |
4 | Correct | 696 ms | 540 KB | Output is correct |
5 | Correct | 626 ms | 416 KB | Output is correct |
6 | Correct | 432 ms | 788 KB | Output is correct |
7 | Correct | 428 ms | 676 KB | Output is correct |
8 | Correct | 3 ms | 628 KB | Output is correct |
9 | Correct | 4 ms | 568 KB | Output is correct |
10 | Correct | 1 ms | 620 KB | Output is correct |
11 | Correct | 482 ms | 660 KB | Output is correct |
12 | Correct | 566 ms | 676 KB | Output is correct |
13 | Correct | 851 ms | 516 KB | Output is correct |
14 | Correct | 729 ms | 664 KB | Output is correct |
15 | Correct | 535 ms | 532 KB | Output is correct |
16 | Correct | 437 ms | 676 KB | Output is correct |
17 | Correct | 577 ms | 548 KB | Output is correct |
18 | Correct | 457 ms | 788 KB | Output is correct |
19 | Correct | 524 ms | 860 KB | Output is correct |
20 | Correct | 375 ms | 668 KB | Output is correct |
21 | Correct | 61 ms | 572 KB | Output is correct |
22 | Correct | 56 ms | 700 KB | Output is correct |
23 | Correct | 95 ms | 932 KB | Output is correct |
24 | Correct | 5 ms | 616 KB | Output is correct |
25 | Correct | 5 ms | 620 KB | Output is correct |
26 | Correct | 2 ms | 500 KB | Output is correct |
27 | Correct | 4 ms | 636 KB | Output is correct |
28 | Correct | 2 ms | 608 KB | Output is correct |
29 | Correct | 530 ms | 532 KB | Output is correct |
30 | Correct | 431 ms | 524 KB | Output is correct |
31 | Correct | 560 ms | 532 KB | Output is correct |
32 | Correct | 521 ms | 524 KB | Output is correct |
33 | Correct | 536 ms | 416 KB | Output is correct |
34 | Correct | 257 ms | 668 KB | Output is correct |
35 | Correct | 448 ms | 792 KB | Output is correct |
36 | Correct | 449 ms | 792 KB | Output is correct |
37 | Correct | 459 ms | 768 KB | Output is correct |
38 | Correct | 425 ms | 904 KB | Output is correct |
39 | Correct | 451 ms | 916 KB | Output is correct |
40 | Correct | 453 ms | 896 KB | Output is correct |
41 | Correct | 391 ms | 760 KB | Output is correct |
42 | Correct | 62 ms | 676 KB | Output is correct |
43 | Correct | 92 ms | 828 KB | Output is correct |
44 | Correct | 136 ms | 672 KB | Output is correct |
45 | Correct | 180 ms | 700 KB | Output is correct |
46 | Correct | 239 ms | 664 KB | Output is correct |
47 | Correct | 319 ms | 656 KB | Output is correct |
48 | Correct | 60 ms | 856 KB | Output is correct |
49 | Correct | 63 ms | 872 KB | Output is correct |