Grakn Forces 2020题解

Grakn Forces 2020 [Div1 and Div2 combined]

A. Circle Coloring

别看这个

首先,令 \(c_1=a_1\)

那么对于 \(i \in \{2,3,…,n-1\}\) 如果 \(a_i = c_i -1\),则设 \(c_i=b_i\)。否则,设 \(c_i = a_i\)

最后,将 \(c_n\) 设为 \(\{a_n,b_n,c_n\}\)的其中之一,\(c_n \ne c_1\)\(c_{n-1}\)

看这个:

At first, set \(p_1 = a_1\).

Then for \(i \in \{2, \ldots, n-1\}\) if \(a_i = p_{i-1}\), then set \(p_i = b_i\). Otherwise, set \(p_i = a_i\).

In the end, set \(p_n\) to one of \(\{a_n, b_n, c_n\}\), which is not equal to \(p_1\) or \(p_{n-1}\).

Code

B. Arrays Sum

Case \(k=1\):

If all ai are equal the answer is \(1\).

Otherwise the answer is \(−1\).

Case \(k>1\):

Let's consider an array \(a' = (a_2 - a_1, a_3 - a_2, \ldots, a_n - a_{n-1})\) and arrays \(b_i' = (b_{i, 2} - b_{i, 1}, b_{i, 3} - b_{i, 2}, \ldots, b_{i, n} - b_{i, n-1})\).

The number of non-zero elements in \(b_i'\) is at most \(k-1\).

Let's define \(c\) as the number of non-zero elements in \(a'\) or in the other words the number of indices \(i\), such that \(a_i≠a_i+1\).

The answer is at least \(\lceil \frac{c}{k-1} \rceil\). It's easy to prove that there exists arrays \(b_i\) with such number \(m\).

Code

C. Discrete Acceleration

Let's make a binary search on the answer. If we have some time \(t\) we can calculate the coordinate of each car after \(t\) seconds. Let's define them as \(x_1\) and \(x_2\). If \(x_1≤x_2\) let's move the left bound of the binary search, otherwise, let's move the right bound.

Time complexity: \(O(n \log{\frac{1}{\epsilon}})\).

Code

D. Searchlights

Let's define as \(x\) our move to the right and as \(y\) our move to the up. For all pairs \((i,j)\) of (robber, searchlight) at least one of this should be true: \(x+a_i>c_j\), \(y+b_i>d_j\). So if \(x≤c_j-a_i\) then \(y≥d_j-b_i+1\).

Let's make an array \(r\) of length \(C=106\) and write on each position of \(x\) the minimum value of \(y\). For each \((i,j)\) we should make \(r_x=\max(r_x,d_j-b_i+1)\) for all \(x≤c_j-a_i\). So we have \(nm\) queries of \(\max=\) on prefix. We can do it using suffix maximums. After we will calculate all ax the answer is \(\min\limits_{x}{(x + r_x)}\).

Time complexity: \(O(nm+C)\).

Code

E. Avoid Rainbow Cycles

Let's make a bipartite graph with \(m\) vertices on the left side and \(n\) vertices on the right side.

We will connect vertex \(i\) from the left side with all elements of \(A_i\).

It can be proven, that the graph, which we create using our sets don't have rainbow cycles if and only if our bipartite graph don't have cycles.

So, our task is equivalent of finding the Maximum Spanning Tree of this bipartite graph, where edge between \(i\) (from left side) and \(j\) (from right side) has weight equal to \(a_i+b_j\).

posted @ 2020-10-03 13:13  沸-腾-鱼  阅读(226)  评论(0编辑  收藏  举报