Tuesday, November 23, 2021
$\Omega(nk/\log{n})$ lower bound for $k$-gossip
Friday, November 12, 2021
First proper Codeforces round
This was my first Codeforces round (Div2 754) where I competed live. It was very fun and I solved the first three problems. My main issue was not the actual solutions but mainly the implementations. I spent more time debugging than thinking which was a bit of a pain since I just wanted to get on with the harder problems. I'm going to give brief solutions for the first three problems.
Problem A: You are given three positive integers $a_1, a_2$ and $a_3$ and a function $d(a_1, a_2, a_3) = |a_1 + a_3 -2\cdot a_2|$. We can pick any two of the three numbers and add $1$ to one of them and subtract $1$ from the the other. The problem asks for the minimum value of $d(a_1, a_2, a_3)$ that can be achieved given the allowed move.
The idea is that we can only increase/decrease $d(a_1, a_2, a_3)$ by $3$. So we just need to see what $a_1+a_3-2\cdot a_3$ mod $3$ is and this is our answer.
Problem B: We are given a binary string $b$ of length $n$. To do this we are allowed to do the following two things which counts as one move:
- Choose a subsequence of any length such that the elements are in non-increasing order.
- Reverse the chosen subsequence.
- Substring has length $\geq 2$.
- $a$ occurs strictly more times than $b$.
- $a$ occurs strictly more times than $c$.
- $\{u,v\}$ is an edge,
- $v$ has not already been visited, and
- $u\oplus v \leq \min(u,v)$.
Sunday, November 7, 2021
$\Omega(n^{2/3}/k^{1/3})$ smoothed lower bound for flooding.
In the static flooding problem, we are given a graph $G=(V,E)$ and one node $v\in V$ wants to dissipate some information to all other nodes in $G$. We consider this problem in the distributed dynamic setting.
It is known that flooding requires $\Omega(n)$ rounds to complete in static graphs (consider the line graph). But we can parameterize this by the static graph diameter $D$ instead since most graphs have $n\geq D$. In this case we need $\Theta(D)$ rounds.
However, in the dynamic graph setting we can construct a graph $\mathcal{G}$ where the diameter is constant, but we still require $\Omega(n)$ rounds for flooding to complete. So we can no longer parameterize the round complexity in terms of $D$.
We will aim to give a smoothed lower bound for flooding, where the proof presented here is taken from [Din+15].
Section 1: The spooling graph.
We want a dynamic graph where even though the diameter is constant, flooding requires $\Omega(n)$ rounds to complete. Such a graph is called the spooling graph.
For $1\leq r\leq n-1$, the $r$-spooling graph is a graph consisting of a left star of nodes $\{1, ..., r\}$ centered at $r$ and a second right star of nodes $\{r+1, ..., n\}$ centered around $r+1$ with the edge $\{r, r+1\}$ connecting the two stars. Clearly this graph has constant diameter $3$ across rounds.
Consider the case where node $1$ starts with the message to be flooded. Then we need $\Omega(n)$ rounds for flooding to complete since only one node learns the message per round.
- $v$ is numbered $r+1$ and will therefore learn the message from the node numbered $r$,
- there is a smoothed edge between some node in the left star and $v$ in the right star,
- $r+1$ knows the message and $v$ is in the right star.
Saturday, November 6, 2021
Just a cool theorem about monotonic subequences.
- Either $n_i \leq n_j$, or
- $n_i\geq n_j$.
Properties of Smoothed Connected Graphs
Thursday, November 4, 2021
CEOI 2020: Fancy fence
Problem statement:
Everybody knows that Balázs has the fanciest fence in the whole town. It’s built up from $N$ fancy sections. The sections are rectangles standing closely next to each other on the ground. The $i^{\text{th}}$ section has integer height $h_i$ and integer width $w_i$ . We are looking for fancy rectangles on this fancy fence. A rectangle is fancy if:
- its sides are either horizontal or vertical and have integer lengths
- the distance between the rectangle and the ground is integer
- the distance between the rectangle and the left side of the first section is integer
- it’s lying completely on sections
Input: The first line contains $N$, the number of sections. The second line contains $N$ space-separated integers, the $i^{\text{th}}$ number is $h_i$ . The third line contains $N$ space-separated integers, the $i^{\text{th}}$ number is $w_i$.
Constraints:
$1 \leq N \leq 10^5$
$1 \leq h_i, wi \leq 10^9$
Time limit: 0.1 s
Memory limit: 32 MiB
My approach:
It seems reasonable to first figure out how many fancy rectangles an $h_i\times w_i$ fancy section has. If we draw an $h_i\times w_i$ rectangle as follows.
Each square is $1\times 1$ and the purple lines indicate the separation between consecutive fancy sections. Let $W=w_1+w_2+...+w_N$. Notice $F(h_2, W-w_1)$ counts all fancy rectangles counted by $F(h_1, W)$ except the rectangles that start in the first fancy section. We use this to get an answer for when $h_i<h_{i+1}$.
$$\sum_{i=1}^{N}{F(h_i, W-w_{i-1})-F(h_{i-1}, W-w_{i-1})}$$
where $w_0=h_0=0$. But what about the general case where we are not given that $h_i<h_{i+1}$?
Sunday, October 31, 2021
My thoughts on ICPC UK problem D
We are given an array $a_1, a_2, ..., a_n$ where $-10^9\leq a_i\leq 10^9$ and $2\leq n\leq 3000$ and we want to compute the value of the maximum subsequence of this array such that the subsequence has gaps of non-increasing sizes between the positions of consecutive subsequence elements in the array. We call this condition $C$ for short.
The first thing that jumps to mind is to use dynamic programming. We can define $\text{dp}[i, l]$ to be the maximum subsequence ending at $a_i$ which satisfies $C$ where the previous subsequence element is at $i-l$.
Our base case is
$$\forall 1\leq l<n : \text{dp}[1, l] = a_1$$
then our transition function is
$$\text{dp}[i, l] = \max_{l\leq l' \text{ and } i-l-l' \geq 1}\{\text{dp}[i-l, l']\} + a_i$$
since if we arrive at $a_i$ with the last jump having length $l$, we know that we must have arrived from $a_{i-l}$ where we arrived to that with $l'\geq l$. In the above transition equation, we assume that $i>l$ otherwise $\text{dp}[i, l] = -\text{INF}$ since the jump of length $l$ would longer than possible.
However, a straightforward implementation yields an $O(n^3)$ solution which is too slow. We are looking for $O(n^2)$ or better. Although in the contest I did not find anything better.
AtCoder shananigans
Here is the problem , and below is the raw transcript of my thoughts. Obs: It is always optimal to use all $K$ moves. intuitive proof. While...
-
We are given $N$ cities on an integer number line at positions $0<x_1<x_2<...<x_N$, where our capital is initially at position 0...
-
The problem is essentially, given $2\leq n\leq 10^5$ people, where the $i^{\text{th}}$ person has a skill level of $b_i$ in billiards and $p...
-
We are given a permutation of $1,2,...,n$, $a_1, a_2, ..., a_n$. Construct the undirected graph with vertex set $1, 2, ..., n$ and $(i, j)$ ...