답안 #500090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500090 2021-12-30T10:09:15 Z 600Mihnea Amusement Park (JOI17_amusement_park) C++17
100 / 100
28 ms 5672 KB
#include "Joi.h"
#include <bits/stdc++.h>

using namespace std;

const int BITS = 60;

mt19937 reng(3333);

void Joi(int N, int M, int A[], int B[], long long X, int T) {
  int root = reng() % N;
  vector<vector<int>> g(N);
  vector<int> color(N, -1);

  for (int i = 0; i < M; i++) {
    g[A[i]].push_back(B[i]);
    g[B[i]].push_back(A[i]);
  }
  for (int i = 0; i < N; i++) shuffle(g[i].begin(), g[i].end(), reng);


  vector<bool> vis(N, 0);
  vector<vector<int>> ng(N);

  function<void(int)> makeG = [&] (int a) {
    vis[a] = 1;
    for (auto &b : g[a]) {
      if (!vis[b]) {
        ng[a].push_back(b);
        makeG(b);
      }
    }
  };
  makeG(root);
  g = ng;
  for (int i = 0; i < N; i++) shuffle(g[i].begin(), g[i].end(), reng);



  function<void(int)> draw = [&] (int a) {
    vector<int> all;
    queue<int> q;
    q.push(a);
    all.push_back(a);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (auto &y : g[x]) {
        if ((int) all.size() + 1 > BITS) break;
        q.push(y);
        all.push_back(y);
      }
    }
    assert((int) all.size() <= BITS);
    for (int i = 0; i < (int) all.size(); i++) {
      color[all[i]] = i;
    }
    for (int i = 0; i < (int) all.size(); i++) {
      for (auto &v : g[all[i]]) {
        if (color[v] == -1) {
          draw(v);
        }
      }
    }
  };
  draw(root);
  for (auto &x : color) assert(0 <= x && x < BITS);


  vector<int> numBits(BITS);
  for (int i = 0; i < BITS; i++) {
    if (X & (1LL << i)) {
      numBits[i] = 1;
    } else {
      numBits[i] = 0;
    }
  }



  for(int i = 0; i < N; i++) {
    MessageBoard(i, numBits[color[i]]);
  }
}


#include "Ioi.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int BITS = 60;

mt19937 rng(3333);

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
  int root = rng() % N;
  vector<vector<int>> g(N);
  vector<int> color(N, -1);
  vector<int> parrent(N, -1);

  for (int i = 0; i < M; i++) {
    g[A[i]].push_back(B[i]);
    g[B[i]].push_back(A[i]);
  }
  for (int i = 0; i < N; i++) shuffle(g[i].begin(), g[i].end(), rng);

  vector<bool> vis(N, 0);
  vector<int> sub(N);
  vector<vector<int>> ng(N);

  function<void(int)> makeG = [&] (int a) {
    vis[a] = 1;
    sub[a] = 1;
    for (auto &b : g[a]) {
      if (!vis[b]) {
        ng[a].push_back(b);
        makeG(b);
        parrent[b] = a;
        sub[a] += sub[b];
      }
    }
  };
  makeG(root);
  g = ng;

  for (int i = 0; i < N; i++) shuffle(g[i].begin(), g[i].end(), rng);
  map<int, vector<pair<int, int>>> guys;
  vector<int> who(N);

  function<void(int)> draw = [&] (int a) {
    vector<pair<int, int>> all;
    queue<int> q;
    q.push(a);
    vector<int> vrts = {a};
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (auto &y : g[x]) {
        if ((int) vrts.size() + 1 > BITS) break;
        q.push(y);
        vrts.push_back(y);
        all.push_back({x, y});
      }
    }
    guys[a] = all;
    assert((int) all.size() <= BITS);
    for (int i = 0; i < (int) vrts.size(); i++) {
      color[vrts[i]] = i;
      who[vrts[i]] = a;
    }
    for (int i = 0; i < (int) vrts.size(); i++) {
      for (auto &v : g[vrts[i]]) {
        if (color[v] == -1) {

          draw(v);
        }
      }
    }
  };
  draw(root);
  ll solu = 0;
  int done = 0;

  set<pair<int, int>> s;

  while (sub[P] < BITS) {
    s.insert({P, parrent[P]});
    s.insert({parrent[P], P});
    V = Move(parrent[P]);
    P = parrent[P];
  }
  vector<pair<int, int>> all = guys[who[P]];

  function<bool(pair<int, int>, pair<int, int>)> cmp = [&] (pair<int, int> a, pair<int, int> b) {
    return s.count(a) < s.count(b);
  };

  sort(all.begin(), all.end(), cmp);

  for (int i = 0; i < N; i++) g[i].clear();

  for (auto &it : all) g[it.first].push_back(it.second), g[it.second].push_back(it.first);

  vector<int> dep(N);

  function<void(int, int)> cdep = [&] (int a, int p) {
    dep[a] = 0;
    for (auto &b : g[a]) {
      if (b != p) {
        cdep(b, a);
        dep[a] = max(dep[a], 1 + dep[b]);
      }
    }
  };

  function<void(int, int)> expl = [&] (int a, int p) {
    solu |= (1LL << color[a]) * V;
    done++;
    int v = -1;
    for (auto &b : g[a]) {
      if (b == p) continue;
      if (v == -1) v = b;
      else if (dep[b] > dep[v]) v = b;
    }
    for (auto &b : g[a]) {
      if (b == p || b == v) continue;
      if (done == BITS) break;
      V = Move(b);
      if (done == BITS) break;
      expl(b, a);
      if (done == BITS) break;
      V = Move(a);
      if (done == BITS) break;
    }
    for (auto &b : g[a]) {
      if (b == p || b != v) continue;
      if (done == BITS) break;
      V = Move(b);
      if (done == BITS) break;
      expl(b, a);
      if (done == BITS) break;
      V = Move(a);
      if (done == BITS) break;
    }
  };

  cdep(P, -1);
  expl(P, -1);

  assert(done == BITS);
  for (auto &x : color) assert(0 <= x && x < BITS);



  vector<int> numBits(BITS, -1);
  int needBits = BITS;


  return solu;
}

Compilation message

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:154:7: warning: unused variable 'needBits' [-Wunused-variable]
  154 |   int needBits = BITS;
      |       ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 488 KB Output is correct
2 Correct 1 ms 744 KB Output is correct
3 Correct 2 ms 756 KB Output is correct
4 Correct 1 ms 616 KB Output is correct
5 Correct 0 ms 752 KB Output is correct
6 Correct 0 ms 752 KB Output is correct
7 Correct 0 ms 748 KB Output is correct
8 Correct 2 ms 756 KB Output is correct
9 Correct 1 ms 756 KB Output is correct
10 Correct 1 ms 752 KB Output is correct
11 Correct 4 ms 932 KB Output is correct
12 Correct 0 ms 624 KB Output is correct
13 Correct 0 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 1 ms 756 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 5428 KB Output is correct
2 Correct 26 ms 5496 KB Output is correct
3 Correct 27 ms 5484 KB Output is correct
4 Correct 16 ms 3780 KB Output is correct
5 Correct 17 ms 5492 KB Output is correct
6 Correct 16 ms 4216 KB Output is correct
7 Correct 16 ms 4404 KB Output is correct
8 Correct 16 ms 4280 KB Output is correct
9 Correct 18 ms 4416 KB Output is correct
10 Correct 16 ms 4040 KB Output is correct
11 Correct 17 ms 4040 KB Output is correct
12 Correct 14 ms 3252 KB Output is correct
13 Correct 14 ms 3308 KB Output is correct
14 Correct 16 ms 3420 KB Output is correct
15 Correct 15 ms 3764 KB Output is correct
16 Correct 16 ms 3776 KB Output is correct
17 Correct 17 ms 3640 KB Output is correct
18 Correct 16 ms 3616 KB Output is correct
19 Correct 17 ms 3644 KB Output is correct
20 Correct 13 ms 4280 KB Output is correct
21 Correct 14 ms 4536 KB Output is correct
22 Correct 17 ms 4420 KB Output is correct
23 Correct 16 ms 4152 KB Output is correct
24 Correct 16 ms 4376 KB Output is correct
25 Correct 17 ms 4296 KB Output is correct
26 Correct 17 ms 4168 KB Output is correct
27 Correct 16 ms 4552 KB Output is correct
28 Correct 16 ms 4452 KB Output is correct
29 Correct 14 ms 3764 KB Output is correct
30 Correct 15 ms 4028 KB Output is correct
31 Correct 0 ms 744 KB Output is correct
32 Correct 2 ms 752 KB Output is correct
33 Correct 1 ms 756 KB Output is correct
34 Correct 1 ms 744 KB Output is correct
35 Correct 0 ms 624 KB Output is correct
36 Correct 0 ms 616 KB Output is correct
37 Correct 2 ms 496 KB Output is correct
38 Correct 2 ms 496 KB Output is correct
39 Correct 0 ms 496 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 1 ms 624 KB Output is correct
42 Correct 2 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 624 KB Output is correct
2 Correct 1 ms 616 KB Output is correct
3 Correct 0 ms 620 KB Output is correct
4 Correct 3 ms 1296 KB Output is correct
5 Correct 3 ms 1288 KB Output is correct
6 Correct 2 ms 1296 KB Output is correct
7 Correct 4 ms 1296 KB Output is correct
8 Correct 4 ms 1296 KB Output is correct
9 Correct 14 ms 5048 KB Output is correct
10 Correct 15 ms 4868 KB Output is correct
11 Correct 13 ms 5304 KB Output is correct
12 Correct 0 ms 744 KB Output is correct
13 Correct 0 ms 616 KB Output is correct
14 Correct 2 ms 488 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 5332 KB Output is correct
2 Correct 26 ms 5412 KB Output is correct
3 Correct 27 ms 5424 KB Output is correct
4 Correct 16 ms 3636 KB Output is correct
5 Correct 17 ms 5064 KB Output is correct
6 Correct 17 ms 4288 KB Output is correct
7 Correct 18 ms 4448 KB Output is correct
8 Correct 17 ms 4168 KB Output is correct
9 Correct 17 ms 4420 KB Output is correct
10 Correct 17 ms 4060 KB Output is correct
11 Correct 18 ms 4100 KB Output is correct
12 Correct 16 ms 3372 KB Output is correct
13 Correct 19 ms 3260 KB Output is correct
14 Correct 16 ms 3312 KB Output is correct
15 Correct 18 ms 3740 KB Output is correct
16 Correct 17 ms 3816 KB Output is correct
17 Correct 20 ms 3564 KB Output is correct
18 Correct 22 ms 3576 KB Output is correct
19 Correct 16 ms 3652 KB Output is correct
20 Correct 13 ms 4292 KB Output is correct
21 Correct 13 ms 4552 KB Output is correct
22 Correct 17 ms 4076 KB Output is correct
23 Correct 17 ms 4248 KB Output is correct
24 Correct 18 ms 4536 KB Output is correct
25 Correct 19 ms 4596 KB Output is correct
26 Correct 17 ms 4556 KB Output is correct
27 Correct 15 ms 4464 KB Output is correct
28 Correct 16 ms 4232 KB Output is correct
29 Correct 18 ms 4404 KB Output is correct
30 Correct 18 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 5580 KB Output is correct
2 Correct 27 ms 5580 KB Output is correct
3 Correct 28 ms 5672 KB Output is correct
4 Correct 19 ms 3756 KB Output is correct
5 Correct 17 ms 4844 KB Output is correct
6 Correct 22 ms 4440 KB Output is correct
7 Correct 23 ms 4688 KB Output is correct
8 Correct 18 ms 4628 KB Output is correct
9 Correct 16 ms 4488 KB Output is correct
10 Correct 16 ms 4120 KB Output is correct
11 Correct 19 ms 4132 KB Output is correct
12 Correct 18 ms 3460 KB Output is correct
13 Correct 17 ms 3352 KB Output is correct
14 Correct 18 ms 3608 KB Output is correct
15 Correct 17 ms 3880 KB Output is correct
16 Correct 19 ms 3916 KB Output is correct
17 Correct 16 ms 3848 KB Output is correct
18 Correct 22 ms 3800 KB Output is correct
19 Correct 27 ms 3836 KB Output is correct
20 Correct 17 ms 4496 KB Output is correct
21 Correct 14 ms 4648 KB Output is correct
22 Correct 24 ms 4732 KB Output is correct
23 Correct 25 ms 4736 KB Output is correct
24 Correct 19 ms 4772 KB Output is correct
25 Correct 26 ms 4124 KB Output is correct
26 Correct 19 ms 4380 KB Output is correct
27 Correct 25 ms 4492 KB Output is correct
28 Correct 25 ms 4356 KB Output is correct
29 Correct 17 ms 4040 KB Output is correct
30 Correct 20 ms 4332 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 760 KB Output is correct
33 Correct 2 ms 796 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 756 KB Output is correct
36 Correct 1 ms 748 KB Output is correct
37 Correct 2 ms 748 KB Output is correct
38 Correct 2 ms 644 KB Output is correct
39 Correct 1 ms 584 KB Output is correct
40 Correct 1 ms 716 KB Output is correct
41 Correct 1 ms 756 KB Output is correct
42 Correct 1 ms 720 KB Output is correct