# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
774179 |
2023-07-05T12:33:58 Z |
danikoynov |
Game (IOI14_game) |
C++14 |
|
999 ms |
36708 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1510;
int n;
int used[maxn], in_st[maxn * maxn], in_mst[maxn * maxn];
vector < int > st, mst;
mt19937 rng;
void random_shuffle()
{
for (int i = 0; i < st.size(); i ++)
{
int idx = rng() % (int)(st.size());
swap(st[i], st[idx]);
}
}
int par[maxn];
int find_leader(int v)
{
if (v == par[v])
return v;
return (par[v] = find_leader(par[v]));
}
bool unite(int v, int u)
{
v = find_leader(v);
u = find_leader(u);
if (v == u)
return false;
par[v] = u;
return true;
}
bitset < maxn > nb[maxn];
void initialize(int N)
{
n = N;
for (int i = 0; i < n; i ++)
for (int j = i + 1; j < n; j ++)
{
if (i != j)
{
nb[i][j] = nb[j][i] = 1;
st.push_back(i * n + j), in_st[i * n + j] = 1;
}
}
for (int i = 0; i < n; i ++)
par[i] = i;
random_shuffle();
for (int edge : st)
{
int v = edge / n, u = edge % n;
if (unite(v, u))
{
///cout << v << " : " << u << endl;
in_st[edge] = 0;
in_mst[edge] = 1;
mst.push_back(edge);
}
}
random_shuffle();
}
vector < int > adj[maxn];
void dfs(int v, int cnt)
{
used[v] = cnt;
for (int u : adj[v])
{
if (!used[u])
dfs(u, cnt);
}
}
void rem(int v, int u)
{
int pt = 0;
while(adj[v][pt] != u)
pt ++;
adj[v].erase(adj[v].begin() + pt);
}
int cnt = 0;
int hasEdge(int u, int v)
{
cnt ++;
//cout << "----------------" << endl;
if (u > v)
swap(u, v);
int hs = u * n + v;
if (!in_mst[hs])
{
nb[u][v] = nb[v][u] = 0;
in_st[hs] =0;
return 0;
}
for (int i = 0; i < n; i ++)
adj[i].clear(), used[i] = 0;
for (int edge : mst)
{
if (edge == hs)
continue;
///cout << edge / n << " " << edge % n << endl;
adj[edge / n].push_back(edge % n);
adj[edge % n].push_back(edge / n);
}
dfs(0, 1);
for (int i = 0; i < n; i ++)
if (used[i] == 0)
{
dfs(i, 2);
break;
}
if (n * (n - 1) / 2 - cnt > n * 20)
{
bitset < maxn > tk;
for (int i = 0; i < n; i ++)
{
if (used[i] == 1)
tk[i] = 1;
}
nb[hs / n][hs % n] = nb[hs % n][hs / n] = 0;
for (int i = 0; i < n; i ++)
{
if (used[i] == 2)
{
bitset < maxn > cur = (nb[i] & tk);
if (cur.count() > 0)
{
int v = i, u = cur._Find_first();
///cout << v << " : " << u << endl;
if (v > u)
swap(v, u);
in_mst[v * n + u] = 1;
mst.push_back(v * n + u);
int pt = 0;
while(mst[pt] != hs)
pt ++;
in_mst[hs] = 0;
in_st[v * n + u] = 0;
mst.erase(mst.begin() + pt);
return 0;
}
}
}
nb[hs / n][hs % n] = nb[hs % n][hs / n] = 1;
return 1;
}
else
{
vector < int > new_st;
for (int cur: st)
{
if (in_st[cur])
new_st.push_back(cur);
}
st = new_st;
for (int edge : st)
{
if (edge == hs)
continue;
if (used[edge / n] != used[edge % n])
{
///cout << "replace " << edge / n << " " << edge % n << endl;
in_st[hs] = 0;
in_mst[edge] = 1;
mst.push_back(edge);
in_mst[hs] = 0;
int pt = 0;
while(mst[pt] != hs)
pt ++;
mst.erase(mst.begin() + pt);
in_st[edge] = 0;
return 0;
}
}
}
return 1;
}
Compilation message
game.cpp: In function 'void random_shuffle()':
game.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < st.size(); i ++)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
360 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
360 KB |
Output is correct |
20 |
Correct |
1 ms |
356 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
356 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
360 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
356 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
2 ms |
500 KB |
Output is correct |
35 |
Correct |
2 ms |
500 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
2 ms |
468 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
4 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
2 ms |
468 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
2 ms |
468 KB |
Output is correct |
49 |
Correct |
2 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
468 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
3 ms |
468 KB |
Output is correct |
53 |
Correct |
2 ms |
468 KB |
Output is correct |
54 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
368 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
360 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
360 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
360 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
360 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
356 KB |
Output is correct |
30 |
Correct |
1 ms |
360 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
360 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
500 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Correct |
2 ms |
508 KB |
Output is correct |
40 |
Correct |
3 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
500 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
4 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
3 ms |
500 KB |
Output is correct |
46 |
Correct |
2 ms |
596 KB |
Output is correct |
47 |
Correct |
3 ms |
496 KB |
Output is correct |
48 |
Correct |
2 ms |
468 KB |
Output is correct |
49 |
Correct |
2 ms |
468 KB |
Output is correct |
50 |
Correct |
2 ms |
468 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
2 ms |
468 KB |
Output is correct |
53 |
Correct |
2 ms |
468 KB |
Output is correct |
54 |
Correct |
3 ms |
468 KB |
Output is correct |
55 |
Correct |
71 ms |
4764 KB |
Output is correct |
56 |
Correct |
71 ms |
4756 KB |
Output is correct |
57 |
Correct |
81 ms |
4944 KB |
Output is correct |
58 |
Correct |
72 ms |
4828 KB |
Output is correct |
59 |
Correct |
71 ms |
4832 KB |
Output is correct |
60 |
Correct |
71 ms |
4804 KB |
Output is correct |
61 |
Correct |
72 ms |
4808 KB |
Output is correct |
62 |
Correct |
84 ms |
4868 KB |
Output is correct |
63 |
Correct |
74 ms |
4860 KB |
Output is correct |
64 |
Correct |
999 ms |
5112 KB |
Output is correct |
65 |
Correct |
44 ms |
4644 KB |
Output is correct |
66 |
Correct |
75 ms |
4856 KB |
Output is correct |
67 |
Correct |
74 ms |
4644 KB |
Output is correct |
68 |
Correct |
80 ms |
4780 KB |
Output is correct |
69 |
Correct |
76 ms |
4752 KB |
Output is correct |
70 |
Correct |
76 ms |
4764 KB |
Output is correct |
71 |
Correct |
71 ms |
4760 KB |
Output is correct |
72 |
Correct |
79 ms |
4764 KB |
Output is correct |
73 |
Correct |
71 ms |
4780 KB |
Output is correct |
74 |
Correct |
72 ms |
4784 KB |
Output is correct |
75 |
Correct |
78 ms |
4808 KB |
Output is correct |
76 |
Correct |
179 ms |
10608 KB |
Output is correct |
77 |
Correct |
180 ms |
10384 KB |
Output is correct |
78 |
Correct |
174 ms |
10288 KB |
Output is correct |
79 |
Correct |
178 ms |
10312 KB |
Output is correct |
80 |
Correct |
176 ms |
10348 KB |
Output is correct |
81 |
Correct |
172 ms |
10288 KB |
Output is correct |
82 |
Correct |
181 ms |
10368 KB |
Output is correct |
83 |
Correct |
173 ms |
10412 KB |
Output is correct |
84 |
Correct |
172 ms |
10268 KB |
Output is correct |
85 |
Correct |
317 ms |
16740 KB |
Output is correct |
86 |
Correct |
315 ms |
15952 KB |
Output is correct |
87 |
Correct |
326 ms |
15804 KB |
Output is correct |
88 |
Correct |
317 ms |
15792 KB |
Output is correct |
89 |
Correct |
315 ms |
15800 KB |
Output is correct |
90 |
Correct |
316 ms |
15748 KB |
Output is correct |
91 |
Correct |
317 ms |
15716 KB |
Output is correct |
92 |
Correct |
316 ms |
15676 KB |
Output is correct |
93 |
Correct |
317 ms |
15672 KB |
Output is correct |
94 |
Correct |
795 ms |
28580 KB |
Output is correct |
95 |
Correct |
867 ms |
29168 KB |
Output is correct |
96 |
Correct |
794 ms |
36528 KB |
Output is correct |
97 |
Correct |
820 ms |
36708 KB |
Output is correct |
98 |
Correct |
784 ms |
36540 KB |
Output is correct |
99 |
Correct |
866 ms |
36588 KB |
Output is correct |
100 |
Correct |
800 ms |
36692 KB |
Output is correct |