__baozii__'s blog

By __baozii__, history, 7 weeks ago, In English

We hope you enjoyed the problems!

Rate the contest!

2245A - Кто сторожит свиносторожей?

Solution
Code
Rate the problem!

2245B - Удалить и сконкатенировать

Solution
Code
Rate the problem!

2245C - MEXOR

Solution
Code
Rate the problem!

2245D1 - Построение массива (простая версия)

Solution
Code
Rate the problem!

2245D2 - Построение массива (сложная версия)

Solution
Code
Rate the problem!

2245E - Том и Джерри

Solution
Code
Rate the problem!

2245F - Знакомо?

Solution
Code
Rate the problem!

2245G - NPC-челлендж

Solution
Code
Rate the problem!

2245H - Видимые соединения

Solution
Code
Rate the problem!
  • Vote: I like it
  • +118
  • Vote: I do not like it

»
7 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Auto comment: topic has been updated by __baozii__ (previous revision, new revision, compare).

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Fast editorial!

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Sorry my bad i clicked the register button

»
7 weeks ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

wa on tc 17 is basicly AC, can i have points?
Face Image

»
7 weeks ago, hide # |
Rev. 2  
Vote: I like it +30 Vote: I do not like it

The tutorial didn't render correctly, can you fix it please __baozii__?

Edit: maybe the bug is happening only for me

»
7 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Damn D was graph?? never even thought of thinking graph for this.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

C was a good problem despite i couldnt solve it

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Absolutely amazing contest omg fire job

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

weird problems, D1 was fun to solve though

»
7 weeks ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

D was so good

Solved D1 with topological sort, couldn't get D2

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +7 Vote: I do not like it

    For D2, you can do a topological sort similar to D1, but using $$$a_i$$$ and $$$-a_i$$$ rather than $$$|a_i|$$$.

    Since if there exists a solution, there exists one where all values of $$$a_i$$$ and $$$-a_i$$$ are distinct and non-zero, you can build a graph with $$$2n$$$ nodes and each constraint gives some strict inequalities between $$$a_i$$$ and $$$-a_j$$$. Once you get a topological sort, whether $$$a_i$$$ or $$$-a_i$$$ appears first tells you whether $$$a_i$$$ should be positive or negative, and you get a solution.

    Funnily enough this was the way I solved D1 as well.

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

      I got AC with this solution: Compute the topological ordering on this graph, and for each $$$x$$$, print ord[POSITIVE_NODE(x)] - ord[NEGATIVE_NODE(X)]. I wonder if it's correct or just a coincidence.

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

        It is correct. Consider you found a topological order and built the solution.

        If you must satisfy a constraint $$$a_i + a_j \gt 0$$$, then if both are positive, we are good. Otherwise, say $$$a_i \lt 0$$$, then $$$ord[i] \lt ord[-i]$$$, but by construction of the graph, $$$ord[-j] \lt ord[i]$$$ and $$$ord[-i] \lt ord[j]$$$, so $$$ord[-j] \lt ord[i] \lt ord[-i] \lt ord[j]$$$ and we get $$$a_i + a_j \gt 0$$$.

        Similarly, you satisfy constraints $$$a_i + a_j \lt 0$$$ as well.

        Simple but elegant !

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How can C be solved?

I solved it using XOR basis.

what is the easier approach?

  • »
    »
    7 weeks ago, hide # ^ |
    Rev. 4  
    Vote: I like it +6 Vote: I do not like it

    Notice that every sequence f satisfying following conditions is valid:

    • f(i) <= i+1
    • f(i+1) >= f(i)
    • f(n-1) = n
    • 0 <= f(i) <= n

    so you can construct f backward, set f(n-1) = n and place every digit in binary representation of k xor n to f(n-2), f(n-3) and so on, then construct corresponding permutation p.

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

      So, the right way is just constuct k xor n using powers of 2!

      I used harder approach, which using xor basis to find these numbers rather than the power of 2's.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could anyone explain why sorting is used in the official solution for Problem B? The second operation clearly states we can only pick two adjacent elements, which literally refers to elements next to each other in the original array, right? If pairings are restricted to adjacent elements only, sorting the entire array and rearranging its order should not be valid at all. Is there a misunderstanding of the problem statement here?

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

    You can consider it as having some 'negative' numbers (which you want to pair), and some 'positive' which you don't mind pairing. As long as there are at least one of each kind, you can also find an adjacent pair of such as well -- therefore, you don't need to care about their ordering but just about their count(s).

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

    Yes you can only do adjacent pairings. However, you can always construct an order of operations such that you can use the bigger half of the elements as the max. Imagine marking every element as 1 if it's in the bigger half of the elements, and 0 otherwise. No matter what, there is always a 1 next to a zero, and we can remove both.So you can always achieve using the biggest half of the array.

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it -10 Vote: I do not like it

    Suppose you mark some elements as 0 and others as 1, and declare that each paired operation removes exactly one of 0 and 1. Then as long as 1 <= number of 0s <= number of 1s, you can always find an adjacent pair regardless of order.

»
7 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Solved D1 1 minute after contest :<( bruuh

ConstructiveForces

»
7 weeks ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

D1 can be solved in really stupid ways (like sorting by number of non-negative sums) that don't generalise well for D2. I'm surprised the points' split was so much in favour of D1.

»
7 weeks ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

guessforces

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by __baozii__ (previous revision, new revision, compare).

»
7 weeks ago, hide # |
 
Vote: I like it -69 Vote: I do not like it

Propose multiple constructions and pure-guess problems won't make your reputation be more positive.

Sincerely to every author who have the very bottom-line sympathy to participants.

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +93 Vote: I do not like it

    Do I propose contests to make my reputation more positive? I author problems because I love authoring problems. I want to share them to the community.

    Simply because problems C and D are constructive or problem B is greedy does not make the contest "multiple constructions and pure-guess problems". Is your definition of competitive programming purely data structures?

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

      I suspect that MaxBlazeIceInk (as well as I) doesn't like the variance that increases with tasks like C or D.

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

    Hug you,my honey,MaxBlazeIceInk,Hope your journey in the algorithm competition goes smoothly.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

guessforces

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What's the purpose of setting memory limit of problem F to 128 mb? don't think there's much difference, since it only prevent using int[500][500][500].

Also O(n^4) solution can actually pass.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Was a massive fan of problem A!

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Did anyone else solve B this way?

if i take two elements say , a,b then its either max(a,b)-c or a+b-2c so given that max(a,b)-c>a+b-2c has to satisfy,then c must be greater than the min of the both, so all the values smaller than c must be somewhere matched with greater than c , so it will pair up and so on and did some other proofs to get to the final sol.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hell, I think the solution to G seems pretty AI-generated.

»
7 weeks ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Could someone explain the proof of the lemma in D1 in more detail? I didn`t understand it

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    The point they're trying to make is that $$$\lvert a_i \rvert = \lvert a_j \rvert$$$ for $$$i \neq j$$$ can always be avoided.

    An easier way to show this is to bend the rules of the problem a bit and allow for decimals. Suppose that for some valid solution $$$a$$$, we have $$$\lvert a_i \rvert = \lvert a_j \rvert$$$ for $$$i \neq j$$$. Simply add $$$0.1$$$ to $$$a_i$$$. This will keep all non-negative restrictions sound as the sum increases, and no negative restrictions will be broken as $$$0.1$$$ is not enough of a change to go from a negative integer to a non-negative integer.

    Since there's an infinite number of decimals between any two integers, we have plenty of freedom in selecting small offests to satisfy all of the conditions.

    Now just convince yourself that these decimal values could in fact be scaled up to integers with the correct power of 10.

    The editorial follows this idea, but uses carefully chosen integer offsets instead.

»
7 weeks ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

Thank you for the wonderful contest!

»
7 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Alternate solution to C with no casework on K:

If the MSB of $$$(k\oplus n)$$$ is greater than the MSB of $$$(n-1)$$$, then no possible permutation can make the MSB of $$$(k\oplus n)$$$ appear in the final xorsum, so the answer is no.

Otherwise, consider the binary representation of $$$(k\oplus n)$$$. If the $$$i$$$-th bit from the left of $$$(k\oplus n)$$$ is set, mark $$$2^{i-1}$$$ as a "used element". Additionally mark $$$0$$$ as a used element. Then, output all the non-used elements, then the used elements in order.

»
7 weeks ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

D2 and E are really good problems, enjoyed them so much.

»
7 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

This round will always be special for me.. it got me to Pupil! Huge thanks to __baozii__ for such a wonderful set of problems...

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

nice contest, loved D2 and E <3

»
7 weeks ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

The D2 of doom and despair.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone please explain in detail how to solve B?

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

    First, subtract $$$c$$$ from each $$$A_i$$$. Suppose there are now $$$a$$$ nonnegative numbers and $$$n-a$$$ negative numbers.

    We consider two cases. If $$$a \ge n-a$$$, then there must be a nonnegative number adjacent to a negative number. We can delete the pair and obtain a nonnegative contribution. In the end, we can always collect all nonnegative contributions, so we only need to calculate the sum of all nonnegative numbers.

    Now consider $$$a \lt n-a$$$. We are inevitably forced to include some negative numbers. We reduce this case to the previous one. First, we delete some negative numbers and take their contributions. If we delete $$$k$$$ negative numbers, then we need

    $$$ a+k \ge n-a-k, $$$

    so

    $$$ k \ge \left\lceil \frac{n-2a}{2} \right\rceil. $$$

    Therefore, we take all nonnegative numbers together with the $$$k$$$ largest negative numbers, which solves the problem.

    Translated by ChatGPT

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

    The goal is to maximize the sum. Therefore, we keep all elements $$$a_i$$$ such that $$$a_i \ge c$$$ and try to eliminate as many elements with $$$a_i \lt c$$$ as possible.

    It is easy to see that any element $$$a_i \lt c$$$ can be eliminated by pairing it with an element $$$a_j \ge c$$$. Therefore, if there are $$$k$$$ elements satisfying $$$a_i \ge c$$$, we can eliminate up to $$$k$$$ elements satisfying $$$a_i \lt c$$$.

    After doing so, some elements with $$$a_i \lt c$$$ may still remain. These remaining elements can only be paired among themselves, which means that at most half of them will contribute to the final sum.

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

      actually the main confusion in the solution and the problem statement is that, in the problem statement they say to remove elements in pair which are adjacent, but in the solution somehow the order doesn't matter.

      This is not at all intuitive. Even I'm not able to understand this.

      • »
        »
        »
        »
        7 weeks ago, hide # ^ |
         
        Vote: I like it +1 Vote: I do not like it

        Try viewing the sequence as a binary sequence, where $$$1$$$ means that we want to include the corresponding number, while $$$0$$$ means that we want to delete it.

        As long as both $$$1$$$ and $$$0$$$ remain, there must be an adjacent pair consisting of a $$$1$$$ and a $$$0$$$. Removing this pair is equivalent to applying the second operation. Repeating this process eventually leaves only some $1$s, which can then be removed using the first operation.

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

      But what about the order of the elements,it is mentioned in the question that we have to take only the adjacent elements.Why we are not taking that into account?

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

        The order of the elements does not matter at all.

        Consider the version of the problem where $$$c=0$$$. Suppose there are $$$k$$$ positive elements, where $$$2k \gt n$$$. You want to include all of these positive elements into your answer.

        As long as there are both positive and negative elements inside the array, you are guaranteed to have an adjacent pair of positive and negative elements. We are not removing an arbitrary positive element and an arbitrary negative element. It is just there must exist an adjacent pair.

»
7 weeks ago, hide # |
Rev. 4  
Vote: I like it +12 Vote: I do not like it

Reduce D to 2-SAT:

Let true represent positive and false represent negative. For each $$$i$$$, $$$j$$$, if $$$o = 1$$$ then at least one of $$$i$$$ or $$$j$$$ needs to be positive, so add a $$$i \lor j$$$ clause, and similarly if $$$o = 2$$$ then at least one of $$$i$$$ or $$$j$$$ needs to be negative, so add a $$$\lnot i \lor \lnot j$$$ clause. Then if this formula is satisfiable we have the signs and can do the topological sort on $$$|a_i|$$$.

The solution is effectively the implication graph of 2-SAT anyways, but this was a nice way for me to overcomplicate the problem and forget how my 2-SAT template works and then not get it correct until 20 seconds after the contest ended.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

F drove me crazy!

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by __baozii__ (previous revision, new revision, compare).

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I often recall the past.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Implemented Recursion on B and got MLE TwT

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Waiting for H, as always!

»
7 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

this is the most beautiful and fun contest i've participated in so far

thanks for the great problems

»
7 weeks ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

Best round I've ever seen

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Please someone explain solution for $$$B$$$ and $$$C$$$ in easy language. I can't understand the editorial solution.

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    I have a rather easy C solution, it's pure implementation Notice at the end, when you have made the complete array, the last Mex will be N. Say you have a target T, given to you in problem, there will be set of bits set in N say nb1,nb2... Similarly you will have some bits set in T say tb1, tb2..etc The idea is if there are bit position set in both n and t, then we don't have to make that mex, the last mex will be sufficient to produce that, but if a bit is set in any one of n or t, then we need to generate mex either to set that particular bit in result or to remove that bit from result using xor.Initially our result was N,then we do these operation, basically we add power of 2 for bit position with xor = 1, then append it to array, then in reverse order all the remaining elements from 0 to n — 1, then we need to check if all the elements are less than n, if they are, then answer is Yes, return the reverse of this array, if not then NO permutation will exist.

  • »
    »
    7 weeks ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    Here is my approach.

    Let $$$x = k \oplus n$$$

    Observe that $$$f(n - 1) = n$$$. Therefore, we need $$$f(0) \oplus f(1) \oplus \cdots \oplus f(n - 2) = x$$$.

    Another important observation is that the position of $$$0$$$ in the permutation matters. If $$$a_i = 0$$$, then $$$f(0) = f(1) = \cdots = f(i - 1) = 0$$$ and $$$f(i) = \text{minimum value on the right of 0}$$$.

    Thus, our task reduces to constructing some values whose XOR is equal to $$$x$$$.

    Let $$$a = \text{the most significant bit of } x$$$, $$$b = a \oplus x$$$. Since $$$a \oplus b = x$$$, we can place the last three elements of the permutation as:

    $$$ 0,\ b,\ a. $$$

    All remaining numbers can be placed to the left of $$$0$$$ in any order. Then the XOR of the corresponding values will be exactly $$$k$$$.

    Of course, there are several edge cases that must be handled separately.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In problem D2,can someone please explain why the editorial reverses t and the signs(-1 for d0=0,1 for d1=0) before assigning values? Why cant I assign a positive value if d[0]=0 and a negative value if d[1]=0 and increase the value for the next one?

  • »
    »
    7 weeks ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    d[0][i]==0 that actually means that every j in which a[i]+a[j]>=0 is eliminated and there is all available j which gives a[i]+a[j]<0 .. so we are putting larger negative value sequentially for every this kind of i in which d[0][i]==0 and same logic goes ford[1][i]==0,we will put larger positive value sequentially...so at last the last elements of the order(here it is t) will get smallest value according with sign and first element will get largest elements....so we will start putting large to small if we do not pretend to reverse the order list....if you reverse order list,, it is easy to put values 0 to n-1 according its sign...

»
7 weeks ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it

I had a different approach for D2, worth checking out :

Instead of dealing with negative numbers, let's pretend a_i and -a_i are independent variables. For every number 1 to n, create a graph with 2N nodes: Node P_i represents +a_i Node N_i represents -a_i

In graph theory, an inequality Y >= X + W is modeled as a directed edge X -> Y with weight W. Let's rearrange our given constraints to match this format:

Type 1 (a_i + a_j >= 0): Rearranging gives a_i >= -a_j. In our nodes: P_i >= N_j + 0. Add edges N_j -> P_i and N_i -> P_j with weight 0.

Type 2 (a_i + a_j < 0): Rearranging gives -a_i > a_j, which means -a_i >= a_j + 1. In our nodes: N_i >= P_j + 1. Add edges P_j -> N_i and P_i -> N_j with weight 1.

Notice that weight-0 edges always go N -> P, and weight-1 edges always go P -> N. The graph is perfectly bipartite. This means there are no 0-weight cycles. If topological sort detects any cycle, it's a contradiction ( solution isn't possible ).

Initialize all nodes with in_degree == 0 to a value of 0. Run Kahn's Algorithm (Topological Sort) to compute the longest path (val) to every node. val[nxt] = max(val[nxt], val[curr] + weight). If the number of processed nodes is != 2N, a cycle exists.

If it's a DAG, the final answer for each element is simply the difference between its positive and negative "pressures": a_i = val[P_i] — val[N_i] For a Type 2 constraint : a_i + a_j < 0 --> Our graph has edges P_i -> N_j (weight 1) and P_j -> N_i (weight 1). By the definition of longest paths, this guarantees: val[N_j] — val[P_i] >= 1 and val[N_i] — val[P_j] >= 1 Now plug our formula into the sum: a_i + a_j = (val[P_i] — val[N_i]) + (val[P_j] — val[N_j])

a_i + a_j = -(val[N_j] — val[P_i]) — (val[N_i] — val[P_j]) <= -2

Similarly, it can be proved for Type 1 constraint.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thank you for your great tutorial!

»
7 weeks ago, hide # |
 
Vote: I like it -16 Vote: I do not like it

Dear codeforces

I got a message ragarding accusation for plag --> Attention! Your solution 383003288 for the problem 2245D1 significantly coincides with solutions Jashnoor_gill/382990901, Samsaara/383003288. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://codeforces.me/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked.

I dont know this other user i know there are some same variables used but that is actually common for this tarjans algorithm. I commonly used variables like these in my codes as you can check. Also i confirm i wrote this code by myself and there are many differences between our implementation again based on variable names and my code being without use of structures. I beg you to look into this case as it actually breaks the morale of a user. I can explain the solution based on 2 SAT and tarjan algorithm and had faced similar problems even before.I know that some flow of the implementation looks similar but it is actually instinct to look for this type of logic when facing problem like that.

I understand and respect Codeforces efforts to maintain fair competition, which is why this warning was very discouraging to receive. I have always tried to solve problems honestly, and being accused of plagiarism despite writing the solution myself has been quite upsetting and dissappointing.

please ignore spelling mistakes samsaara

»
7 weeks ago, hide # |
 
Vote: I like it -11 Vote: I do not like it

I solved this problem completely on my own during the contest. I did not discuss the problem with anyone, share my code, or look at anyone else's solution. I also did not use any public IDEs or paste sites.

The solution itself is very short and follows the most direct approach: subtract c from every element, sort in descending order, take the first (n+1)/2 elements, and then add the remaining positive ones. Because of this, I think it's natural for independent solutions to look similar.

My submission and the other one also have several differences. I use my own minimal template in VS Code, while the other submission uses a large competitive programming template with debug utilities, different macros, variable names, and formatting.

I write all my code locally in VS Code. I'm happy to email my rough work that can help verify that I solved the problem independently.

I would really appreciate it if my submission could be reviewed manually.

»
7 weeks ago, hide # |
Rev. 2  
Vote: I like it -22 Vote: I do not like it

2 years and I still can't consistently solve 4 problems in div2 :(

»
6 weeks ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

Hey so this is a human solve for H __baozii__ 383620870

»
6 weeks ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it

Late reply, but I have been mulling over 2245D2 - Construct an Array (Hard Version) and I think the editorial skips over a crucial part of the proof, which I want to cover.

(Also the bit about replacing “nonnegative” with “positive” in the editorial is unnecessary.)

Let me recap. From the solution to D1, we know

D1

Then for problem D2 we can construct a recursive solution:

D2

This last part is not proven in the editorial. I will prove it by contradiction.

proof
»
6 weeks ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

I'm under the impression that 384018980 is a human solution.

»
5 weeks ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Since maspy has already solved H, could you please add the tutorial for it, __baozii__? Thanks!

»
5 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I will leave a brief hint for Problem H.

  • There are only $$$O(N^2M)$$$ pairs that are reachable by a pattern other than (col, row, col), so all of them can be enumerated.
  • It is enough to do the following:
  • For the enumerated pairs, subtract those that are also reachable by a (col, row, col) pattern.

  • Add all pairs that are reachable by a (col, row, col) pattern.

For the (col, row, col) pattern, suppose that, for a fixed pair, the possible rows are $$$r_0,r_1,\ldots,r_n$$$. Then the number of such pairs can be counted by adding +1 for each $$$r_i$$$, and -1 for each pairs $$$r_i,r_{i+1}$$$.

An $$$O(N^2M)$$$ time solution is relatively straightforward, but some care is probably needed to keep both the constant factor and the memory usage under control.