답안 #366686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366686 2021-02-15T00:46:27 Z Mamnoon_Siam Amusement Park (JOI17_amusement_park) C++17
0 / 100
56 ms 20928 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

/* sorry, this is the bare minimum :'( */
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second

const int N = 1e5 + 5;

namespace {
  vi t[N], g[N];
  int vis[N];
  int idx[N], done[N];
  vi sub[N];
  int cnt = 0;
  void dfs0(int u) {
    vis[u] = 1;
    for(int v : g[u]) if(!vis[v]) {
      t[u].emplace_back(v);
      t[v].emplace_back(u);
      dfs0(v);
    }
  }
  void trace_subtree(int u, vi& subtree) {
    vis[u] = 1;
    cnt++;
    subtree.emplace_back(u);
    for(int v : t[u]) if(!vis[v] and cnt < 60) {
      trace_subtree(v, subtree);
    }
  }
}

void Joi(int n, int m, int A[], int B[], long long X, int T) {
  for(int i = 0; i < m; ++i) {
    g[A[i]].emplace_back(B[i]);
    g[B[i]].emplace_back(A[i]);
  }
  memset(idx, -1, sizeof idx);
  dfs0(0);
  memset(vis, 0, sizeof vis);
  // for(int x : t[0]) cout << x << ' '; cout << endl;
  for(int i = 0; i < n; ++i) if(!~idx[i]) {
    // cout << "i = " << i << endl;
    vi subtree;
    trace_subtree(i, subtree);
    for(int u : subtree)
      vis[u] = 0;
    for(int u : subtree) {
      if(~idx[u]) vis[idx[u]] = 1;
    }
    vi unused;
    for(int i = 0; i < 60; ++i) {
      if(!vis[i]) unused.emplace_back(i);
    }
    // for(int x : unused) cout << x << ' '; cout << endl;
    for(int u : subtree) {
      if(~idx[u]) vis[idx[u]] = 0;
    }
    for(int u : subtree) {
      if(!~idx[u]) {
        idx[u] = unused.back();
        unused.pop_back();
        sub[u] = subtree;
      }
    }
  }
  for(int i = 0; i < n; ++i) {
    // cout << i << ' ' << idx[i] << endl;
    MessageBoard(i, X >> idx[i] & 1);
  }
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

/* sorry, this is the bare minimum :'( */
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second

const int N = 1e5 + 5;

namespace {
  vi t[N], g[N];
  int vis[N];
  int idx[N], done[N];
  vi sub[N];
  int cnt = 0;
  void dfs0(int u) {
    vis[u] = 1;
    for(int v : g[u]) if(!vis[v]) {
      t[u].emplace_back(v);
      t[v].emplace_back(u);
      dfs0(v);
    }
  }
  void trace_subtree(int u, vi& subtree) {
    vis[u] = 1;
    cnt++;
    subtree.emplace_back(u);
    for(int v : t[u]) if(!vis[v] and cnt < 60) {
      trace_subtree(v, subtree);
    }
  }
  void euler_tour(int u, vi& tour, vi& subtree) {
    tour.emplace_back(u);
    vis[u] = 1;
    for(int v : t[u]) if(!vis[v] and count(all(subtree), v)) {
      euler_tour(v, tour, subtree);
      tour.emplace_back(u);
    }
  }
}

long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {
  for(int i = 0; i < m; ++i) {
    g[A[i]].emplace_back(B[i]);
    g[B[i]].emplace_back(A[i]);
  }
  memset(idx, -1, sizeof idx);
  dfs0(0);
  memset(vis, 0, sizeof vis);
  // for(int x : t[0]) cout << x << ' '; cout << endl;
  for(int i = 0; i < n; ++i) if(!~idx[i]) {
    // cout << "i = " << i << endl;
    vi subtree;
    trace_subtree(i, subtree);
    for(int u : subtree)
      vis[u] = 0;
    for(int u : subtree) {
      if(~idx[u]) vis[idx[u]] = 1;
    }
    vi unused;
    for(int i = 0; i < 60; ++i) {
      if(!vis[i]) unused.emplace_back(i);
    }
    // for(int x : unused) cout << x << ' '; cout << endl;
    for(int u : subtree) {
      if(~idx[u]) vis[idx[u]] = 0;
    }
    for(int u : subtree) {
      if(!~idx[u]) {
        idx[u] = unused.back();
        unused.pop_back();
        sub[u] = subtree;
      }
    }
  }
  vi tour;
  // cout << "tour = "; for(int x : tour) cout << x << ' '; cout << endl;
  euler_tour(P, tour, sub[P]);
  tour.erase(tour.begin());
  ll ret = ll(V) << idx[P];
  for(int u : tour) {
    ret |= ll(Move(u)) << idx[u];
  }
  return ret;
}

Compilation message

Joi.cpp:19:15: warning: '{anonymous}::done' defined but not used [-Wunused-variable]
   19 |   int idx[N], done[N];
      |               ^~~~

Ioi.cpp:19:15: warning: '{anonymous}::done' defined but not used [-Wunused-variable]
   19 |   int idx[N], done[N];
      |               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 16356 KB Output is correct
2 Incorrect 13 ms 16504 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 20928 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 16544 KB Output is correct
2 Correct 12 ms 16360 KB Output is correct
3 Incorrect 12 ms 16488 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 20804 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 20804 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -