#include "Joi.h"
#include <iostream>
#include <vector>
using namespace std;
vector<int>G[10009]; int col[10009], v[20009], cnts;
void make_ransuu1(int B) {
for (int i = 0; i < B; i++) v[i] = i;
unsigned long long x = 1;
for (int i = 0; i < 1000000; i++) {
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
int u1 = (x % B);
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
int u2 = (x % B);
swap(v[u1], v[u2]);
}
}
void dfs(int pos) {
if (col[pos] >= 0) return;
col[pos] = cnts % 60; cnts++;
for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]);
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
make_ransuu1(M);
for (int i = 0; i < M; i++) { G[A[v[i]]].push_back(B[v[i]]); G[B[v[i]]].push_back(A[v[i]]); }
for (int i = 0; i < N; i++) col[i] = -1;
dfs(0);
for (int i = 0; i < N; i++) MessageBoard(i, (X / (1LL << col[i])) % 2);
}
#include "Ioi.h"
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
vector<int>I[10009]; int dist[10009], par[10009], cols[10009], vv[20009], cntv;
int N, M; bool used[60];
void make_ransuu2(int B) {
for (int i = 0; i < B; i++) vv[i] = i;
unsigned long long x = 1;
for (int i = 0; i < 1000000; i++) {
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
int u1 = (x % B);
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
int u2 = (x % B);
swap(vv[u1], vv[u2]);
}
}
void dfs2(int pos) {
if (cols[pos] >= 0) return;
cols[pos] = cntv % 60; cntv++;
for (int i = 0; i < I[pos].size(); i++) dfs2(I[pos][i]);
}
vector<int> nearest(int sta, int rem) {
for (int i = 0; i < N; i++) dist[i] = (1 << 30);
queue<int>Q; Q.push(sta); dist[sta] = 0;
while (!Q.empty()) {
int pos = Q.front(); Q.pop();
for (int i = 0; i < I[pos].size(); i++) {
int to = I[pos][i];
if (dist[to] > dist[pos] + 1) {
dist[to] = dist[pos] + 1;
par[to] = pos;
Q.push(to);
}
}
}
int id = 0, minx = 10000;
for (int i = 0; i < N; i++) {
if (cols[i] == rem && dist[i] < minx) {
minx = dist[i]; id = i;
}
}
vector<int>U;
while (true) {
U.push_back(id); if (id == sta) break;
id = par[id];
}
reverse(U.begin(), U.end());
return U;
}
long long Ioi(int NN, int MM, int A[], int B[], int P, int V, int T) {
N = NN; M = MM; make_ransuu2(M);
for (int i = 0; i < M; i++) { I[A[vv[i]]].push_back(B[vv[i]]); I[B[vv[i]]].push_back(A[vv[i]]); }
for (int i = 0; i < N; i++) cols[i] = -1;
dfs2(0);
int cx = P; long long rem = 0;
for (int i = 0; i < 60; i++) {
vector<int>E; int id = -1;
for (int j = 0; j < 60; j++) {
if (used[j] == true) continue;
vector<int>F = nearest(cx, j);
if (E.size() == 0 || E.size() > F.size()) { E = F; id = j; }
}
int F = V;
for (int j = 1; j < E.size(); j++) {
F = Move(E[j]);
}
rem += 1LL * F * (1LL << id);
if (E.size() >= 1) cx = E[E.size() - 1];
used[id] = true;
}
return rem;
}
Compilation message
Joi.cpp: In function 'void dfs(int)':
Joi.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]);
~~^~~~~~~~~~~~~~~
Ioi.cpp: In function 'void dfs2(int)':
Ioi.cpp:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < I[pos].size(); i++) dfs2(I[pos][i]);
~~^~~~~~~~~~~~~~~
Ioi.cpp: In function 'std::vector<int> nearest(int, int)':
Ioi.cpp:40:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < I[pos].size(); i++) {
~~^~~~~~~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:81:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j < E.size(); j++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
1332 KB |
Output is correct |
2 |
Correct |
50 ms |
1288 KB |
Output is correct |
3 |
Correct |
56 ms |
1388 KB |
Output is correct |
4 |
Correct |
51 ms |
1376 KB |
Output is correct |
5 |
Correct |
51 ms |
1292 KB |
Output is correct |
6 |
Correct |
49 ms |
1376 KB |
Output is correct |
7 |
Correct |
63 ms |
1344 KB |
Output is correct |
8 |
Correct |
54 ms |
1356 KB |
Output is correct |
9 |
Correct |
54 ms |
1396 KB |
Output is correct |
10 |
Correct |
47 ms |
1264 KB |
Output is correct |
11 |
Correct |
76 ms |
1640 KB |
Output is correct |
12 |
Correct |
46 ms |
1248 KB |
Output is correct |
13 |
Correct |
63 ms |
1284 KB |
Output is correct |
14 |
Correct |
47 ms |
1260 KB |
Output is correct |
15 |
Correct |
47 ms |
1268 KB |
Output is correct |
16 |
Correct |
56 ms |
1396 KB |
Output is correct |
17 |
Correct |
51 ms |
1280 KB |
Output is correct |
18 |
Correct |
55 ms |
1376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
993 ms |
4096 KB |
Output is correct |
2 |
Correct |
1071 ms |
4240 KB |
Output is correct |
3 |
Correct |
1110 ms |
4144 KB |
Output is correct |
4 |
Correct |
741 ms |
2984 KB |
Output is correct |
5 |
Correct |
1006 ms |
3104 KB |
Output is correct |
6 |
Correct |
799 ms |
3084 KB |
Output is correct |
7 |
Correct |
861 ms |
3108 KB |
Output is correct |
8 |
Correct |
749 ms |
3096 KB |
Output is correct |
9 |
Correct |
902 ms |
3184 KB |
Output is correct |
10 |
Correct |
407 ms |
3192 KB |
Output is correct |
11 |
Correct |
387 ms |
2964 KB |
Output is correct |
12 |
Correct |
479 ms |
2800 KB |
Output is correct |
13 |
Correct |
501 ms |
2824 KB |
Output is correct |
14 |
Correct |
466 ms |
2740 KB |
Output is correct |
15 |
Correct |
676 ms |
2772 KB |
Output is correct |
16 |
Correct |
692 ms |
2936 KB |
Output is correct |
17 |
Correct |
705 ms |
2916 KB |
Output is correct |
18 |
Correct |
671 ms |
2772 KB |
Output is correct |
19 |
Correct |
730 ms |
2992 KB |
Output is correct |
20 |
Correct |
450 ms |
3128 KB |
Output is correct |
21 |
Correct |
469 ms |
3156 KB |
Output is correct |
22 |
Correct |
552 ms |
3052 KB |
Output is correct |
23 |
Correct |
536 ms |
3276 KB |
Output is correct |
24 |
Correct |
693 ms |
3068 KB |
Output is correct |
25 |
Correct |
528 ms |
3180 KB |
Output is correct |
26 |
Correct |
683 ms |
3012 KB |
Output is correct |
27 |
Correct |
642 ms |
3012 KB |
Output is correct |
28 |
Correct |
611 ms |
3112 KB |
Output is correct |
29 |
Correct |
561 ms |
2984 KB |
Output is correct |
30 |
Correct |
588 ms |
2964 KB |
Output is correct |
31 |
Correct |
56 ms |
1144 KB |
Output is correct |
32 |
Correct |
49 ms |
1152 KB |
Output is correct |
33 |
Correct |
46 ms |
1368 KB |
Output is correct |
34 |
Correct |
56 ms |
1152 KB |
Output is correct |
35 |
Correct |
49 ms |
1272 KB |
Output is correct |
36 |
Correct |
49 ms |
1288 KB |
Output is correct |
37 |
Correct |
47 ms |
1240 KB |
Output is correct |
38 |
Correct |
47 ms |
1144 KB |
Output is correct |
39 |
Correct |
49 ms |
1232 KB |
Output is correct |
40 |
Correct |
52 ms |
1236 KB |
Output is correct |
41 |
Correct |
56 ms |
1152 KB |
Output is correct |
42 |
Correct |
53 ms |
1288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
1416 KB |
Output is correct |
2 |
Correct |
44 ms |
1152 KB |
Output is correct |
3 |
Correct |
52 ms |
1148 KB |
Output is correct |
4 |
Correct |
89 ms |
1556 KB |
Output is correct |
5 |
Correct |
104 ms |
1548 KB |
Output is correct |
6 |
Correct |
93 ms |
1696 KB |
Output is correct |
7 |
Correct |
113 ms |
1824 KB |
Output is correct |
8 |
Correct |
100 ms |
1676 KB |
Output is correct |
9 |
Correct |
518 ms |
3444 KB |
Output is correct |
10 |
Correct |
635 ms |
3532 KB |
Output is correct |
11 |
Correct |
606 ms |
3504 KB |
Output is correct |
12 |
Correct |
45 ms |
1400 KB |
Output is correct |
13 |
Correct |
51 ms |
1364 KB |
Output is correct |
14 |
Correct |
51 ms |
1280 KB |
Output is correct |
15 |
Correct |
51 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1063 ms |
4268 KB |
Output is correct |
2 |
Correct |
1057 ms |
4112 KB |
Output is correct |
3 |
Correct |
945 ms |
4276 KB |
Output is correct |
4 |
Correct |
675 ms |
2896 KB |
Output is correct |
5 |
Correct |
894 ms |
3192 KB |
Output is correct |
6 |
Correct |
790 ms |
3172 KB |
Output is correct |
7 |
Correct |
803 ms |
3160 KB |
Output is correct |
8 |
Correct |
808 ms |
3032 KB |
Output is correct |
9 |
Correct |
793 ms |
2976 KB |
Output is correct |
10 |
Correct |
490 ms |
3044 KB |
Output is correct |
11 |
Correct |
459 ms |
2976 KB |
Output is correct |
12 |
Correct |
428 ms |
2804 KB |
Output is correct |
13 |
Correct |
499 ms |
2792 KB |
Output is correct |
14 |
Correct |
484 ms |
2952 KB |
Output is correct |
15 |
Correct |
608 ms |
2964 KB |
Output is correct |
16 |
Correct |
582 ms |
2860 KB |
Output is correct |
17 |
Correct |
660 ms |
2960 KB |
Output is correct |
18 |
Correct |
778 ms |
2872 KB |
Output is correct |
19 |
Correct |
752 ms |
2896 KB |
Output is correct |
20 |
Correct |
499 ms |
3152 KB |
Output is correct |
21 |
Correct |
567 ms |
3232 KB |
Output is correct |
22 |
Correct |
594 ms |
3060 KB |
Output is correct |
23 |
Correct |
685 ms |
3120 KB |
Output is correct |
24 |
Correct |
539 ms |
3228 KB |
Output is correct |
25 |
Correct |
603 ms |
3196 KB |
Output is correct |
26 |
Correct |
617 ms |
3212 KB |
Output is correct |
27 |
Correct |
676 ms |
3232 KB |
Output is correct |
28 |
Correct |
609 ms |
3008 KB |
Output is correct |
29 |
Correct |
553 ms |
3012 KB |
Output is correct |
30 |
Correct |
520 ms |
2964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
995 ms |
4136 KB |
Output is correct |
2 |
Correct |
1138 ms |
4124 KB |
Output is correct |
3 |
Correct |
987 ms |
4264 KB |
Output is correct |
4 |
Correct |
793 ms |
2968 KB |
Output is correct |
5 |
Correct |
877 ms |
3492 KB |
Output is correct |
6 |
Correct |
873 ms |
3080 KB |
Output is correct |
7 |
Correct |
818 ms |
2968 KB |
Output is correct |
8 |
Correct |
831 ms |
3196 KB |
Output is correct |
9 |
Correct |
811 ms |
3004 KB |
Output is correct |
10 |
Correct |
403 ms |
3004 KB |
Output is correct |
11 |
Correct |
505 ms |
2960 KB |
Output is correct |
12 |
Correct |
536 ms |
2736 KB |
Output is correct |
13 |
Correct |
488 ms |
2748 KB |
Output is correct |
14 |
Correct |
509 ms |
2736 KB |
Output is correct |
15 |
Correct |
594 ms |
2856 KB |
Output is correct |
16 |
Correct |
625 ms |
2932 KB |
Output is correct |
17 |
Correct |
677 ms |
2972 KB |
Output is correct |
18 |
Correct |
689 ms |
2964 KB |
Output is correct |
19 |
Correct |
710 ms |
2860 KB |
Output is correct |
20 |
Correct |
536 ms |
3284 KB |
Output is correct |
21 |
Correct |
458 ms |
3176 KB |
Output is correct |
22 |
Correct |
571 ms |
2996 KB |
Output is correct |
23 |
Correct |
531 ms |
3148 KB |
Output is correct |
24 |
Correct |
603 ms |
2988 KB |
Output is correct |
25 |
Correct |
541 ms |
3200 KB |
Output is correct |
26 |
Correct |
506 ms |
3004 KB |
Output is correct |
27 |
Correct |
562 ms |
3444 KB |
Output is correct |
28 |
Correct |
620 ms |
3372 KB |
Output is correct |
29 |
Correct |
602 ms |
3256 KB |
Output is correct |
30 |
Correct |
538 ms |
3300 KB |
Output is correct |
31 |
Correct |
46 ms |
1152 KB |
Output is correct |
32 |
Correct |
46 ms |
1256 KB |
Output is correct |
33 |
Correct |
50 ms |
1396 KB |
Output is correct |
34 |
Correct |
48 ms |
1316 KB |
Output is correct |
35 |
Correct |
52 ms |
1384 KB |
Output is correct |
36 |
Correct |
47 ms |
1420 KB |
Output is correct |
37 |
Correct |
44 ms |
1400 KB |
Output is correct |
38 |
Correct |
51 ms |
1248 KB |
Output is correct |
39 |
Correct |
51 ms |
1156 KB |
Output is correct |
40 |
Incorrect |
57 ms |
1156 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |