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

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

We invite you to participate in CodeChef’s Starters 156, this Wednesday, 16th October, rated upto 6 stars (i.e. for users with rating < 2500)

Time: 8:00 PM — 10:00 PM IST

Joining us on the problem setting panel are:

Written editorials will be available for all on discuss.codechef.com. Pro users can find the editorials directly on the problem pages after the contest. The video editorials of the problems will be available only to Pro users.

Also, if you have some original and engaging problem ideas, and you’re interested in them being used in CodeChef's contests, you can share them here. Hope to see you participating.

The following is the number of problems in each division :

  • Division 1 : 5 problems
  • Division 2 : 7 problems
  • Division 3 : 7 problems
  • Division 4 : 8 problems

There are no subtasks this time.

Good Luck!

Congratulations to Top 5!

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

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

As a tester with a smol brain, I can guarantee that participating in this contest increases your brain size by $$$10$$$%

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

Contest starts in ~20 Minutes

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

can you please make someone manage the clarification tab, please?

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

I spent 30 mins in contest and solved a variation of D1B (when we want to minimize $$$\Sigma^{n}_{i=1} |B_i-C_i|$$$)...

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

    Are you sure your solution is correct?

    Let's take an example: x = 2, b = 1, 3, 6, 7, 10, 12, 14

    You d array will be -INF, 2, 3, 1, 3, 2, 2, -INF

    If you process the first 3 first, then closest one is the 1 right to it.

    The d array become -INF, 2, 2, 2, 3, 2, 2, -INF.

    Then for the other 3, you need to match with the right -INF and takes 3 operations. 4 in total. The final original array is 1, 3, 5, 7, 9, 11, 13

    But actually, if you process the second 3 first, it only takes 3 operations in total. The final original array is 2, 4, 6, 8, 10, 12, 14

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

      My bad. Now I think we can use the network flow model to solve it.

      Using your example, let's set nodes $$$0$$$ to $$$8$$$, as well as source point $$$S$$$ and sink point $$$T$$$.

      For nodes $$$i$$$ and $$$i+1 (0 \le i \lt 8)$$$, add bidirectional edges with infinite capacity between them. Then connect edges $$$S \overset{\text{capacity=1}}{\rightarrow} 2$$$, $$$S \overset{\text{capacity=1}}{\rightarrow} 4$$$, $$$0 \overset{\text{capacity=INF}}{\rightarrow} T$$$, $$$3 \overset{\text{capacity=1}}{\rightarrow} T$$$ and $$$8 \overset{\text{capacity=INF}}{\rightarrow} T$$$. The cost of all edges is $$$1$$$. This allows us to find the MCMF.

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

    You were not supposed to minimize the sum of differences. rather you had to minimize the maximum difference.

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

How to solve Count Triplets

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

    Imagine that you have two fixed indexes $$$i$$$ and $$$k$$$, such that $$$i \lt k$$$, and you must choose $$$j$$$.

    • If $$$|a_i-a_k| \lt |i-k|$$$ its impossible to choose $$$j$$$, because $$$|i-k| \leq |i-j|+|j-k|$$$.
    • If $$$|a_i-a_k| = |i-k|$$$ we can choose any $$$j$$$ such that $$$i\leq j \leq k$$$.
    • Finally, if $$$|a_i-a_k| \gt |i-k|$$$ we have two options, $$$j \lt i$$$ or $$$k \lt j$$$. The values of the $$$j$$$'s can be found with a simple equation, checking if they can exist, because they can be a real number or out-of-bounds.

    Then we have an $$$O(n^2)$$$ solution, iterate for every pair $$$(i,k)$$$ and add the count of the possible $$$j$$$'s to the answer. For reducing the complexity remember that $$$1\leq a_i \leq 100$$$, so $$$|a_i-a_k| \lt 100$$$. We can iterate with $$$k$$$ being between $$$i-100$$$ and $$$i+100$$$, making the complexity $$$O(200n)$$$.

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

Hi, The editorialist's PYPY code for problem Count Triplets keeps TLEing when I submit it(it checks 200 options for k). I only check for 100 options for k and mine is consistently getting accepted even though it is sometimes very close to the time limit. Maybe next time, will you consider setting a more relaxed time limit for such problems? I think this is the second time recently that something like this has happened the other one being starters 153-(XSQR problem) where someone could possibly figure out all the interesting ideas of a problem and get TLE because of slightly imperfect implementation. I and many others don't want to not be able to solve problems because of reasons like this in future.

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

My alternative, simpler solution for the MAGNET problem:

First, find a chain of length 4 (let's assume it's 1-2-3-4). We only track M1 and M2. Perform the operations in the order 3, 4, 2, 1. After that, use node 1 as the root and perform the operations in non-decreasing order of depth. We can see M1 and M2 will never be merged.