#include "game.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> adj[600600], INV[600600];
int n, k, cyc;
ll a[600600]; ///1 -> left, 2 -> right, 3 -> cycle (bit string)
void add_edge(int x, int y, int first = 1){
if (first) {adj[x].push_back(y); INV[y].push_back(x);}
if (cyc) return;
int l = 1, r = k;
ll prvx = a[x], prvy = a[y];
for (int i=0;;i+=2){
if (l>r) break;
assert(i<=40);
int m = (l+r)>>1;
if (x==m) a[x] |= 1LL<<i;
if (x==m+n) a[x] |= 2LL<<i;
if (y==m) a[x] |= 1LL<<i;
if (y==m+n) a[y] |= 2LL<<i;
if (a[x]&(2LL<<i)) a[y] |= 2LL<<i;
if (a[y]&(1LL<<i)) a[x] |= 1LL<<i;
if ((a[x]&(3LL<<i)) == (3LL<<i)) cyc = 1;
if ((a[y]&(3LL<<i)) == (3LL<<i)) cyc = 1;
if (cyc) break;
if ((a[x]&(3LL<<i)) != (a[y]&(3LL<<i))) break;
if (a[x]&(1LL<<i)) r = m-1;
else l = m+1;
}
if (prvx!=a[x]) for (auto &nx:INV[x]) add_edge(nx, x, 0);
if (prvy!=a[y]) for (auto &ny:adj[y]) add_edge(y, ny, 0);
}
void print(int x){
printf("%d: ", x);
int l = 1, r = k;
for (int i=0;;i+=2){
int m = (l+r)>>1;
if (a[x]&(1LL<<i)) {printf("1 [%d, %d] / ", l, r); r = m-1;}
else if (a[x]&(2LL<<i)) {printf("2 [%d, %d] / ", l, r); l = m+1;}
else break;
}
printf("(cyc = %d)\n", cyc);
}
void init(int N, int K) {
n = N, k = K;
for (int i=1;i<k;i++){
add_edge(i, i+n);
add_edge(i+n, i+1);
}
add_edge(k, k+n);
//for (int i=1;i<=k;i++) {print(i); print(i+n);}
}
int add_teleporter(int u, int v) {
++u, ++v;
add_edge(u<=k?u+n:u, v);
return cyc;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28484 KB |
Output is correct |
2 |
Correct |
14 ms |
28392 KB |
Output is correct |
3 |
Correct |
14 ms |
28496 KB |
Output is correct |
4 |
Correct |
14 ms |
28496 KB |
Output is correct |
5 |
Correct |
14 ms |
28476 KB |
Output is correct |
6 |
Correct |
16 ms |
28552 KB |
Output is correct |
7 |
Correct |
17 ms |
28496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28484 KB |
Output is correct |
2 |
Correct |
14 ms |
28392 KB |
Output is correct |
3 |
Correct |
14 ms |
28496 KB |
Output is correct |
4 |
Correct |
14 ms |
28496 KB |
Output is correct |
5 |
Correct |
14 ms |
28476 KB |
Output is correct |
6 |
Correct |
16 ms |
28552 KB |
Output is correct |
7 |
Correct |
17 ms |
28496 KB |
Output is correct |
8 |
Correct |
15 ms |
28508 KB |
Output is correct |
9 |
Correct |
13 ms |
28496 KB |
Output is correct |
10 |
Correct |
15 ms |
28496 KB |
Output is correct |
11 |
Correct |
14 ms |
28456 KB |
Output is correct |
12 |
Correct |
14 ms |
28496 KB |
Output is correct |
13 |
Correct |
14 ms |
28504 KB |
Output is correct |
14 |
Correct |
14 ms |
28524 KB |
Output is correct |
15 |
Correct |
16 ms |
28496 KB |
Output is correct |
16 |
Correct |
14 ms |
28496 KB |
Output is correct |
17 |
Correct |
16 ms |
28496 KB |
Output is correct |
18 |
Correct |
16 ms |
28520 KB |
Output is correct |
19 |
Correct |
15 ms |
28496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28484 KB |
Output is correct |
2 |
Correct |
14 ms |
28392 KB |
Output is correct |
3 |
Correct |
14 ms |
28496 KB |
Output is correct |
4 |
Correct |
14 ms |
28496 KB |
Output is correct |
5 |
Correct |
14 ms |
28476 KB |
Output is correct |
6 |
Correct |
16 ms |
28552 KB |
Output is correct |
7 |
Correct |
17 ms |
28496 KB |
Output is correct |
8 |
Correct |
15 ms |
28508 KB |
Output is correct |
9 |
Correct |
13 ms |
28496 KB |
Output is correct |
10 |
Correct |
15 ms |
28496 KB |
Output is correct |
11 |
Correct |
14 ms |
28456 KB |
Output is correct |
12 |
Correct |
14 ms |
28496 KB |
Output is correct |
13 |
Correct |
14 ms |
28504 KB |
Output is correct |
14 |
Correct |
14 ms |
28524 KB |
Output is correct |
15 |
Correct |
16 ms |
28496 KB |
Output is correct |
16 |
Correct |
14 ms |
28496 KB |
Output is correct |
17 |
Correct |
16 ms |
28496 KB |
Output is correct |
18 |
Correct |
16 ms |
28520 KB |
Output is correct |
19 |
Correct |
15 ms |
28496 KB |
Output is correct |
20 |
Correct |
14 ms |
28528 KB |
Output is correct |
21 |
Correct |
16 ms |
28432 KB |
Output is correct |
22 |
Correct |
15 ms |
28536 KB |
Output is correct |
23 |
Correct |
15 ms |
28484 KB |
Output is correct |
24 |
Correct |
16 ms |
28648 KB |
Output is correct |
25 |
Correct |
16 ms |
28624 KB |
Output is correct |
26 |
Correct |
16 ms |
28624 KB |
Output is correct |
27 |
Correct |
16 ms |
28636 KB |
Output is correct |
28 |
Correct |
16 ms |
28752 KB |
Output is correct |
29 |
Correct |
18 ms |
28672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28484 KB |
Output is correct |
2 |
Correct |
14 ms |
28392 KB |
Output is correct |
3 |
Correct |
14 ms |
28496 KB |
Output is correct |
4 |
Correct |
14 ms |
28496 KB |
Output is correct |
5 |
Correct |
14 ms |
28476 KB |
Output is correct |
6 |
Correct |
16 ms |
28552 KB |
Output is correct |
7 |
Correct |
17 ms |
28496 KB |
Output is correct |
8 |
Correct |
15 ms |
28508 KB |
Output is correct |
9 |
Correct |
13 ms |
28496 KB |
Output is correct |
10 |
Correct |
15 ms |
28496 KB |
Output is correct |
11 |
Correct |
14 ms |
28456 KB |
Output is correct |
12 |
Correct |
14 ms |
28496 KB |
Output is correct |
13 |
Correct |
14 ms |
28504 KB |
Output is correct |
14 |
Correct |
14 ms |
28524 KB |
Output is correct |
15 |
Correct |
16 ms |
28496 KB |
Output is correct |
16 |
Correct |
14 ms |
28496 KB |
Output is correct |
17 |
Correct |
16 ms |
28496 KB |
Output is correct |
18 |
Correct |
16 ms |
28520 KB |
Output is correct |
19 |
Correct |
15 ms |
28496 KB |
Output is correct |
20 |
Correct |
14 ms |
28528 KB |
Output is correct |
21 |
Correct |
16 ms |
28432 KB |
Output is correct |
22 |
Correct |
15 ms |
28536 KB |
Output is correct |
23 |
Correct |
15 ms |
28484 KB |
Output is correct |
24 |
Correct |
16 ms |
28648 KB |
Output is correct |
25 |
Correct |
16 ms |
28624 KB |
Output is correct |
26 |
Correct |
16 ms |
28624 KB |
Output is correct |
27 |
Correct |
16 ms |
28636 KB |
Output is correct |
28 |
Correct |
16 ms |
28752 KB |
Output is correct |
29 |
Correct |
18 ms |
28672 KB |
Output is correct |
30 |
Correct |
28 ms |
29828 KB |
Output is correct |
31 |
Correct |
19 ms |
29260 KB |
Output is correct |
32 |
Correct |
38 ms |
31876 KB |
Output is correct |
33 |
Correct |
35 ms |
30536 KB |
Output is correct |
34 |
Correct |
63 ms |
36048 KB |
Output is correct |
35 |
Correct |
66 ms |
32552 KB |
Output is correct |
36 |
Correct |
53 ms |
30660 KB |
Output is correct |
37 |
Correct |
49 ms |
30680 KB |
Output is correct |
38 |
Correct |
43 ms |
30548 KB |
Output is correct |
39 |
Correct |
46 ms |
30544 KB |
Output is correct |
40 |
Correct |
61 ms |
35652 KB |
Output is correct |
41 |
Correct |
52 ms |
33352 KB |
Output is correct |
42 |
Correct |
60 ms |
31296 KB |
Output is correct |
43 |
Correct |
75 ms |
32088 KB |
Output is correct |
44 |
Correct |
84 ms |
32668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28484 KB |
Output is correct |
2 |
Correct |
14 ms |
28392 KB |
Output is correct |
3 |
Correct |
14 ms |
28496 KB |
Output is correct |
4 |
Correct |
14 ms |
28496 KB |
Output is correct |
5 |
Correct |
14 ms |
28476 KB |
Output is correct |
6 |
Correct |
16 ms |
28552 KB |
Output is correct |
7 |
Correct |
17 ms |
28496 KB |
Output is correct |
8 |
Correct |
15 ms |
28508 KB |
Output is correct |
9 |
Correct |
13 ms |
28496 KB |
Output is correct |
10 |
Correct |
15 ms |
28496 KB |
Output is correct |
11 |
Correct |
14 ms |
28456 KB |
Output is correct |
12 |
Correct |
14 ms |
28496 KB |
Output is correct |
13 |
Correct |
14 ms |
28504 KB |
Output is correct |
14 |
Correct |
14 ms |
28524 KB |
Output is correct |
15 |
Correct |
16 ms |
28496 KB |
Output is correct |
16 |
Correct |
14 ms |
28496 KB |
Output is correct |
17 |
Correct |
16 ms |
28496 KB |
Output is correct |
18 |
Correct |
16 ms |
28520 KB |
Output is correct |
19 |
Correct |
15 ms |
28496 KB |
Output is correct |
20 |
Correct |
14 ms |
28528 KB |
Output is correct |
21 |
Correct |
16 ms |
28432 KB |
Output is correct |
22 |
Correct |
15 ms |
28536 KB |
Output is correct |
23 |
Correct |
15 ms |
28484 KB |
Output is correct |
24 |
Correct |
16 ms |
28648 KB |
Output is correct |
25 |
Correct |
16 ms |
28624 KB |
Output is correct |
26 |
Correct |
16 ms |
28624 KB |
Output is correct |
27 |
Correct |
16 ms |
28636 KB |
Output is correct |
28 |
Correct |
16 ms |
28752 KB |
Output is correct |
29 |
Correct |
18 ms |
28672 KB |
Output is correct |
30 |
Correct |
28 ms |
29828 KB |
Output is correct |
31 |
Correct |
19 ms |
29260 KB |
Output is correct |
32 |
Correct |
38 ms |
31876 KB |
Output is correct |
33 |
Correct |
35 ms |
30536 KB |
Output is correct |
34 |
Correct |
63 ms |
36048 KB |
Output is correct |
35 |
Correct |
66 ms |
32552 KB |
Output is correct |
36 |
Correct |
53 ms |
30660 KB |
Output is correct |
37 |
Correct |
49 ms |
30680 KB |
Output is correct |
38 |
Correct |
43 ms |
30548 KB |
Output is correct |
39 |
Correct |
46 ms |
30544 KB |
Output is correct |
40 |
Correct |
61 ms |
35652 KB |
Output is correct |
41 |
Correct |
52 ms |
33352 KB |
Output is correct |
42 |
Correct |
60 ms |
31296 KB |
Output is correct |
43 |
Correct |
75 ms |
32088 KB |
Output is correct |
44 |
Correct |
84 ms |
32668 KB |
Output is correct |
45 |
Correct |
285 ms |
41748 KB |
Output is correct |
46 |
Correct |
21 ms |
29264 KB |
Output is correct |
47 |
Correct |
21 ms |
29520 KB |
Output is correct |
48 |
Correct |
363 ms |
61620 KB |
Output is correct |
49 |
Correct |
269 ms |
49588 KB |
Output is correct |
50 |
Correct |
1150 ms |
89200 KB |
Output is correct |
51 |
Correct |
1106 ms |
69968 KB |
Output is correct |
52 |
Correct |
584 ms |
49624 KB |
Output is correct |
53 |
Correct |
831 ms |
50052 KB |
Output is correct |
54 |
Correct |
1008 ms |
51516 KB |
Output is correct |
55 |
Correct |
1209 ms |
50640 KB |
Output is correct |
56 |
Correct |
1590 ms |
51364 KB |
Output is correct |
57 |
Correct |
735 ms |
74528 KB |
Output is correct |
58 |
Correct |
712 ms |
74724 KB |
Output is correct |
59 |
Correct |
767 ms |
74664 KB |
Output is correct |
60 |
Correct |
723 ms |
74884 KB |
Output is correct |
61 |
Correct |
894 ms |
74500 KB |
Output is correct |
62 |
Correct |
738 ms |
66112 KB |
Output is correct |
63 |
Correct |
614 ms |
62836 KB |
Output is correct |
64 |
Correct |
1602 ms |
96740 KB |
Output is correct |
65 |
Correct |
660 ms |
55988 KB |
Output is correct |
66 |
Correct |
568 ms |
52212 KB |
Output is correct |
67 |
Correct |
985 ms |
62528 KB |
Output is correct |
68 |
Correct |
274 ms |
51656 KB |
Output is correct |
69 |
Correct |
115 ms |
45776 KB |
Output is correct |
70 |
Correct |
1071 ms |
69728 KB |
Output is correct |
71 |
Correct |
405 ms |
52460 KB |
Output is correct |
72 |
Correct |
300 ms |
48692 KB |
Output is correct |
73 |
Correct |
939 ms |
69344 KB |
Output is correct |
74 |
Correct |
1876 ms |
53288 KB |
Output is correct |
75 |
Correct |
1703 ms |
65592 KB |
Output is correct |
76 |
Correct |
1735 ms |
73204 KB |
Output is correct |