답안 #606434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
606434 2022-07-26T06:43:32 Z Sam_a17 기지국 (IOI20_stations) C++14
100 / 100
891 ms 844 KB
#include <bits/stdc++.h>
using namespace std;
 
#define sz(x) (int((x).size()))
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(x) cout << #x << " " << x << endl;
#define uniq(x) x.resize(unique(all(x)) - x.begin());
 
#define pb push_back
#define ld long double
#define ll long long
 
void pr(vector<int>& a) {
  cerr << "arr" << " ";
  for(auto i: a) {
    cerr << i << " "; 
  } cerr << endl;
}
 
 
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels(n), in(n), depth(n), tin(n), tout(n);
  vector<int> adj[n + 1];
 
  int timer = 0;
  for(int i = 0; i < n - 1; i++) {
    in[u[i]]++, in[v[i]]++;
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }
 
  function<void(int node, int parent)> dfs;
  
  vector<int> compress;

  dfs = [&](int node, int parent) {
    tin[node] = timer++;

    for(auto i: adj[node]) {
      if(i == parent) continue;
      depth[i] = depth[node] + 1;
      dfs(i, node);
    }

    tout[node] = timer++;
  };
 

  dfs(0, -1);
 
  for(int i = 0; i < n; i++) {
    if(depth[i] % 2 == 0) {
      compress.push_back(tin[i]);
      labels[i] = tin[i];
    } else {
      compress.push_back(tout[i]);
      labels[i] = tout[i];
    }
  }

  sort(all(compress));

	for (int i = 0; i < n; i++) {
    labels[i] = lower_bound(all(compress), labels[i]) - compress.begin();
    tin[i] = tout[i] = 0;
    adj[i].clear();
	}
 
	return labels;
}
 
int find_next_station(int s, int t, std::vector<int> c) {

  if(sz(c) == 1) {
    return c[0];
  }

  int s_ti, s_tu;

  // pr(c);

  int size = sz(c);
  sort(all(c));

  bool t_in = false, t_out = false;

  if(s < c[0]) {
    s_ti = s;
    s_tu = c[size - 2];

    t_in = true;
  } else {
    s_tu = s;
    s_ti = c[1];

    t_out = true;
  }

  if(t >= s_ti && t <= s_tu) {
    // s's subtree
    if(t_in) {
      for(int i = 0; i < size; i++) {
        if(c[i] >= t) {
          return c[i];
        }
      }

      assert(false);
    } else {
      sort(rall(c));

      for(int i = 0; i < size; i++) {
        if(c[i] <= t) {
          return c[i];
        }
      }

      assert(false);
    }
  } else {
    if(t_in) {
      sort(all(c));
      return c.back();
    } else {
      sort(all(c));
      return c[0];
    }
  }

	return c[0];
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:87:22: warning: variable 't_out' set but not used [-Wunused-but-set-variable]
   87 |   bool t_in = false, t_out = false;
      |                      ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 494 ms 672 KB Output is correct
2 Correct 450 ms 636 KB Output is correct
3 Correct 870 ms 488 KB Output is correct
4 Correct 633 ms 504 KB Output is correct
5 Correct 599 ms 508 KB Output is correct
6 Correct 456 ms 580 KB Output is correct
7 Correct 380 ms 636 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 747 ms 544 KB Output is correct
2 Correct 517 ms 500 KB Output is correct
3 Correct 845 ms 420 KB Output is correct
4 Correct 777 ms 416 KB Output is correct
5 Correct 587 ms 416 KB Output is correct
6 Correct 448 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 552 ms 720 KB Output is correct
2 Correct 468 ms 672 KB Output is correct
3 Correct 794 ms 416 KB Output is correct
4 Correct 490 ms 636 KB Output is correct
5 Correct 561 ms 508 KB Output is correct
6 Correct 445 ms 672 KB Output is correct
7 Correct 442 ms 636 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
11 Correct 501 ms 416 KB Output is correct
12 Correct 431 ms 720 KB Output is correct
13 Correct 500 ms 704 KB Output is correct
14 Correct 417 ms 500 KB Output is correct
15 Correct 47 ms 472 KB Output is correct
16 Correct 60 ms 544 KB Output is correct
17 Correct 111 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 861 ms 504 KB Output is correct
2 Correct 639 ms 420 KB Output is correct
3 Correct 544 ms 512 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 619 ms 500 KB Output is correct
8 Correct 891 ms 484 KB Output is correct
9 Correct 608 ms 420 KB Output is correct
10 Correct 462 ms 500 KB Output is correct
11 Correct 4 ms 492 KB Output is correct
12 Correct 4 ms 496 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 1 ms 548 KB Output is correct
16 Correct 491 ms 416 KB Output is correct
17 Correct 420 ms 420 KB Output is correct
18 Correct 492 ms 508 KB Output is correct
19 Correct 522 ms 420 KB Output is correct
20 Correct 439 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 549 ms 672 KB Output is correct
2 Correct 402 ms 700 KB Output is correct
3 Correct 798 ms 512 KB Output is correct
4 Correct 637 ms 504 KB Output is correct
5 Correct 482 ms 508 KB Output is correct
6 Correct 444 ms 672 KB Output is correct
7 Correct 381 ms 548 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 5 ms 592 KB Output is correct
10 Correct 0 ms 504 KB Output is correct
11 Correct 372 ms 484 KB Output is correct
12 Correct 593 ms 572 KB Output is correct
13 Correct 800 ms 504 KB Output is correct
14 Correct 561 ms 484 KB Output is correct
15 Correct 590 ms 420 KB Output is correct
16 Correct 459 ms 508 KB Output is correct
17 Correct 631 ms 416 KB Output is correct
18 Correct 451 ms 708 KB Output is correct
19 Correct 498 ms 784 KB Output is correct
20 Correct 427 ms 624 KB Output is correct
21 Correct 47 ms 468 KB Output is correct
22 Correct 63 ms 572 KB Output is correct
23 Correct 91 ms 568 KB Output is correct
24 Correct 4 ms 496 KB Output is correct
25 Correct 3 ms 500 KB Output is correct
26 Correct 4 ms 492 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 2 ms 472 KB Output is correct
29 Correct 437 ms 600 KB Output is correct
30 Correct 531 ms 504 KB Output is correct
31 Correct 566 ms 504 KB Output is correct
32 Correct 473 ms 560 KB Output is correct
33 Correct 507 ms 416 KB Output is correct
34 Correct 301 ms 652 KB Output is correct
35 Correct 487 ms 752 KB Output is correct
36 Correct 489 ms 756 KB Output is correct
37 Correct 388 ms 624 KB Output is correct
38 Correct 408 ms 576 KB Output is correct
39 Correct 422 ms 844 KB Output is correct
40 Correct 493 ms 724 KB Output is correct
41 Correct 435 ms 580 KB Output is correct
42 Correct 62 ms 676 KB Output is correct
43 Correct 98 ms 536 KB Output is correct
44 Correct 151 ms 544 KB Output is correct
45 Correct 168 ms 548 KB Output is correct
46 Correct 302 ms 508 KB Output is correct
47 Correct 239 ms 636 KB Output is correct
48 Correct 64 ms 680 KB Output is correct
49 Correct 67 ms 740 KB Output is correct