답안 #500034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500034 2021-12-30T09:46:37 Z 600Mihnea Amusement Park (JOI17_amusement_park) C++17
81 / 100
34 ms 5596 KB
#include "Joi.h"
#include <bits/stdc++.h>

using namespace std;

const int BITS = 60;


void Joi(int N, int M, int A[], int B[], long long X, int T) {
  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]);
  }


  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(0);
  g = ng;

  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(0);
  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;

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
  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]);
  }

  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(0);
  g = ng;

  map<int, vector<pair<int, int>>> guys;

  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;
    }
    for (int i = 0; i < (int) vrts.size(); i++) {
      for (auto &v : g[vrts[i]]) {
        if (color[v] == -1) {

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

  set<pair<int, int>> s;

  while (sub[P] < BITS || !guys.count(P)) {
    s.insert({P, parrent[P]});
    s.insert({parrent[P], P});
    V = Move(parrent[P]);
    P = parrent[P];
  }
  vector<pair<int, int>> all = guys[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);


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

  expl(P);

  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:118:7: warning: unused variable 'needBits' [-Wunused-variable]
  118 |   int needBits = BITS;
      |       ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 540 KB Output is correct
2 Correct 0 ms 616 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 1 ms 616 KB Output is correct
5 Correct 0 ms 564 KB Output is correct
6 Correct 1 ms 616 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 0 ms 616 KB Output is correct
11 Correct 4 ms 932 KB Output is correct
12 Correct 0 ms 496 KB Output is correct
13 Correct 1 ms 756 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 764 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 5292 KB Output is correct
2 Correct 25 ms 5308 KB Output is correct
3 Correct 23 ms 5324 KB Output is correct
4 Correct 15 ms 3512 KB Output is correct
5 Correct 20 ms 4472 KB Output is correct
6 Correct 16 ms 4152 KB Output is correct
7 Correct 15 ms 4156 KB Output is correct
8 Correct 20 ms 4244 KB Output is correct
9 Correct 20 ms 4304 KB Output is correct
10 Correct 19 ms 3960 KB Output is correct
11 Correct 15 ms 3772 KB Output is correct
12 Correct 14 ms 3232 KB Output is correct
13 Correct 13 ms 3244 KB Output is correct
14 Correct 15 ms 3248 KB Output is correct
15 Correct 19 ms 3520 KB Output is correct
16 Correct 18 ms 3744 KB Output is correct
17 Correct 19 ms 3436 KB Output is correct
18 Correct 19 ms 3572 KB Output is correct
19 Correct 20 ms 3496 KB Output is correct
20 Correct 13 ms 4468 KB Output is correct
21 Correct 14 ms 4432 KB Output is correct
22 Correct 18 ms 3832 KB Output is correct
23 Correct 17 ms 4176 KB Output is correct
24 Correct 24 ms 3952 KB Output is correct
25 Correct 16 ms 4188 KB Output is correct
26 Correct 17 ms 4108 KB Output is correct
27 Correct 16 ms 4264 KB Output is correct
28 Correct 14 ms 4212 KB Output is correct
29 Correct 14 ms 3904 KB Output is correct
30 Correct 16 ms 4016 KB Output is correct
31 Correct 2 ms 624 KB Output is correct
32 Correct 2 ms 488 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 1 ms 616 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 484 KB Output is correct
37 Correct 0 ms 488 KB Output is correct
38 Correct 2 ms 488 KB Output is correct
39 Correct 2 ms 488 KB Output is correct
40 Correct 0 ms 496 KB Output is correct
41 Correct 2 ms 624 KB Output is correct
42 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 624 KB Output is correct
2 Correct 1 ms 624 KB Output is correct
3 Correct 0 ms 616 KB Output is correct
4 Correct 4 ms 1420 KB Output is correct
5 Correct 4 ms 1408 KB Output is correct
6 Correct 4 ms 1428 KB Output is correct
7 Correct 3 ms 1416 KB Output is correct
8 Correct 5 ms 1392 KB Output is correct
9 Correct 12 ms 5564 KB Output is correct
10 Correct 13 ms 5564 KB Output is correct
11 Correct 12 ms 5596 KB Output is correct
12 Correct 1 ms 488 KB Output is correct
13 Correct 2 ms 616 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 1 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 5320 KB Output is correct
2 Correct 24 ms 5320 KB Output is correct
3 Correct 26 ms 5224 KB Output is correct
4 Correct 20 ms 3488 KB Output is correct
5 Partially correct 18 ms 4948 KB Partially correct
6 Correct 22 ms 4400 KB Output is correct
7 Correct 19 ms 4264 KB Output is correct
8 Correct 16 ms 4012 KB Output is correct
9 Correct 20 ms 4012 KB Output is correct
10 Correct 19 ms 3912 KB Output is correct
11 Correct 17 ms 3840 KB Output is correct
12 Correct 15 ms 3212 KB Output is correct
13 Partially correct 16 ms 3188 KB Partially correct
14 Partially correct 19 ms 3284 KB Partially correct
15 Correct 18 ms 3480 KB Output is correct
16 Correct 16 ms 3492 KB Output is correct
17 Correct 20 ms 3368 KB Output is correct
18 Partially correct 16 ms 3496 KB Partially correct
19 Correct 17 ms 3504 KB Output is correct
20 Correct 15 ms 4392 KB Output is correct
21 Correct 15 ms 4376 KB Output is correct
22 Correct 19 ms 4268 KB Output is correct
23 Correct 19 ms 4004 KB Output is correct
24 Correct 15 ms 4076 KB Output is correct
25 Correct 16 ms 4156 KB Output is correct
26 Correct 16 ms 4148 KB Output is correct
27 Correct 15 ms 4440 KB Output is correct
28 Correct 17 ms 3944 KB Output is correct
29 Correct 15 ms 3864 KB Output is correct
30 Correct 19 ms 4092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 5308 KB Output is correct
2 Correct 25 ms 5328 KB Output is correct
3 Correct 25 ms 5580 KB Output is correct
4 Correct 16 ms 3604 KB Output is correct
5 Incorrect 17 ms 5464 KB Output isn't correct
6 Halted 0 ms 0 KB -