Блог пользователя MyBrainGotTLE

Автор MyBrainGotTLE, история, 3 месяца назад, По-английски
Disclaimer

2241A - Divide and Conquer

Let $$${z_1, z_2, z_3, ..., z_k}$$$ be the values of $$$z$$$ in the operations to transform $$$x$$$ into $$$y$$$. $$$\newline$$$ The resulting x after the operations is: $$$\dfrac{x}{\displaystyle\prod^{k}_{i=1} z_i}$$$

In other words, we have $$$y = \dfrac{x}{\displaystyle\prod^{k}_{i=1} z_i}$$$

Or $$$\displaystyle\prod^{k}_{i=1} z_i = \dfrac{x}{y}$$$.

Since $$$\displaystyle\prod^{k}_{i=1} z_i$$$ is an integer, $$$\dfrac{x}{y}$$$ must also be an integer, so the answer is YES if $$$x$$$ is divisible by $$$y$$$ and NO otherwise

Time complexity: $$$O(1)$$$ per testcase

Code

2241B - Good times Good times

Before we find the answer, express $$$concat(n, n)$$$ (where concat(x, y) means concatenating $$$x$$$ and $$$y$$$ together) in terms of $$$n$$$

Answer

We know that $$$10^{d(n)} + 1$$$ is a good number since it only contains 0 and 1, and $$$concat(n, n)$$$ is a good number since n is a good number, so we need to output $$$10^{d(n)} + 1$$$. We do not need to worry about the bounds since $$$d(n) \le 8$$$

Time complexity: $$$O(d(n))$$$ per testcase

Code

2241C - RemovevomeR

First, let's prove that the answer does not exceed 2

Consider a binary string $$$s$$$ of length $$$n \ge 3$$$.

  • If there are 2 consecutive equal characters, they form a palindrome

  • Otherwise, $$$s$$$ must be of the form $$$01010101...$$$ or $$$10101010...$$$. Then $$$010$$$ and $$$101$$$ form palindromes.

So we can always decrease the size of a binary string with length at least 3

Now let's see in which cases is the answer equal to 2. $$$\newline$$$ In fact, the answer is equal to 2 when there exists exactly 1 index $$$i$$$ such that $$$1 \le i \le n - 1$$$ and $$$s_i \ne s_{i + 1}$$$

This can be proven by combining consecutive equal characters into blocks.

  • If there are exactly 2 blocks, they cannot be combined together, thus resulting in a final length of 2.

  • Otherwise, operations can be performed to turn a block into a single character with the corresponding value. The leftover string will have alternating 1s and 0s, so we can keep removing characters until there is only 1 character left.

Time complexity: $$$O(n)$$$ per testcase

Code

2241D - An Alternative Way

There are 2 observations we need to make in this problem:

  1. We do not need to care cases where $$$a_i \le b_i$$$ since we can perform an operation where $$$l = r = i$$$ a total of $$$b_i - a_i$$$ times

  2. When we want to decrease $$$a_i$$$, we have to increase $$$a_{i - 1}$$$. This leads to the fact that we cannot decrease the first element

From these 2 observations, we can form a strategy as follows:

Traverse the array backwards and for each $$$i$$$ such that $$$2 \le i \le n$$$ and $$$a_i \gt b_i$$$, we decrease $$$a_i$$$ by $$$a_i - b_i$$$ and increase $$$a_{i - 1}$$$ by $$$a_i - b_i$$$ $$$\newline$$$ Finally, if $$$a_1 \le b_1$$$ output YES, otherwise output NO

Time complexity: $$$O(n)$$$ per testcase

Note: For the sake of simplicity, the decrease of $$$a_i$$$ has been omitted in the following implementation

Code
  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

this contest was another level. crazy times

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

im VERY EXCITED of prob B!!!

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Ah. That's a quick reduction on C. Should have thought of that LOL.

The way I worked it was if you have a substring that's 0...0 or 1...1 then you're guaranteed to be able to reduce this to 0 or 1 respectively since you're guaranteed to have a palindrome recursively inside the ...

So it then becomes checking if, the first position of the longest 0...0 or 1...1 string is either index 0 or able to eliminate the ones/zeroes ahead of it AND if the last position of the longest 0...0 or 1...1 string is either index n-1 or you're able to eliminate the ones/zeroes behind it.

Still O(n) but your method's definitely faster.

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

On problem B you can't exactly put 100000001 on every test case... I thought of that during the contest and it failed. The reason that this strategy doesn't work is because that if you have lets say "67" for x, then 67*100000001 will be 67000000067, which contains three different digits — 0, 6, and 7, which would fail.