Submission #1068249

# Submission time Handle Problem Language Result Execution time Memory
1068249 2024-08-21T08:50:29 Z Boas Keys (IOI21_keys) C++17
37 / 100
3000 ms 34392 KB
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef set<int> si;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define ALL(x) begin(x), end(x)
#define sz(x) (int)x.size()

vi find_reachable(vi r, vi u, vi v, vi c)
{
	int n = sz(r);
	int m = sz(c);
	vvii adj(n);
	loop(m, i)
	{
		adj[u[i]].pb({v[i], c[i]});
		adj[v[i]].pb({u[i], c[i]});
	}
	vi cnt(n);
	loop(n, i)
	{
		si keys;
		vvi edgesPerKey(n);
		vb vis(n);
		auto addRoom = [&](auto &&self, int room) -> void
		{
			int key = r[room];
			vis[room] = 1;
			cnt[i]++;
			if (!keys.count(key))
			{
				keys.insert(key);
				for (int j : edgesPerKey[key])
				{
					if (!vis[j])
						self(self, j);
				}
			}
			for (auto [j, keyNeeded] : adj[room])
			{
				if (vis[j])
					continue;
				if (keys.count(keyNeeded))
				{
					self(self, j);
				}
				else
					edgesPerKey[keyNeeded].pb(j);
			}
		};
		addRoom(addRoom, i);
	}
	int min = *min_element(ALL(cnt));
	vi ans(n);
	loop(n, i) if (cnt[i] == min) ans[i] = 1;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 472 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 6 ms 348 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 472 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 6 ms 348 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 238 ms 860 KB Output is correct
28 Correct 239 ms 856 KB Output is correct
29 Correct 231 ms 860 KB Output is correct
30 Correct 116 ms 604 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 444 KB Output is correct
34 Correct 63 ms 604 KB Output is correct
35 Correct 119 ms 604 KB Output is correct
36 Correct 513 ms 860 KB Output is correct
37 Correct 500 ms 856 KB Output is correct
38 Correct 816 ms 928 KB Output is correct
39 Correct 809 ms 860 KB Output is correct
40 Correct 11 ms 600 KB Output is correct
41 Correct 59 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Execution timed out 3067 ms 34392 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 472 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 6 ms 348 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 238 ms 860 KB Output is correct
28 Correct 239 ms 856 KB Output is correct
29 Correct 231 ms 860 KB Output is correct
30 Correct 116 ms 604 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 444 KB Output is correct
34 Correct 63 ms 604 KB Output is correct
35 Correct 119 ms 604 KB Output is correct
36 Correct 513 ms 860 KB Output is correct
37 Correct 500 ms 856 KB Output is correct
38 Correct 816 ms 928 KB Output is correct
39 Correct 809 ms 860 KB Output is correct
40 Correct 11 ms 600 KB Output is correct
41 Correct 59 ms 692 KB Output is correct
42 Execution timed out 3067 ms 34392 KB Time limit exceeded
43 Halted 0 ms 0 KB -