harshith_04's blog

By harshith_04, 11 months ago, In English

Thanks for participating in our CodeNite 2025.

2120A — Square of Rectangles

Idea: Dragmon Solution: Dragmon Prepared by: Dragmon

Hint
Solution
Code - aryansanghi
Code - harshith_04

2120B — Square Pool

Idea: harshith_04, Dragmon Solution: harshith_04, Dragmon Prepared by: harshith_04

Hint 1
Hint 2
Solution
Code - harshith_04

2120C — Divine Tree

Idea: harshith_04 Solution: harshith_04 Prepared by: harshith_04

Hint
Solution
Code - harshith_04

2120D — Matrix Game

Idea: Dragmon Solution: Dragmon Prepared by: Dragmon

Hint
Solution
Code - aryansanghi
Code - Starsilk

2120E — Lanes of Cars

Idea: Dragmon Solution: Dragmon Prepared by: picramide, Dragmon

Hint 1
Hint 2
Solution
Code - aryansanghi
Code - ugly2333

2120F — Superb Graphs

Idea: Dragmon Solution: Dragmon Prepared by: picramide, Dragmon

Hint 1
Hint 2
Solution
Code - picramide
Bonus problem

2120G — Eulerian Line Graph

Idea: Dragmon Solution: Dragmon Prepared by: Dragmon

Hint 1
Hint 2
Hint 3
Solution
Code - aryansanghi
Code - ugly2333

The removed problem was supposed to be G in the Div. 1 + Div. 2, the same problem exists and is available here.

Solution
Code O(n) - harshith_04
Code O(n*logn) - IceKnight1093
Bonus for those who haven't seen the Solution
  • Vote: I like it
  • -232
  • Vote: I do not like it

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

3000₹ for this

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

.

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

Fast tutorial

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

There are lots of "Unable to parse markup [type=CF_MATHJAX]", which is giving me a hard time reading the editorial, hope the authors fix this.

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

is it still a rated round??

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

harshith_04 seeing parsing errors in solutions, please fix them.

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

so many Unable to parse markup [type=CF_MATHJAX]

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

I found a very simple pattern for C during the contest, the answer will be simply the m-n th iteration of bubble sort on 1 2 3....n, but couldnt manage to find a way to get to that in less than O(n^2).

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

So why there are lots of Unable to parse markup [type=CF_MATHJAX]?

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

me very happy to read the editorial... meanwhile

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

    This is a CF issue ig, it loads perfectly for me. Try refreshing and maybe open in private window can help.

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

      you are right ... thank you!!!

      I tried opening in incognito and I can read the math stuff.. maybe I have installed some extension which is messing up

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

Yes, the diagrams in problem B were very cute and also very helpful... it saved my time from drawing on my own notebook .. thanks for the effort

»
11 months ago, hide # |
 
Vote: I like it +42 Vote: I do not like it
  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it +47 Vote: I do not like it

    We were given the aformentioned problem as reference by our coordinator so that I can define line graphs and such. Regarding similarity, they are not similar at all, they just both use concept of line graphs. You can try to solve them both and see for yourself. The pic is same because I took screeonshot of their pic and added it to the problem as it is already available in wikipedia and it is great for illustrating the line graph concept.

    • »
      »
      »
      11 months ago, hide # ^ |
       
      Vote: I like it +9 Vote: I do not like it

      No, it's ok

      Maybe I should've said "G reminded me of this problem ..."

      Regarding the pic it was more like "Hold up, wait a minute" thing

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

in D,

when calculation permutations of n, doing nCa considers the remaining elements alike but why so?

why not

n! / [ (a — 1)!^(k — 1) * a! ]

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

    there exists a value v which would appear at least 'a' times, now for the tuple, the number of possible values of v are k. Independently, the number of positions at which the value v would appear is a, we can choose any 'a' positions out of a total of n positions(size of row), choosing 'a' distinct objects out of n distinct objects is nCa.

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

In C problem, isn't it cur += i instead of cur += i + 1?

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

    Why is no one pointing this out!! We add i to check and add i+1 to cur. Also it gives WA. Also why are we looping on j?

»
11 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

Can someone tell me why does Greedy approach doesn't work in Problem E

325545303

I used a MultiSet and find the no of lane changes x between the Longest queue and shortest queue for which the reduction in angriness is maximum. And, I kept doing it until angriness can't be reduced.

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

solution for D is quite pretty

»
11 months ago, hide # |
Rev. 3  
Vote: I like it +21 Vote: I do not like it

"Unable to parse markup [type=CF_MATHJAX]"

What is Mike doing

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

Can you give some more detailed prove about G? I feel like the first two cases of Euler path is only giving conclusions. Maybe my mind is literally not working idk.

And I feel like this whole problem is solved by guessing all the cases for a participant, I(and many ppl imo) didn't pass because not finding out the first two cases of Euler path exists, and finding these two cases is the only difficulty in this problem imo. I thought of the first case might happen at last, but failed to find a case for it, so I went to bed because I'm so sleepy XD

In short I don't think this problem fits a Div1+2 H. I'm glad it got changed to a div2.

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it +15 Vote: I do not like it

    The cases were found by doing rigourous case analysis of L^2(G) then L(G) then G. The proof is quite long and convoluted to put in the blog, so I didn't give the proof.

    Proof idea

    Regarding the problem difficulty, the LGM testers were the only ones to give their feedback, and everyone agreed it is fit for a Div1+2 H. So, that was the reasoning to put it there. But, I do respect your feedback!

    • »
      »
      »
      11 months ago, hide # ^ |
       
      Vote: I like it +13 Vote: I do not like it

      Well I seems to understand the method. For me when in contest, I got though the first part of the solution and the third part of Euler path(mostly by seeing the third sample case) pretty fast, which suprised me'caues the position of the problem. maybe it's because I've seen a problem with the same transform method as defination.

      imo this problem will have lot more solvers if the sample contains all cases, maybe that's why I feel it's not that hard, but with the sample now it's still hard to figure out the missing cases. Maybe it's just my personal preference, I think cp should be a game of finding solutions, not the cases to solve, maybe it's because i suffered from it a few times in AGC and lose some rating.

      I think over the prove for a while and participated in the ARC afterwards, so I write this reply so late. I checked the other problems, I hadn't check tutorial yet, but find it quite challenging, I do appreciate the problems and hardwork from you guys anyway!

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

      Not sure if I'm misunderstanding something — is the claim in Euler path case 1 actually correct? Here, $$$G$$$ doesn't have an Euler tour, $$$L(G)$$$ does, and there is a graph $$$H$$$ such that $$$G=L^2(H)$$$.

      Spoiler
      • »
        »
        »
        »
        11 months ago, hide # ^ |
         
        Vote: I like it +18 Vote: I do not like it

        Under the context of the problem statement, initial graph G always has an euler tour. Here, L^-2(G) doesn't have an Euler tour, so it can't be the input graph, and there is no L^-3(G) or lesser graphs that we care about. So, we don't mind that case.

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

          I agree with this comment, but the way the editorial is currently phrased is misleading at best (it never says that $$$H$$$ has to have an Euler trail, and even if $$$H$$$ doesn't have an Euler trail, what if $$$L^{-k}(H)$$$ exists and has an Euler trail for some $$$k \gt 0$$$?).

          And it seems like it is missing from your case analysis.

          • »
            »
            »
            »
            »
            »
            11 months ago, hide # ^ |
            Rev. 2  
            Vote: I like it +18 Vote: I do not like it

            I do agree with the misleading part, I'll try to rephrase it better. Regarding case analysis, it did get accounted in it . The only case where $$$G$$$ doesn't have line graph but $$$L(G)$$$ does, only way for $$$G=L^2(H)$$$ is if $$$H$$$ is a long path connected to a $$$K_{1,3}$$$(like your example). But in that case, no further $$$L^{-1}(H)$$$ or beyond is there, so it didn't matter under the context of problem statement.

            Thank you so much for the clarification!

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

              Thanks for clarifying.

              Is it possible to solve the problem when $$$G$$$ is not constrained to have an Euler trail? In particular, suppose $$$L^k(G)$$$ has an Euler trail for some $$$k \gt 0$$$. If you define $$$k^*$$$ to be the minimum such $$$k$$$, is it true that $$$k^*$$$ is upper bounded by some constant?

              If I'm not mistaken, you're claiming $$$k^*\le 3$$$, though is that actually achievable?

              • »
                »
                »
                »
                »
                »
                »
                »
                11 months ago, hide # ^ |
                Rev. 3  
                Vote: I like it +38 Vote: I do not like it

                That was the original intended problem for the problemset, though it was deemed too much casework and I too didn't have a concrete proof for it, so we went with current version on suggestion by our coordinator, which I believe was the right decision.

                Coming back to the problem, if $$$G$$$ is not constrained, then-

                Solution

                So, the claim $$$k^*\leq 3$$$ is true, as it was proven without using the assumption of initial graph not having an Euler tour. Thank you for showing interest into the problem.

              • »
                »
                »
                »
                »
                »
                »
                »
                11 months ago, hide # ^ |
                Rev. 4  
                Vote: I like it +32 Vote: I do not like it

                Also, while I was thinking more about the problem now, I realized that the case that you told is the only possible case where $$$G$$$ doesn't have an Euler tour, $$$L(G)$$$ does and there is a graph $$$H$$$ such that $$$G=L^2(H)$$$. Attaching any arbitrary long path to a $$$K_{1,3}$$$ doesn't work. And no other case of $$$G$$$ has $$$L^{-1}(G)$$$ as $$$L(H)$$$ for any $$$H$$$ as $$$L^{-1}(G)$$$ always has a claw(a.k.a. $$$K_{1,3}$$$) induced. So it means $$$k^*\leq2$$$ holds.

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

                  Oh, does that mean that $$$k^*\le 2$$$ actually holds?

                  (cuz in the case I shared we have $$$k^*=1$$$)

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  11 months ago, hide # ^ |
                  Rev. 3  
                  Vote: I like it +38 Vote: I do not like it

                  Yes(sorry for the delay, I have $$$1$$$ response every $$$10$$$ minute penalty for <-100 contribution).

                  Food for thought
                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  11 months ago, hide # ^ |
                   
                  Vote: I like it 0 Vote: I do not like it

                  I'm not sure if I understand the case analysis correctly, but wouldn't

                  H = L^{-2}(G)
                  1 2
                  2 3
                  3 4
                  4 5
                  5 7
                  4 6
                  6 8
                  

                  be another valid example where k* = 3?

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

                  $$$k^*=2$$$ for the case you've shared, as $$$L^2(H)$$$ has exactly two odd degree vertices.

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

                  Ah I see. L^3(H) has an Euler Tour, but I didn't realize L^2(H) also does.

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

In tutorial of the problem C , it should be loop $$$i$$$ rather than $$$j$$$. Although it does not affect understanding

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

I don't understand something in C. greedy we constructu $$$ m - n $$$, we have n as remaining sum to construct. now if the tree is like $$$ root = \gt ans[2] = \gt ans[3] = \gt .... = \gt 1 $$$ (ignore the remaining nodes so far), then this will have sum of diviness as $$$ root + ans[2] + ans[3] + .... + 1 $$$ and when adding all other they will have diviness value of 1 so it'll be this $$$ sum + 1.remaining nodes $$$. how is the remaining nodes part made equal to $$$n$$$?

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

I am a little confused on the editorial of D, it claims there should be (a-1)*k + 1 columns and (b-1) * (k*nca) + 1 rows, but the editorial code prints (a-1)*k + 1 first, then (b-1) * (k*nca) + 1. Doesn't the problem specify the number of rows should be printed first, then the number of columns? If you swap the meaning of column and row in the editorial it makes sense in my opinion or am I misreading something? C and D were interesting problems, shame the contest was ruined by cheaters.

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

The LaTeX of Problem D didn't work well.

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

$$$D$$$ was a cool one

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

The

Unable to parse markup [type=CF_MATHJAX]

and Unable to parse markup [type=CF_MATHJAX]

value of Unable to parse markup [type=CF_MATHJAX]

for a divine tree to exist are Unable to parse markup [type=CF_MATHJAX]

and Unable to parse markup [type=CF_MATHJAX]

respectively. Unable to parse markup [type=CF_MATHJAX]

Any Unable to parse markup [type=CF_MATHJAX]

can be achieved similar to exhaustive subset sum with redraws enabled. Let

Unable to parse markup [type=CF_MATHJAX]

, Unable to parse markup [type=CF_MATHJAX]

, Unable to parse markup [type=CF_MATHJAX]

= [ ]. Now, we need to select a multiset of Unable to parse markup [type=CF_MATHJAX]

non-negative integers that sum to Unable to parse markup [type=CF_MATHJAX]

. Unable to parse markup [type=CF_MATHJAX]

Loop Unable to parse markup [type=CF_MATHJAX]

from Unable to parse markup [type=CF_MATHJAX]

to 0
, if cur+i≤p
cur += i+1, ans.push_back(i+1) If ans.back() is not 1 add a 1 , why?

Construction: The tree can always be simple path, why?

Tree is rooted at ans[0] . Let's store vis[0:n−1]=false to keep track if a node is visited or not. Loop Unable to parse markup [type=CF_MATHJAX]

from Unable to parse markup [type=CF_MATHJAX]

to Unable to parse markup [type=CF_MATHJAX]

and add edge between Unable to parse markup [type=CF_MATHJAX]

to Unable to parse markup [type=CF_MATHJAX]

and mark all of them Unable to parse markup [type=CF_MATHJAX]

in vis . Take all un-visited in the array Unable to parse markup [type=CF_MATHJAX]

and add an edge from Unable to parse markup [type=CF_MATHJAX]

to Unable to parse markup [type=CF_MATHJAX]

. Loop Unable to parse markup [type=CF_MATHJAX]

from Unable to parse markup [type=CF_MATHJAX]

to Unable to parse markup [type=CF_MATHJAX]

and add an edge from Unable to parse markup [type=CF_MATHJAX]

to Unable to parse markup [type=CF_MATHJAX]

. The divine tree which is a simple path looks like ans[0]↔ . . .

Unable to parse markup [type=CF_MATHJAX]

. . . ↔unvis.back() .

=> "Great" solution :))

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

In the Solution for Problem E. exc(v+k) > def(v) I think you are missing a equal sign

»
11 months ago, hide # |
Rev. 2  
Vote: I like it +9 Vote: I do not like it

Alternative approach for E: 325584212

Use a greedy strategy: always move a car from the line with the most cars to the one with the least. While it's easy to compute the cost after each move, doing this directly would take linear time in the total number of cars.

However, the cost function is convex (this can be proven easily, I think), so instead of simulating every move, you can binary search over the possible car-taking-from-lines to find the minimal cost efficiently.

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

    I tried E on Python using a greedy strategy. It sadly gave a TLE ERROR on pretest 10. However, mine was much slower, because I forgot that we can easily find how many cars would we move to the minimum number of cars, and how much to subtract from the initial sum of the cost of the lanes. I think it may be done, but would be highly inefficient for larger lanes. I mean a pure greedy one with the maximum to minimum changes, like the ones I gave changed a bit (include the formulae). Also, I am a Newbie, so, I didn't expect much

»
11 months ago, hide # |
Rev. 5  
Vote: I like it +14 Vote: I do not like it

Regarding Problem D, it's easy to understand why $$$n = k \times (a-1) + 1$$$ based on the pigeonhole principle.

I was initially confused about the process of deriving the minimum $$$m$$$, but I now roughly understand it. So compared to the solution, I want to provide a more detailed explanation.

Let us consider the problem in this way:

For the first column, suppose we choose color $$$c$$$ to appear exactly $$$a$$$ times, while all other colors appear only $$$a-1$$$ times.

First, I want to explain here why all other colors appear only $$$a-1$$$ times.

Suppose there is another color $$$d$$$ ($$$d \neq c$$$) that also appears $$$a$$$ times. Then, intuitively, having more candidate colors to choose from in the first column makes it easier to later achieve $$$b$$$ columns of the same color (at the very least, it does not make it harder).

Please understand the above statement, as it is crucial for the subsequent derivation.

Now, suppose we are at the $$$j$$$-th column ($$$j \gt 1$$$). Let the colors in rows $$$1$$$ to $$$i$$$ of column $$$j$$$ be $$$f_1, f_2, \dots, f_i$$$. We can deduce three points:

  1. No color appears more than $$$a$$$ times (strictly greater than $$$a$$$ times): If a color $$$g$$$ appears more than $$$a$$$ times in column $$$j$$$, then in subsequent columns, achieving a final configuration where the color (specifically $$$g$$$) is the same does not become harder.
  2. Beyond the color $$$g$$$ that appears exactly $$$a$$$ times, no other color can appear $$$\geq a$$$ times: Suppose another color $$$d$$$ ($$$d \neq g$$$) also appears $$$a$$$ times. Then, intuitively, having more candidate colors to choose from in later columns makes it easier to achieve $$$b$$$ columns of the same color (at the very least, it does not make it harder).
  3. For colors other than $$$g$$$ (which appears exactly $$$a$$$ times), the positions of colors appearing $$$a-1$$$ times are unimportant: Since these colors appear only $$$a-1$$$ times in this column, they will never be selected for this column.

Therefore, we can conclude that the number of configurations per column can be (considered as) $$$k \times \binom{n}{a}$$$.

Thus, the minimum value of $$$m$$$ is finally $$$k \times \binom{n}{a} \times (b-1) + 1$$$.

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

    For colors other than g (which appears exactly a times), the positions of colors appearing a−1 times are unimportant: Since these colors appear only a−1 times in this column, they will never be selected for this column.

    This seems somewhat unintutive for me

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

Can someone see and tell me how am i getting out of bound error 325596815 Like at this point i cant even spot the difference between my code and the editorial code.

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

so what do the authors want to express by problem g, actually i gave up immediately once iv found the solution to problem g

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

Really liked Problem E! D is a cool one too.

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

D WAS SO SIMPLE ALL ALONG

SOLUTION
»
11 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

In the solution of D, I think you've swapped the rows and columns. For example: k*(a-1)+1 isn't the size of each row but the number of rows.

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

Can someone please try to hack my A

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

O(n) solution for C

325487855

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

[Question about Problem B] Is it clear from the problem statement what happens when three or more balls collide at the same point at the same time?

[Comment] I personally felt that the overall quality of the problems itself was sufficient.

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

    "It is guaranteed that multiple collisions do not occur at the same moment and position." This is mentioned in the problem statement.

    Fun Fact — I discovered this 1 week before the contest that 3-body collisions can be interpreted in multiple ways, so we removed the ambiguity.

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

      Thank you. I overlooked that. I think it would be better if it were also mentioned in the input section.

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

Can someone explain in D why for choosing column is

"The number of possible values of the tuple is k×nCa " . ?

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

    the size of the tuple is A+1 first element is a number from 1 to K and the next A are positions (from 1 to N) so out of N positions there are NcA choices and K ways to chose the number

    note that the positions don't correspond to the chosen first number in the tuple here because we just want to find all the possible tuples.

    also N is the number of rows calculated earlier so there are only N choices for the position

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

cur+= i+1 — maybe cur+=i?

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

In C Divine Tree why curr += i; not cur+=1?

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

What was the meaning of rotation in A

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

Another nice solution for Problem E: Let us consider the operation of moving one car from the longest line to the shortest line. We know that this operation is optimal up to a certain point, until the cost of k exceeds the benefit of the operation. Then we can binary search on the number of operations to find the point where it stops being beneficial. To simulate doing m operations, we can distribute m among the minimum numbers in the array, and distribute -m among the maximum numbers in the array, then track the change to the cost. 326369185

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

Hello. I have a question about the codes provided for 2120D — Matrix Game.

The case

1
30000 33335 33335

Your code outputs 16659 1

I see you calculate $$$\binom{n}{k}$$$ in $$$O(k)$$$ by multiplying by the modular inverse, but is the correct answer for $$$m$$$ truly 1?

In your counting, the numerator becomes 0, because you multiply it by $$$(n-i+1)$$$, which is $$$0$$$ at some point.

To give another example, let's say you want to calculate $$$\binom{17}{6}$$$ $$$mod$$$ $$$5$$$. The algorithm above will return $$$0$$$ because the numerator becomes $$$0$$$, but the actual answer is $$$12376$$$, which modulo 5 is $$$1$$$

It might be that for the example I shared the answer is 1, but wouldn't there be a case where it fails?

  • »
    »
    11 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +6 Vote: I do not like it

    Hey,

    As long as the number being multiplied in denominator is not a multiple of $$$mod$$$, the operation of inverse modulo remains valid. For example, $$$\frac{15}{5}\mod 5$$$ is invalid under $$$p\times q^{-1} \mod 5$$$ for $$$\frac{p}{q}$$$ as denominator is multiple of $$$5$$$. The numerator doesn't matter then.

    In the problem D, any value in denominator being multiplied is always less than $$$mod$$$ as $$$k \lt mod$$$, so $$$k-i+1 \lt mod$$$ for all $$$1\leq i\leq k$$$. So, it is always coprime to $$$mod$$$, and safe under inverse modulo.

    For the first example you've shared, the answer is indeed $$$1$$$ as under modulo, as you can easily prove — if $$$16659$$$ is the value after taking modulo with mod, it means value of $$$n$$$ is $$$mod*r+16659$$$ where $$$r$$$ is some positive integer. So, $$$n-i+1$$$ is divisible by $$$mod$$$ for $$$i=16660 \lt 33335=k$$$. But, the denominator will always be coprime to $$$mod$$$ as shown.

    For the second example, it is invalid as some denominator is a multiple of $$$5$$$ that is being multiplied($$$6-i+1$$$ for $$$i=2$$$). So, you first have to reduce numerator and denominator by removing the common factor of $$$5$$$ from both and then find $$$p\times q^{-1}\mod 5$$$

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

E reminded me of this and this

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

Need Help for C DIVINE TREE submission Link The Log say wrong answer Test 226: Expected -1, got a Tree !! (test case 226) But i have checked the condition of

if(m<n || m>n*(n+1ll)/2ll)
    {
        cout<<"-1\n";
        return;
    }
  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    if you add this condition:

    if (n == 1) {
        if (m != 1) cout << "-1\n";
        else cout << "1\n";
        return;
    }
    

    it should fix your code

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

What does the notation in the solution of D mean? the x^n times C_a? C_a is catalan numbers or something else?

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    $$$^nC_a$$$ is alternate notation for $$$n \choose a$$$. The authors didn't format it correctly though so it looks like the $$$n$$$ applies to the $$$\times$$$; this tripped me up as well when I read the editorial.

    If you want to use the $$$^nC_r$$$ notation in Latex, a simple fix is putting \, before it, e.g. $$$k\times\,^nC_r$$$ instead of $$$k\times^nC_r$$$.

»
10 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

Hello Dragmon! I would like to ask about something in your solution for the problem G, specifically in this line:

Spoiler

Shouldn't this only return true when k = 1? For example, this test case:

Spoiler

This test case should be valid as it has an Euler trail, and in your code this test case's answer is "YES", while the actual answer should be "NO", I tried it according to my code and logic, any many other codes. Please correct me if I'm wrong, but I had to make sure everything is ok.

  • »
    »
    9 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +13 Vote: I do not like it

    Hi. Yes you are right, the answer should be NO. I somehow forgot to add $$$k=1$$$ condition within if and since there weren't any testcase of type where two odd vertices of degree $$$1$$$ and $$$3$$$ are connected with $$$k \gt =2$$$ so my solution passed against the AC benchmark solutions(including brute force one) in polygon.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it +6 Vote: I do not like it

      I see, I got a bit confused while analyzing the logic and code then ended up with a similar conclusion, but your explanation clears it up. it happens so it's alright, and thanks for the reply!

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
void printCheckSquare(int l,int b){
    if(l == b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

void solve(){
    int l1,b1,l2,b2,l3,b3;
    cin>>l1>>b1>>l2>>b2>>l3>>b3;

    // main code
    if((l1==l2 && l2==l3)) printCheckSquare(l1,b1+b2+b3);
    else if(b1==b2 && b2==b3) printCheckSquare(b1,l1+l2+l3);
    else if(b1 == b2+b3 && l2==l3) printCheckSquare(b1,l1+l2);
    else if(l1==l2+l3 && (b2==b3)) printCheckSquare(l1,b1+b2);

    else cout<<"NO"<<endl;
}

WHY NOT WORKING PLEASE HELP???

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

    For the case

    6 3 3 3 3 3

    The answer is YES as l1=l2+l3, b2=b3 and l1=b1+b2.

    Your code will output NO as it checks b1==b2 and b2==b3 which is true but then in printCheckSquare, it will see 6+3+3!=3.