Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

Abstract

After I participated in Pinely Round 4 yesterday, my rating dropped down a lot.

BUT, I learnt something useful.

1. Check your initialization — AND Reconstruction

After I solved A in a minute and saw the statement of B, I quickly realized that there's an efficient construction which is simply set $$$a_i=b_i|b_{i-1}$$$. The code is below.

code

Can you recognize what's wrong with the code?

answer

2. It's never guaranteed that former problems are easier than others — Absolute Zero

$$$40$$$ minutes after I submitted the second wrong submission of B, I gave up and came to check C.

And, literally the moment I understood the problem statement, I came up with an efficient solution.

In each of the $$$k$$$ operations, sort $$$a$$$, then set $$$x=\lceil a_1+a_n\rceil$$$. If the legal operation sequence exists, my method always reduce $$$\max(a)-\min(a)$$$ for a half.

So I quickly implemented my method successfully, and got accepted. However, it was already an hour from the beginning, so I lost a lot of points.

3. Think about the probability that you're rickrolled by the problem when you struggled solving it — Prime XOR Coloring

From I solved C to the end of the contest, I struggled solving D because I believed that it was easier to solve D than to solve B (because I didn't find that silly bug). I tried to find a pattern what a legal construction has, but I failed. Because I tried to make every color as small as possible.

However, I forgot that it's not necessary to make every color the smallest. Making the number of colors smallest is enough. And in the editorial, the proposer told us, "Why not try to make all $$$\operatorname{xor}$$$ values of the positions with same color an composite number?"

In fact, the sample given in the problem statements is already a hint. It hints us to think about $$$4$$$. As we know, $$$(4)_{10}=(100)_2$$$. There's only one $$$1$$$ in its binary expression. If we make sure that $$$2$$$ lowest bits of two different positions with a same color are always the same, then their $$$\operatorname{xor}$$$ value is always divisible by $$$4$$$, which is a composite number.

Then, for $$$n\ge 6$$$, we can simply set $$$c_i=i\bmod 4+1$$$.

What a rickrolling problem, but I like it!

4. Maybe the answer resides in the boundary condition — Coloring Game

Since I spent all the rest of the time solving D, I only took a look at E and had no idea.

The statement says Alice chooses two different colors each time. So, in order to decrease the probability of Bob winning, she can only choose two colors all the time.

And in this worst case, Bob is possible to win only when the graph is a bipartite graph, which is able to be colored by only two colors.

So the instruction to win is obvious. If the graph is a bipartite graph, choose Bob, since he can always win with at least $$$2$$$ colors. Otherwise, choose Alice, since only a bipartite graph can be colored by only two colors, and it's impossible for Bob to find a legal coloring.

5. Range queries may not lead to a range data structure such as Segment Tree — Triangle Formation

When I took my first look at this problem, I thought about segment tree. However, it's unnecessary in this problem because the densiest sequence ("densiest" means the smallest maximum value) with no non-degenerate triangle formable is the fibonacci sequence. If you do a simple implementation, you'll discover that the $$$45$$$-th term of that sequence already exceeds $$$10^9$$$. So, under the constraint, a subsequence of $$$a$$$ with a size not less than $$$45$$$ always generates a non-degenerate triangle.

But the problem asks us to make $$$2$$$ non-degenerate triangle. How can we do that? In fact, we can simply add $$$3$$$ more numbers into that sequence. because after we extract one of the non-degenerate triangles, there are still $$$45$$$ elements in it, we can still extract another one.

For those subsequences with less than $$$45$$$ elements? Well, since it's obviously easier to get a non-degenerate triangle with closer elements if we sort that sequence, we can forcefully search all the possible combinations in subintervals in the sorted subsequence with a size of $$$6$$$, or all the consecutive subintervals with no intersections and a size of $$$3$$$.

But, if you do that without optimizations, you will get a TLE.

So how to optimize?

Add break to your code, as many as you can.

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

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

It's good that you are trying to analyse your participation. However, some of the things you say are irrelevant or misguided:

Think about the probability that you're rickrolled by the problem when you struggled solving it

I don't think that you need to separately consider the possibility that the problem tries to rickroll you. You might need to think "can the solution be really simple?", but I don't think it's the same. Also I don't think that problem D was rickrolling you necessarily. The fact that 4 colours are always enough is just normal problem-solving, and the problem would be fine if the answers for all small n including the first one where 4 colours are required were not given in the sample -- one could write bruteforce to solve for small n. But I do think that giving them in the sample makes the problem better and funnier.

It hints us to think about 4. As we know, $$$(4)_{10}=(100)_{2}$$$. There's only one 1 in its binary expression.

How is that relevant to anything?

So the instruction to win is obvious. If the graph is a bipartite graph, choose Bob, since he can always win with at least 2 colors.

Is it obvious? The strategy for Bob is more complex than "just use bicoloring".

Range queries may not lead to a range data structure such as Segment Tree

It is sad to me that this needs saying, but thank you for saying it I guess.

So how to optimize? Add break to your code, as many as you can.

That is not the lesson here. What you need to do instead is to come up with a method for checking for 2 triangles that has a provably good execution time, as in normal problem-solving.

  • »
    »
    2 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

    I would argue D and similar problems "rickroll" you by introducing concepts that give access to a much more complex to navigate search space of ideas (properties of prime numbers) only to use a relatively generic property of the concept that you could also have when substituting with many alternative structures (parity).

    While it's part of problem solving, to me it feels like trick in time constrained contest to introduce complex structure but only be able to solve in time by knowing what properties to extract from it commonly in contest meta.

  • »
    »
    7 недель назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Why do you spell colours if you are not british?

    • »
      »
      »
      7 недель назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Why do you think that American English is the default variant? I might not be British, but I live in London.

      • »
        »
        »
        »
        7 недель назад, # ^ |
          Проголосовать: нравится +4 Проголосовать: не нравится

        Because American English is the most widely used variant of English in the world, and also its the variant in which the great MikeMirzayanov writes posts in.

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

Did the majority of people that solved F know about the Fibonacci sequence and non-degenerate triangles? How much did that help in solving the problem?

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

    the solution is basically 2 parts

    1 — noticing the the query length cant be greater than 50 , with fibonacci sequence and non-degenerate triangles

    2 — coming up with the cases for <=50 length queries

    so yeah ig knowing those helps in noticing the first part fast

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

    Well, no. The Fibonacci sequence provide a tight bound, but honestly you could go a bit more loose and still pass the TL. You only need 1 observation: Let's assume a sorted array $$$a$$$ does not contain any non-degenerate triangle. Now, sort all of the elements in $$$a$$$ and look at three consecutive elements. We observe that $$$2 * a_i \leq a_i + a_{i+1} \leq a_{i+2}$$$. Thus, if $$$|a|$$$ is greater than $$$30 * 2 = 60$$$, it contains a non-degenerate triangle. The same story goes for two non-degenerate triangles, since if you remove $$$3$$$ elements and $$$|a|$$$ is still greater than $$$60$$$, it still contains a triangle. Therefore if the range of a query exceeded $$$63$$$, then the answer is always yes. Matter of fact, I used $$$240$$$, cause I'm a complete idiot (my program runs in 0.8s).