#include "game.h"
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>
using namespace std;
const int INF = (int)1e9 + 7;
int n;
int k;
vector<int> prec;
vector<vector<int>> g, ig;
vector<pair<int, int>> range;
void init(int nn, int kk)
{
n = nn;
k = kk;
g.clear();
ig.clear();
prec.clear();
range.clear();
g.resize(n + 1);
ig.resize(n + 1);
range.resize(n + 1);
prec.resize(n + 1);
for (int i = 1; i <= n; i++)
{
range[i] = { 0, k + 1 };
prec[i] = (1 << 20);
//prec[i] = 1;
}
}
int upd(int from, int to);
int test(int v)
{
if (prec[v] == 1) return 0;
if (range[v].first / prec[v] == range[v].second / prec[v])
{
assert(prec[v] >= 2);
assert(prec[v] % 2 == 0);
prec[v] /= 2;
for (auto& vec : g[v])
{
if (upd(v, vec)) return 1;
}
for (auto& vec : ig[v])
{
if (upd(vec, v)) return 1;
}
}
return 0;
}
int upd(int from, int to)
{
{
int val = (from <= k) ? (from) : range[from].first;
if (val/prec[to] > range[to].first/prec[to])
{
range[to].first = val;
for (auto& vertex : g[to])
{
if (upd(to, vertex))
{
return 1;
}
}
}
}
{
int val = (to <= k) ? (to) : range[to].second;
if (val/prec[from] < range[from].second/prec[from])
{
range[from].second = val;
for (auto& vertex : ig[from])
{
if (upd(vertex, from))
{
return 1;
}
}
}
}
if (test(from)) return 1;
if (test(to)) return 1;
if (range[from].first >= range[from].second) return 1;
if (range[to].first >= range[to].second) return 1;
return 0;
}
int add_teleporter(int from, int to)
{
from++;
to++;
assert(1 <= from && from <= n);
assert(1 <= to && to <= n);
g[from].push_back(to);
ig[to].push_back(from);
if (from >= to && from <= k) return 1;
if (from == to) return 0;
return upd(from, to);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
520 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
720 KB |
Output is correct |
25 |
Correct |
5 ms |
592 KB |
Output is correct |
26 |
Correct |
5 ms |
372 KB |
Output is correct |
27 |
Correct |
4 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
592 KB |
Output is correct |
29 |
Correct |
4 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
520 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
720 KB |
Output is correct |
25 |
Correct |
5 ms |
592 KB |
Output is correct |
26 |
Correct |
5 ms |
372 KB |
Output is correct |
27 |
Correct |
4 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
592 KB |
Output is correct |
29 |
Correct |
4 ms |
620 KB |
Output is correct |
30 |
Correct |
38 ms |
3220 KB |
Output is correct |
31 |
Correct |
12 ms |
2384 KB |
Output is correct |
32 |
Correct |
61 ms |
14516 KB |
Output is correct |
33 |
Correct |
60 ms |
3956 KB |
Output is correct |
34 |
Correct |
122 ms |
30696 KB |
Output is correct |
35 |
Correct |
96 ms |
11268 KB |
Output is correct |
36 |
Correct |
79 ms |
4040 KB |
Output is correct |
37 |
Correct |
73 ms |
3976 KB |
Output is correct |
38 |
Correct |
65 ms |
3668 KB |
Output is correct |
39 |
Correct |
72 ms |
3864 KB |
Output is correct |
40 |
Correct |
118 ms |
23652 KB |
Output is correct |
41 |
Correct |
71 ms |
6868 KB |
Output is correct |
42 |
Correct |
71 ms |
8196 KB |
Output is correct |
43 |
Correct |
95 ms |
6524 KB |
Output is correct |
44 |
Correct |
113 ms |
7552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
520 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
720 KB |
Output is correct |
25 |
Correct |
5 ms |
592 KB |
Output is correct |
26 |
Correct |
5 ms |
372 KB |
Output is correct |
27 |
Correct |
4 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
592 KB |
Output is correct |
29 |
Correct |
4 ms |
620 KB |
Output is correct |
30 |
Correct |
38 ms |
3220 KB |
Output is correct |
31 |
Correct |
12 ms |
2384 KB |
Output is correct |
32 |
Correct |
61 ms |
14516 KB |
Output is correct |
33 |
Correct |
60 ms |
3956 KB |
Output is correct |
34 |
Correct |
122 ms |
30696 KB |
Output is correct |
35 |
Correct |
96 ms |
11268 KB |
Output is correct |
36 |
Correct |
79 ms |
4040 KB |
Output is correct |
37 |
Correct |
73 ms |
3976 KB |
Output is correct |
38 |
Correct |
65 ms |
3668 KB |
Output is correct |
39 |
Correct |
72 ms |
3864 KB |
Output is correct |
40 |
Correct |
118 ms |
23652 KB |
Output is correct |
41 |
Correct |
71 ms |
6868 KB |
Output is correct |
42 |
Correct |
71 ms |
8196 KB |
Output is correct |
43 |
Correct |
95 ms |
6524 KB |
Output is correct |
44 |
Correct |
113 ms |
7552 KB |
Output is correct |
45 |
Correct |
453 ms |
29292 KB |
Output is correct |
46 |
Correct |
23 ms |
18360 KB |
Output is correct |
47 |
Correct |
19 ms |
18216 KB |
Output is correct |
48 |
Correct |
776 ms |
146236 KB |
Output is correct |
49 |
Correct |
544 ms |
36724 KB |
Output is correct |
50 |
Correct |
1852 ms |
213412 KB |
Output is correct |
51 |
Correct |
1832 ms |
74948 KB |
Output is correct |
52 |
Correct |
936 ms |
36808 KB |
Output is correct |
53 |
Correct |
1192 ms |
37364 KB |
Output is correct |
54 |
Correct |
1372 ms |
37416 KB |
Output is correct |
55 |
Correct |
1772 ms |
55116 KB |
Output is correct |
56 |
Correct |
1918 ms |
42764 KB |
Output is correct |
57 |
Correct |
868 ms |
30924 KB |
Output is correct |
58 |
Correct |
863 ms |
31096 KB |
Output is correct |
59 |
Correct |
928 ms |
31296 KB |
Output is correct |
60 |
Correct |
940 ms |
31852 KB |
Output is correct |
61 |
Correct |
1071 ms |
33924 KB |
Output is correct |
62 |
Correct |
974 ms |
74760 KB |
Output is correct |
63 |
Correct |
887 ms |
53848 KB |
Output is correct |
64 |
Correct |
2501 ms |
150000 KB |
Output is correct |
65 |
Correct |
953 ms |
52032 KB |
Output is correct |
66 |
Correct |
900 ms |
43836 KB |
Output is correct |
67 |
Correct |
1625 ms |
56020 KB |
Output is correct |
68 |
Correct |
280 ms |
27740 KB |
Output is correct |
69 |
Correct |
88 ms |
21536 KB |
Output is correct |
70 |
Correct |
1583 ms |
77504 KB |
Output is correct |
71 |
Correct |
484 ms |
30284 KB |
Output is correct |
72 |
Correct |
312 ms |
26116 KB |
Output is correct |
73 |
Correct |
1252 ms |
61820 KB |
Output is correct |
74 |
Correct |
2181 ms |
42572 KB |
Output is correct |
75 |
Correct |
1962 ms |
61820 KB |
Output is correct |
76 |
Correct |
2610 ms |
70620 KB |
Output is correct |