#include <cstdio>
#include <cstdlib>
#include <vector>
#include "game.h"
#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 <bitset>
#include <cassert>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>
using namespace std;
const int R = 50;
bool F;
int n;
int k;
vector<bool> req;
vector<vector<int>> g;
vector<vector<int>> ig;
vector<int> minAjungBucket;
vector<int> minAjung;
int getbucket(int x)
{
return x / R;
}
void init(int nn, int kk)
{
F = 0;
n = nn;
k = kk;
minAjung.clear();
g.clear();
ig.clear();
req.clear();
g.resize(n + 1);
ig.resize(n + 1);
minAjungBucket.resize(n + 1);
minAjung.resize(n + 1);
req.resize(n + 1, 0);
for (int i = 1; i <= n; i++)
{
minAjungBucket[i] = (int)1e9 + 7;
minAjung[i] = k + 1;
}
}
void upd(int from)
{
if (F)
{
return;
}
if (from <= k && minAjung[from] <= from)
{
F = 1;
}
for (auto& vec : ig[from])
{
if (minAjung[from] < minAjung[vec])
{
minAjung[vec] = minAjung[from];
upd(vec);
}
}
}
void send_req_all(int from)
{
if (req[from]) return;
req[from] = 1;
for (auto& to : g[from])
{
int val = ((to <= k) ? (to) : (minAjung[to]));
if (val < minAjung[from] && req[from])
{
minAjung[from] = val;
upd(from);
}
}
for (auto& to : g[from])
{
send_req_all(to);
}
}
void updBucket(int from)
{
if (F)
{
return;
}
if (from <= k && minAjungBucket[from] == getbucket(from))
{
send_req_all(from);
}
if (from <= k && minAjungBucket[from] < getbucket(from))
{
F = 1;
}
for (auto& vec : ig[from])
{
if (minAjungBucket[from] < minAjungBucket[vec])
{
minAjungBucket[vec] = minAjungBucket[from];
updBucket(vec);
}
}
}
int add_teleporter(int from, int to)
{
from++;
to++;
assert(1 <= from && from <= n);
assert(1 <= to && to <= n);
if (req[to] == 0 && req[from] == 1)
{
send_req_all(to);
}
g[from].push_back(to);
ig[to].push_back(from);
{
int val = ((to <= k) ? (getbucket(to)) : (minAjungBucket[to]));
if (val < minAjungBucket[from])
{
minAjungBucket[from] = val;
updBucket(from);
}
}
{
int val = ((to <= k) ? (to) : (minAjung[to]));
if (val < minAjung[from] && req[from])
{
minAjung[from] = val;
upd(from);
}
}
return F;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 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 |
0 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 |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 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 |
0 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 |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 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 |
0 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 |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
24 ms |
3036 KB |
Output is correct |
31 |
Correct |
6 ms |
2276 KB |
Output is correct |
32 |
Correct |
38 ms |
5900 KB |
Output is correct |
33 |
Correct |
26 ms |
3756 KB |
Output is correct |
34 |
Correct |
692 ms |
6060 KB |
Output is correct |
35 |
Correct |
382 ms |
5696 KB |
Output is correct |
36 |
Correct |
53 ms |
3720 KB |
Output is correct |
37 |
Correct |
37 ms |
3792 KB |
Output is correct |
38 |
Correct |
26 ms |
3524 KB |
Output is correct |
39 |
Correct |
33 ms |
3576 KB |
Output is correct |
40 |
Correct |
589 ms |
6032 KB |
Output is correct |
41 |
Correct |
176 ms |
5048 KB |
Output is correct |
42 |
Correct |
116 ms |
4224 KB |
Output is correct |
43 |
Correct |
60 ms |
5668 KB |
Output is correct |
44 |
Correct |
100 ms |
5596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 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 |
0 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 |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
24 ms |
3036 KB |
Output is correct |
31 |
Correct |
6 ms |
2276 KB |
Output is correct |
32 |
Correct |
38 ms |
5900 KB |
Output is correct |
33 |
Correct |
26 ms |
3756 KB |
Output is correct |
34 |
Correct |
692 ms |
6060 KB |
Output is correct |
35 |
Correct |
382 ms |
5696 KB |
Output is correct |
36 |
Correct |
53 ms |
3720 KB |
Output is correct |
37 |
Correct |
37 ms |
3792 KB |
Output is correct |
38 |
Correct |
26 ms |
3524 KB |
Output is correct |
39 |
Correct |
33 ms |
3576 KB |
Output is correct |
40 |
Correct |
589 ms |
6032 KB |
Output is correct |
41 |
Correct |
176 ms |
5048 KB |
Output is correct |
42 |
Correct |
116 ms |
4224 KB |
Output is correct |
43 |
Correct |
60 ms |
5668 KB |
Output is correct |
44 |
Correct |
100 ms |
5596 KB |
Output is correct |
45 |
Correct |
239 ms |
28060 KB |
Output is correct |
46 |
Correct |
17 ms |
17232 KB |
Output is correct |
47 |
Correct |
17 ms |
17264 KB |
Output is correct |
48 |
Correct |
316 ms |
45068 KB |
Output is correct |
49 |
Correct |
340 ms |
35580 KB |
Output is correct |
50 |
Execution timed out |
4024 ms |
36184 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |