답안 #257488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257488 2020-08-04T10:50:01 Z islingr Amusement Park (JOI17_amusement_park) C++17
80 / 100
43 ms 4924 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)

using ll = long long;

namespace {
const int N = 1 << 14, B = 60;
int nxt[N];
int head(int u) { return nxt[u] != u ? nxt[u] = head(nxt[u]) : u; }
bool unite(int u, int v) {
	u = head(u); v = head(v);
	if (u == v) return 0;
	nxt[u] = v; return 1;
}

vector<int> g[N];
int timer = 0, sz[N]; ll x;
void dfs_sz(int u) {
	sz[u] = 1;
	for (int v : g[u]) {
		g[v].erase(find(all(g[v]), u));
		dfs_sz(v);
		sz[u] += sz[v];
	}
	sort(all(g[u]), [&](int u, int v) { return sz[u] > sz[v]; });
}

void dfs(int u) {
	MessageBoard(u, x >> timer & 1);
	if (++timer == B) timer = 0;
	for (int v : g[u]) dfs(v);
}
}

void Joi(int n, int m, int a[], int b[], ll X, int t) {
	rep(u, 0, n) nxt[u] = u;
	rep(e, 0, m) {
		if (unite(a[e], b[e])) {
			g[a[e]].push_back(b[e]);
			g[b[e]].push_back(a[e]);
		}
	}
	x = X; dfs_sz(0); dfs(0);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)

using ll = long long;

namespace {
const int N = 1 << 14, B = 60;
int nxt[N];
int head(int u) { return nxt[u] != u ? nxt[u] = head(nxt[u]) : u; }
bool unite(int u, int v) {
  u = head(u); v = head(v);
  if (u == v) return 0;
  nxt[u] = v; return 1;
}

vector<int> g[N];
int p[N], in[N], sz[N], timer = 0;
void dfs_sz(int u) {
	sz[u] = 1;
	for (int v : g[u]) {
		g[v].erase(find(all(g[v]), u));
		dfs_sz(v);
		sz[u] += sz[v];
	}
	sort(all(g[u]), [&](int u, int v) { return sz[u] > sz[v]; });
}

void init(int u) {
  in[u] = timer++;
  for (int v : g[u]) {
    p[v] = u; init(v);
  }
}

ll cur = 0, x = 0;
bool add(int u, ll z) {
  int s = in[u] % B;
  cur |= 1ll << s;
  x |= z << s;
	return __builtin_popcountll(cur) == B;
}
bool dfs(int u, int z) {
	if (add(u, z)) return true;
  for (int v : g[u]) {
    if (dfs(v, Move(v))) return true;
    Move(u);
  }
  return false;
}
}

ll Ioi(int n, int m, int a[], int b[], int P, int V, int T) {
  rep(u, 0, n) nxt[u] = u;
  rep(e, 0, m) {
    if (unite(a[e], b[e])) {
      g[a[e]].push_back(b[e]);
      g[b[e]].push_back(a[e]);
    }
  }

  dfs_sz(0); init(0);
	while (sz[P] < B) {
    if (add(P, V)) break;
    V = Move(p[P]), P = p[P];
  }
	assert(dfs(P, V));
  return x;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1772 KB Output is correct
2 Correct 2 ms 1544 KB Output is correct
3 Correct 3 ms 1752 KB Output is correct
4 Correct 2 ms 1672 KB Output is correct
5 Correct 2 ms 1784 KB Output is correct
6 Correct 2 ms 1544 KB Output is correct
7 Correct 2 ms 1552 KB Output is correct
8 Correct 2 ms 1552 KB Output is correct
9 Correct 2 ms 1552 KB Output is correct
10 Correct 2 ms 1772 KB Output is correct
11 Correct 5 ms 1876 KB Output is correct
12 Correct 2 ms 1772 KB Output is correct
13 Correct 2 ms 1680 KB Output is correct
14 Correct 2 ms 1764 KB Output is correct
15 Correct 2 ms 1552 KB Output is correct
16 Correct 2 ms 1760 KB Output is correct
17 Correct 2 ms 1748 KB Output is correct
18 Correct 3 ms 1648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3852 KB Output is correct
2 Correct 28 ms 3860 KB Output is correct
3 Correct 41 ms 3812 KB Output is correct
4 Correct 22 ms 3352 KB Output is correct
5 Correct 19 ms 3916 KB Output is correct
6 Correct 19 ms 3900 KB Output is correct
7 Correct 19 ms 3660 KB Output is correct
8 Correct 18 ms 3836 KB Output is correct
9 Correct 20 ms 3952 KB Output is correct
10 Correct 17 ms 3276 KB Output is correct
11 Correct 17 ms 3276 KB Output is correct
12 Correct 17 ms 3164 KB Output is correct
13 Correct 17 ms 3004 KB Output is correct
14 Correct 23 ms 3400 KB Output is correct
15 Correct 20 ms 3172 KB Output is correct
16 Correct 22 ms 3148 KB Output is correct
17 Correct 19 ms 3276 KB Output is correct
18 Correct 27 ms 3148 KB Output is correct
19 Correct 27 ms 3356 KB Output is correct
20 Correct 15 ms 3916 KB Output is correct
21 Correct 19 ms 4148 KB Output is correct
22 Correct 18 ms 3532 KB Output is correct
23 Correct 18 ms 3840 KB Output is correct
24 Correct 17 ms 3660 KB Output is correct
25 Correct 19 ms 3872 KB Output is correct
26 Correct 17 ms 3788 KB Output is correct
27 Correct 18 ms 3864 KB Output is correct
28 Correct 20 ms 3864 KB Output is correct
29 Correct 20 ms 3644 KB Output is correct
30 Correct 19 ms 3740 KB Output is correct
31 Correct 5 ms 1652 KB Output is correct
32 Correct 2 ms 1540 KB Output is correct
33 Correct 2 ms 1548 KB Output is correct
34 Correct 2 ms 1540 KB Output is correct
35 Correct 2 ms 1672 KB Output is correct
36 Correct 2 ms 1672 KB Output is correct
37 Correct 2 ms 1768 KB Output is correct
38 Correct 2 ms 1780 KB Output is correct
39 Correct 2 ms 1544 KB Output is correct
40 Correct 2 ms 1672 KB Output is correct
41 Correct 2 ms 1544 KB Output is correct
42 Correct 2 ms 1544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1540 KB Output is correct
2 Correct 1 ms 1540 KB Output is correct
3 Correct 2 ms 1780 KB Output is correct
4 Correct 4 ms 2084 KB Output is correct
5 Correct 4 ms 2332 KB Output is correct
6 Correct 4 ms 2320 KB Output is correct
7 Correct 4 ms 2324 KB Output is correct
8 Correct 4 ms 2212 KB Output is correct
9 Correct 15 ms 4924 KB Output is correct
10 Correct 14 ms 4812 KB Output is correct
11 Correct 17 ms 4684 KB Output is correct
12 Correct 2 ms 1652 KB Output is correct
13 Correct 2 ms 1912 KB Output is correct
14 Correct 2 ms 1772 KB Output is correct
15 Correct 2 ms 1668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3856 KB Output is correct
2 Correct 28 ms 3848 KB Output is correct
3 Partially correct 28 ms 3812 KB Partially correct
4 Correct 19 ms 3148 KB Output is correct
5 Partially correct 19 ms 4300 KB Partially correct
6 Correct 18 ms 3948 KB Output is correct
7 Correct 17 ms 3788 KB Output is correct
8 Correct 20 ms 3404 KB Output is correct
9 Correct 19 ms 3660 KB Output is correct
10 Correct 16 ms 3276 KB Output is correct
11 Correct 18 ms 3324 KB Output is correct
12 Correct 17 ms 3004 KB Output is correct
13 Correct 17 ms 3004 KB Output is correct
14 Correct 22 ms 3400 KB Output is correct
15 Correct 22 ms 3276 KB Output is correct
16 Correct 20 ms 3364 KB Output is correct
17 Correct 22 ms 3352 KB Output is correct
18 Correct 17 ms 3276 KB Output is correct
19 Correct 22 ms 3356 KB Output is correct
20 Correct 15 ms 4132 KB Output is correct
21 Correct 14 ms 3916 KB Output is correct
22 Correct 22 ms 3844 KB Output is correct
23 Correct 23 ms 3892 KB Output is correct
24 Correct 18 ms 3904 KB Output is correct
25 Correct 19 ms 3956 KB Output is correct
26 Correct 19 ms 3868 KB Output is correct
27 Correct 19 ms 4044 KB Output is correct
28 Correct 17 ms 3664 KB Output is correct
29 Correct 19 ms 3564 KB Output is correct
30 Correct 17 ms 3780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 3860 KB Output is correct
2 Correct 28 ms 3856 KB Output is correct
3 Incorrect 43 ms 3812 KB Output isn't correct
4 Halted 0 ms 0 KB -