#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 10100;
static int tot;
static vector<int> g[N];
static vector<int> comp[N];
static int where[N];
static int a[N];
static bool visit[N];
static int reva[60];
static void dfs(int u) {
where[u] = tot;
comp[tot].emplace_back(u);
for (int v : g[u]) {
if (comp[tot].size() == 60) {
return;
} else if (!where[v]) {
dfs(v);
}
}
}
static void extra_dfs(int u, int where, int &need) {
visit[u] = true;
for (int v : g[u]) if (!visit[v]) {
if (need == 0) return;
if (::where[v] != where) {
reva[a[v]] = v;
--need;
}
extra_dfs(v, where, need);
}
}
void Joi(int n, int m, int from[], int to[], ll x, int task) {
for (int i = 0; i < m; ++i) {
g[from[i]].emplace_back(to[i]);
g[to[i]].emplace_back(from[i]);
}
for (int i = 0; i < n; ++i) if (!where[i]) {
++tot; dfs(i);
}
for (int i = 1; i <= tot; ++i) {
if (comp[i].size() == 60) {
int ptr = 0;
for (int u : comp[i]) {
a[u] = ptr++;
}
for (int u : comp[i]) {
vector<int> ng;
for (int v : g[u]) {
if (where[v] == where[u]) {
ng.emplace_back(v);
}
}
g[u].swap(ng);
}
}
}
for (int i = 1; i <= tot; ++i) if (comp[i].size() < 60) {
memset(reva, -1, sizeof reva);
int need = 60 - comp[i].size();
extra_dfs(comp[i].back(), i, need);
int ptr = 0;
vector<int> ncomp;
for (int j = 0; j < 60; ++j) {
if (~reva[j]) {
ncomp.emplace_back(reva[j]);
} else {
a[comp[i][ptr]] = j;
ncomp.push_back(comp[i][ptr++]);
}
}
comp[i].swap(ncomp);
for (int u : comp[i]) {
visit[u] = false;
}
}
for (int i = 0; i < n; ++i) {
MessageBoard(i, (x >> a[i]) & 1);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 10100;
static int tot;
static vector<int> g[N];
static vector<int> comp[N];
static int where[N];
static int a[N];
static bool visit[N];
static int reva[60];
static int can[N];
static void dfs(int u) {
where[u] = tot;
comp[tot].emplace_back(u);
for (int v : g[u]) {
if (comp[tot].size() == 60) {
return;
} else if (!where[v]) {
dfs(v);
}
}
}
static void extra_dfs(int u, int where, int &need) {
visit[u] = true;
for (int v : g[u]) if (!visit[v]) {
if (need == 0) return;
if (::where[v] != where) {
reva[a[v]] = v;
--need;
}
extra_dfs(v, where, need);
}
}
ll ans = 0;
void solve(int u) {
visit[u] = true;
for (int v : g[u]) {
if (can[v] && !visit[v]) {
int t = Move(v);
ans |= (((ll) t << a[v]));
solve(v);
Move(u);
}
}
}
ll Ioi(int n, int m, int from[], int to[], int pos, int val, int task) {
for (int i = 0; i < m; ++i) {
g[from[i]].emplace_back(to[i]);
g[to[i]].emplace_back(from[i]);
}
for (int i = 0; i < n; ++i) if (!where[i]) {
++tot; dfs(i);
}
for (int i = 1; i <= tot; ++i) {
if (comp[i].size() == 60) {
int ptr = 0;
for (int u : comp[i]) {
a[u] = ptr++;
}
for (int u : comp[i]) {
vector<int> ng;
for (int v : g[u]) {
if (where[v] == where[u]) {
ng.emplace_back(v);
}
}
g[u].swap(ng);
}
}
}
for (int i = 1; i <= tot; ++i) if (comp[i].size() < 60) {
memset(reva, -1, sizeof reva);
int need = 60 - comp[i].size();
extra_dfs(comp[i].back(), i, need);
int ptr = 0;
vector<int> ncomp;
for (int j = 0; j < 60; ++j) {
if (~reva[j]) {
ncomp.emplace_back(reva[j]);
} else {
a[comp[i][ptr]] = j;
ncomp.push_back(comp[i][ptr++]);
}
}
comp[i].swap(ncomp);
for (int u : comp[i]) {
visit[u] = false;
}
}
for (int v : comp[where[pos]]) {
can[v] = true;
}
ans = (ll) val * (1ll << a[pos]);
solve(pos);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1800 KB |
Output is correct |
2 |
Correct |
4 ms |
1900 KB |
Output is correct |
3 |
Correct |
5 ms |
1928 KB |
Output is correct |
4 |
Correct |
4 ms |
1668 KB |
Output is correct |
5 |
Correct |
5 ms |
2044 KB |
Output is correct |
6 |
Correct |
4 ms |
1804 KB |
Output is correct |
7 |
Correct |
5 ms |
1928 KB |
Output is correct |
8 |
Correct |
6 ms |
1976 KB |
Output is correct |
9 |
Correct |
5 ms |
1936 KB |
Output is correct |
10 |
Correct |
6 ms |
1908 KB |
Output is correct |
11 |
Correct |
8 ms |
2148 KB |
Output is correct |
12 |
Correct |
5 ms |
1912 KB |
Output is correct |
13 |
Correct |
4 ms |
1936 KB |
Output is correct |
14 |
Correct |
4 ms |
1800 KB |
Output is correct |
15 |
Correct |
4 ms |
1936 KB |
Output is correct |
16 |
Correct |
5 ms |
1800 KB |
Output is correct |
17 |
Correct |
4 ms |
1800 KB |
Output is correct |
18 |
Correct |
5 ms |
1800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
5124 KB |
Output is correct |
2 |
Correct |
37 ms |
5140 KB |
Output is correct |
3 |
Correct |
39 ms |
5208 KB |
Output is correct |
4 |
Correct |
24 ms |
4016 KB |
Output is correct |
5 |
Correct |
23 ms |
4012 KB |
Output is correct |
6 |
Correct |
27 ms |
4280 KB |
Output is correct |
7 |
Correct |
27 ms |
4144 KB |
Output is correct |
8 |
Correct |
27 ms |
4216 KB |
Output is correct |
9 |
Correct |
27 ms |
4128 KB |
Output is correct |
10 |
Correct |
42 ms |
8376 KB |
Output is correct |
11 |
Correct |
43 ms |
8372 KB |
Output is correct |
12 |
Correct |
19 ms |
3676 KB |
Output is correct |
13 |
Correct |
19 ms |
3616 KB |
Output is correct |
14 |
Correct |
19 ms |
3876 KB |
Output is correct |
15 |
Correct |
22 ms |
4260 KB |
Output is correct |
16 |
Correct |
23 ms |
4232 KB |
Output is correct |
17 |
Correct |
23 ms |
4040 KB |
Output is correct |
18 |
Correct |
23 ms |
4040 KB |
Output is correct |
19 |
Correct |
23 ms |
4160 KB |
Output is correct |
20 |
Correct |
16 ms |
3640 KB |
Output is correct |
21 |
Correct |
15 ms |
3632 KB |
Output is correct |
22 |
Correct |
30 ms |
4524 KB |
Output is correct |
23 |
Correct |
31 ms |
4536 KB |
Output is correct |
24 |
Correct |
34 ms |
4656 KB |
Output is correct |
25 |
Correct |
31 ms |
4528 KB |
Output is correct |
26 |
Correct |
31 ms |
4780 KB |
Output is correct |
27 |
Correct |
32 ms |
4664 KB |
Output is correct |
28 |
Correct |
30 ms |
4656 KB |
Output is correct |
29 |
Correct |
28 ms |
4376 KB |
Output is correct |
30 |
Correct |
30 ms |
4524 KB |
Output is correct |
31 |
Correct |
5 ms |
1668 KB |
Output is correct |
32 |
Correct |
4 ms |
1804 KB |
Output is correct |
33 |
Correct |
6 ms |
2000 KB |
Output is correct |
34 |
Correct |
5 ms |
1668 KB |
Output is correct |
35 |
Correct |
5 ms |
1908 KB |
Output is correct |
36 |
Correct |
5 ms |
1920 KB |
Output is correct |
37 |
Correct |
4 ms |
1796 KB |
Output is correct |
38 |
Correct |
4 ms |
1668 KB |
Output is correct |
39 |
Correct |
5 ms |
1680 KB |
Output is correct |
40 |
Correct |
4 ms |
1668 KB |
Output is correct |
41 |
Correct |
6 ms |
1804 KB |
Output is correct |
42 |
Correct |
4 ms |
1680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1656 KB |
Output is correct |
2 |
Correct |
4 ms |
1668 KB |
Output is correct |
3 |
Correct |
4 ms |
1668 KB |
Output is correct |
4 |
Correct |
6 ms |
2048 KB |
Output is correct |
5 |
Correct |
6 ms |
2228 KB |
Output is correct |
6 |
Correct |
6 ms |
2048 KB |
Output is correct |
7 |
Correct |
7 ms |
2224 KB |
Output is correct |
8 |
Correct |
7 ms |
2144 KB |
Output is correct |
9 |
Correct |
17 ms |
3504 KB |
Output is correct |
10 |
Correct |
16 ms |
3376 KB |
Output is correct |
11 |
Correct |
16 ms |
3512 KB |
Output is correct |
12 |
Correct |
4 ms |
1668 KB |
Output is correct |
13 |
Correct |
4 ms |
1804 KB |
Output is correct |
14 |
Correct |
4 ms |
1668 KB |
Output is correct |
15 |
Correct |
4 ms |
1668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
5244 KB |
Output is correct |
2 |
Correct |
37 ms |
5200 KB |
Output is correct |
3 |
Correct |
37 ms |
5216 KB |
Output is correct |
4 |
Correct |
23 ms |
4152 KB |
Output is correct |
5 |
Correct |
22 ms |
3884 KB |
Output is correct |
6 |
Correct |
26 ms |
4188 KB |
Output is correct |
7 |
Correct |
25 ms |
4408 KB |
Output is correct |
8 |
Correct |
27 ms |
4144 KB |
Output is correct |
9 |
Correct |
25 ms |
4152 KB |
Output is correct |
10 |
Correct |
38 ms |
8452 KB |
Output is correct |
11 |
Correct |
39 ms |
8356 KB |
Output is correct |
12 |
Correct |
20 ms |
3692 KB |
Output is correct |
13 |
Correct |
20 ms |
3736 KB |
Output is correct |
14 |
Correct |
19 ms |
3620 KB |
Output is correct |
15 |
Correct |
24 ms |
4048 KB |
Output is correct |
16 |
Correct |
23 ms |
4272 KB |
Output is correct |
17 |
Correct |
24 ms |
4144 KB |
Output is correct |
18 |
Correct |
39 ms |
4020 KB |
Output is correct |
19 |
Correct |
23 ms |
4016 KB |
Output is correct |
20 |
Correct |
16 ms |
3632 KB |
Output is correct |
21 |
Correct |
15 ms |
3504 KB |
Output is correct |
22 |
Correct |
30 ms |
4788 KB |
Output is correct |
23 |
Correct |
32 ms |
4620 KB |
Output is correct |
24 |
Correct |
33 ms |
4776 KB |
Output is correct |
25 |
Correct |
35 ms |
4656 KB |
Output is correct |
26 |
Correct |
33 ms |
4656 KB |
Output is correct |
27 |
Correct |
33 ms |
4536 KB |
Output is correct |
28 |
Correct |
32 ms |
4520 KB |
Output is correct |
29 |
Correct |
31 ms |
4512 KB |
Output is correct |
30 |
Correct |
36 ms |
4396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
5144 KB |
Output is correct |
2 |
Correct |
40 ms |
5340 KB |
Output is correct |
3 |
Correct |
38 ms |
5324 KB |
Output is correct |
4 |
Correct |
24 ms |
4124 KB |
Output is correct |
5 |
Correct |
22 ms |
4008 KB |
Output is correct |
6 |
Correct |
27 ms |
4216 KB |
Output is correct |
7 |
Correct |
25 ms |
4144 KB |
Output is correct |
8 |
Correct |
26 ms |
4204 KB |
Output is correct |
9 |
Correct |
27 ms |
4272 KB |
Output is correct |
10 |
Correct |
41 ms |
8372 KB |
Output is correct |
11 |
Correct |
44 ms |
8368 KB |
Output is correct |
12 |
Correct |
19 ms |
3716 KB |
Output is correct |
13 |
Correct |
20 ms |
3744 KB |
Output is correct |
14 |
Correct |
20 ms |
3776 KB |
Output is correct |
15 |
Correct |
20 ms |
4272 KB |
Output is correct |
16 |
Correct |
20 ms |
4152 KB |
Output is correct |
17 |
Correct |
24 ms |
4280 KB |
Output is correct |
18 |
Correct |
23 ms |
4152 KB |
Output is correct |
19 |
Correct |
25 ms |
4256 KB |
Output is correct |
20 |
Correct |
17 ms |
3724 KB |
Output is correct |
21 |
Correct |
16 ms |
3768 KB |
Output is correct |
22 |
Correct |
31 ms |
4784 KB |
Output is correct |
23 |
Correct |
31 ms |
4656 KB |
Output is correct |
24 |
Correct |
28 ms |
4528 KB |
Output is correct |
25 |
Correct |
31 ms |
4676 KB |
Output is correct |
26 |
Correct |
32 ms |
4664 KB |
Output is correct |
27 |
Correct |
33 ms |
4564 KB |
Output is correct |
28 |
Correct |
35 ms |
4784 KB |
Output is correct |
29 |
Correct |
30 ms |
4360 KB |
Output is correct |
30 |
Correct |
31 ms |
4524 KB |
Output is correct |
31 |
Correct |
5 ms |
1796 KB |
Output is correct |
32 |
Correct |
5 ms |
1668 KB |
Output is correct |
33 |
Correct |
6 ms |
1972 KB |
Output is correct |
34 |
Correct |
5 ms |
1932 KB |
Output is correct |
35 |
Correct |
4 ms |
1920 KB |
Output is correct |
36 |
Correct |
4 ms |
1960 KB |
Output is correct |
37 |
Correct |
5 ms |
1804 KB |
Output is correct |
38 |
Correct |
4 ms |
1932 KB |
Output is correct |
39 |
Correct |
4 ms |
1692 KB |
Output is correct |
40 |
Correct |
4 ms |
1804 KB |
Output is correct |
41 |
Correct |
4 ms |
1668 KB |
Output is correct |
42 |
Correct |
4 ms |
1916 KB |
Output is correct |