awoo's blog

By awoo, history, 2 years ago, translation, In English

1948A - Special Characters

Idea: BledDest

Tutorial
Solution (Neon)

1948B - Array Fix

Idea: BledDest

Tutorial
Solution (Neon)

1948C - Arrow Path

Idea: BledDest

Tutorial
Solution (Neon)

1948D - Tandem Repeats?

Idea: BledDest

Tutorial
Solution (awoo)

1948E - Clique Partition

Idea: BledDest

Tutorial
Solution (BledDest)

1948F - Rare Coins

Idea: BledDest

Tutorial
Solution (Neon)

1948G - MST with Matching

Idea: BledDest

Tutorial
Solution (BledDest)
  • Vote: I like it
  • +93
  • Vote: I do not like it

| Write comment?
»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In problem B why do we need to iterate through array from right to left and not from left to right?

  • »
    »
    2 years ago, hide # ^ |
    Rev. 4  
    Vote: I like it 0 Vote: I do not like it

    Counterexample:

    1

    3

    12 46 20

    If we will iterate from left to right we will get:

    1) 12 < 46. Don't change the array

    2) 46 > 20. Split 46 by 4 and 6

    And we got:

    12 4 6 20. Which is not a non-growth sorted array.

    If we will iterate from right to left we will get:

    1) 46 > 20. Split 46 by 4 and 6

    2) 12 > 4. Split 12 by 1 and 2

    And we got:

    1 2 4 6 20. Which is a non-growth sorted array.

    Summary, iterating from left to right will give us the wrong answer. This is because the right element can split and become smaller than the left element, but we have already checked that the left element is larger than the right element and will not go back to check it again.

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Suppose initially $$$a_{i-1} \le a_i$$$; but after considering $$$a_i$$$ with $$$a_{i+1}$$$, we find out that we have to split $$$a_i$$$. This might break the condition $$$a_{i-1} \le a_i$$$, so if we iterate from left to right, we sometimes have to backtrack to fix the conditions we've broken

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You can go from left to right also. My logic while going from left to right: https://mirror.codeforces.com/contest/1948/submission/251609551

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I solved the problem by iterating from left to right with following logic: you want current element (CUR which can also be last digit if we divided the number in previous step) to be as small as possible because that can only help for next numbers, so you have two cases: 1) if you CAN divide current element i into it's digits with equality holding: CUR <= dig1 <= dig2 you do so, because then CUR = dig2 which is smallest possible. If you can't, if CUR <= a[i] then CUR = a[i]. If both do not hold, return NO. This works because at any moment, last element you have in your new array will be smallest possible which can only help for both of previously mentioned checks.

»
2 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

In the place of tutorial of G ,it is showing tutorial of F.Update it please.

»
2 years ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

is it possible to solve Div2-D in less than O(n^2)?

»
2 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can someone please explain in solution of problem C. What are ok1 and ok2 actually signifying? How are we taking the indices of ok1 and ok2.

I have been trying to understand for an hour, please help.

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    $$$ok1[i]$$$ and $$$ok2[i]$$$ refer to the second solution from the editorial. If $$$ok[i]$$$ is true, then the $$$i$$$-th diagonal pair of odd cells has at least one arrow to the right ($$$ok1$$$ and $$$ok2$$$ denote different diagonal directions).

    You can instead check every diagonal pair by bruteforcing all pairs of adjacent odd cells.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I thought D was hashes, wasnt able to implement it well tho... The author's solution is kinda weird

  • »
    »
    2 years ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Let me explain my solution of D -- I hope this might be easier to understand.

    First, let's fix the length of a tandem, and call it $$$2d$$$ ($$$d$$$ is the length of each half of the tandem). For each $$$d$$$, we try to find a tandem repeat of length $$$2d$$$, and the answer to the problem is the length of the longest one we could find. Also let's define the length of $$$s$$$ as $$$n = |s|$$$.

    A substring $$$s_l s_{l+1} \cdots s_{l + 2d - 1}$$$ is a tandem repeat if, for all indices $$$i \in \{ l, l+1, \ldots, l+d-1 \}$$$, $$$s_i = s_{i+d}$$$ is held. So, what matters here is the relationship between characters with distance $$$d$$$. With that in mind, let's define an array $$$\{ a_i \} \; (1 \le i \le n - d)$$$ as follows: $$$a_i = 1$$$ if $$$s_i = \text{'?'}$$$ or $$$s_{i+d} = \text{'?'}$$$ or $$$s_i = s_{i+d}$$$; $$$a_i = 0$$$ otherwise. Intuitively, $$$a_i$$$ is $$$1$$$ if $$$s_i$$$ and $$$s_{i+d}$$$ are equal or can be made equal. With this array $$$\{ a_i \}$$$, we can rephrase the condition that $$$s_l s_{l+1} \cdots s_{l + 2d - 1}$$$ can be a tandem repeat to: $$$a_l = a_{l+1} = \cdots = a_{l+d-1} = 1$$$ (selection of $$$\text{'?'}$$$s do not matter because each pair of letters in a tandem do not interfere with any other pairs). Thus, if there is a contiguous sequence of $$$1$$$s of length $$$d$$$ in $$$\{ a_i \}$$$, we have a tandem repeat of length $$$2d$$$; otherwise, there's no such tandem.

    Building $$$\{ a_i \}$$$ and finding contiguous $$$1$$$s can be done in $$$O(n)$$$-time, so $$$O(n^2)$$$-time overall.

»
2 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

"Kruskal's algorithm with DSU might be a bit slower, but can also get accepted"

I don't thinks so :(

»
2 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Problem D (Tandem Repeat) Video Editorial : (Audio : Hindi)

Link : ---Click Here (YOUTUBE)

Problem A, B Video Editorial : --Click Here

»
2 years ago, hide # |
Rev. 4  
Vote: I like it +28 Vote: I do not like it

Here's a formulation of F as a probability problem (mostly because I am in a probability class right now :3).

Suppose we have $$$s$$$ silver coins in the bag, $$$g$$$ gold coins in the bag, $$$t_s$$$ total silver coins and $$$t_g$$$ total gold coins. The value of the silver coins in the bag is represented by the random variable $$$S\sim \mathrm{Binom}(s,\frac{1}{2})$$$. The value of the rest of the silver coins is represented by the random variable $$$S'\sim \mathrm{Binom}(t_s-s,\frac{1}{2})$$$.

We wish to compute

$$$ \mathbb{P}\left(S + g \gt S' + t_g-g\right) = \mathbb{P}\left(S - S' \gt t_g-2g\right). $$$

The difference between random variables isn't nice to compute, so we want to turn it into a sum. Notice that the random variable $$$S' ':= t_s-s-S'$$$ has the same $$$\mathrm{Binom}(t_s-s,\frac{1}{2})$$$ distribution as $$$S'$$$ (this only holds because our probabilities are $$$\frac{1}{2}$$$). Therefore,

$$$ \mathbb{P}\left(S - S' \gt t_g-2g\right) = \mathbb{P}\left(S + S' ' \gt t_s - s +t_g-2g\right). $$$

But the sum of binomial random variables is itself a binomial random variable: $$$S+S' '\sim \mathrm{Binom}(t_s-s+s,\frac{1}{2}) = \mathrm{Binom}(t_s,\frac{1}{2})$$$, which gives us the formula

$$$ \mathbb{P}\left(S + S' ' \gt t_s - s +t_g-2g\right) = \left(\frac{1}{2}\right)^{t_s}\sum_{k=t_s - s +t_g-2g + 1}^{t_s}\binom{t_s}{k}. $$$

Here is my submission implementing this: 251836049.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This n^3 method passed systest. Can anyone hack it?

code

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Video Editorial For Problems A,B,C,D,E,F.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem G is awesome. I cannot put forward Konig's theory because I didn't realize that a tree is a bipartite graph during the contest. Sad.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone please provide the solution of B using DP , I think we can use bit masking to solve this as the value of Dp[i] (whether performing operation on the i'th index will result in a sorted array or not ) depends on the pervious values too , so we can have a mask that denotes on which of the previous indexes we have performed the operation ,Thanks for the help .

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Very fun problems, I like this contest!

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hi, for Problem D, when I run my code locally with the provided testcases I get the correct answer. However, when I submit, I get a different output. Any ideas what's going on? link to submission

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In problem F, why we use pw2 = binpow(binpow(2, MOD - 2), m) but not pw2 = binpow(binpow(2, m), MOD - 2)? I really don't understand it, can anyone explain this for me?

»
23 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Gotta say Tandem repeat taught me here.Good EDU problem

»
19 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I'm curious to know if D could be solved using Z algorithm!!

»
19 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why E has n<=40 if the solution is O(n) ?

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

in B, if we don't check that no. is less than 10 then won't it add 0 to the list also while doing b.push_back(a[i] / 10); which can affect the answer.