cry's blog

By cry, 7 days ago, In English
Rating Predictions

2060A - Fibonacciness

Problem Credits: Proof_by_QED
Analysis: larush

Solution 1
Solution 2
Rate The Problem!

2060B - Farmer John's Card Game

Problem Credits: Lilypad
Analysis: larush

Solution
Rate The Problem!

2060C - Game of Mathletes

Problem Credits: LMeyling
Analysis: macaquedev

Solution
Rate The Problem!

2060D - Subtract Min Sort

Problem Credits: Proof_by_QED
Analysis: Proof_by_QED

Solution
Rate The Problem!

2060E - Graph Composition

Problem Credits: LMeyling
Analysis: DivinePunishment

Solution
Rate The Problem!

2060F - Multiplicative Arrays

Problem Credits: Proof_by_QED, cry
Analysis: -firefly-

Hint 1
Hint 2
Hint 3
Solution 1
Solution 2
Rate The Problem!

2060G - Bugged Sort

Problem Credits: chromate00
Analysis: macaquedev

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Rate The Problem!
  • Vote: I like it
  • +48
  • Vote: I do not like it

»
2 hours ago, # |
  Vote: I like it +6 Vote: I do not like it

C took me incredibly long. I was completely overcomplicating it thinking that we needed to subtract from the answer when there was an odd number of non-pair numbers.

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    hahaha, I did the same. I didn't realize the fact that non pair numbers can never be odd up until the contest ended, so silly.

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    hahahaha me too bro

  • »
    »
    64 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    same

  • »
    »
    50 minutes ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Same, I didn't read that n is even only :(

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

It was a nice contest! I got stuck on problem E, but I'll learn from it.

  • »
    »
    39 minutes ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    today was the 1st time ever i reached problem E :), all the best to u!

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

I solved 4 but took a shit long of time.Damn That A ,A problem statement can be better

  • »
    »
    31 minute(s) ago, # ^ |
    Rev. 3   Vote: I like it +1 Vote: I do not like it

    At first reading your comment, I thought you actually had to take a dump during the contest. I almost felt sorry for you.

»
2 hours ago, # |
  Vote: I like it +13 Vote: I do not like it

Why is F so damn hard???

»
2 hours ago, # |
  Vote: I like it +7 Vote: I do not like it

Is it me or the B problem was kind of hard to implement ? It took me a while to solve it. Even the total number of users who solved the problem is less than the problem C.

»
2 hours ago, # |
  Vote: I like it +14 Vote: I do not like it

As an AKer in 2h29min, I think this is closer to DIV2 ;)

»
2 hours ago, # |
  Vote: I like it +7 Vote: I do not like it

Problem G is very good.

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

I lost like 1000-2000 rank because of B and D :( and also got too confident on my two different solutions to E and submitted them both. But nevertheless, This was the most problems I ever solved in any contest yet and I am quite happy.

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

Imo, C was easier than B.

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

Can anyone explain D?

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

contest was really cool...solved A,C but couldn't solve B:(

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

I solved A, C and D but can't solve B. I don't know what is the logical mistake in my solution.

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

    my approach which might help:

    store in the form of int[n][m] sort all vectors find order by taking first el of all check if order is valid, else -1

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

    I created a vector of size n * m, and for each card assigned the number of the person holding it. The problem stated that you have cards starting from 0 to n * m — 1 and each card has to be greater than the last one. So with this array, you already have the sequence:

    Cow 1 has cards: 1 4 7

    Cow 2 has cards: 5 2 8

    Cow 3 has cards: 0 3 6

    The vector will be {3, 1, 2, 3, 1, 2, 3, 1, 2}. We have 3 cows, so we only get the sequence from up to index |qty. of cows-1| and check if it is equal the rest of the sequence.

  • »
    »
    118 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    check for edge case n=1

  • »
    »
    115 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    consider total m rounds.

    In each round that is total N cows will place a card. so,First create a map of all the numbers (0->n*m-1)-> for each number assign the cow. which cow is holding this particular card. Now iterate from z=0.(this is current card number) total we have to place m rounds .and in each round total n cows has to participate. say in round 1 -> z=0->search which cow has this z=0 number.insert that into a vector. increment z; z=1->search which cow has this z=1 .insert that cow number into a vector. after "n" cows played a permutation will be generated. you have to make sure that this is the only permutation will come at the end of the M rounds.

    insert this vector into a set after each round.

    at the end check whether the size is 1 or not you can refer

    https://codeforces.me/contest/2060/submission/301815602

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

Did anyone use Faulhaber formula to solve F?

  • »
    »
    92 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I tried that at first, but then I realised my way of counting was wrong lol

»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it
  • »
    »
    36 minutes ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Test Case :

    1

    4

    1 3 5 2

    Expected Ans : NO

    Your Code Output : YES

  • »
    »
    14 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I did the same at first , you can see my solution and find that we almost coded the same thing , except we both ignored the fact to change a[i-1] , we only focused on changing a[i] , you might ask how does that affect out solution.... Well , for the given test case : n = 8 a = [4 5 4 5 4 5 4 5] try printing your answer , it gives: [4 1 4 1 4 1 4 5] which is non decreasing , but still the answer is YES and that's a fluke.... so what is our next approach? Well luckily for us we dont need to change a lot in this code , just make sure to understand the fact that , we won't change the values only when a[i] > a[i + 1] , we might need to do it otherwise as well , its kinda hard to explain the intution , until i come up with a proper proof but a rough proof might look like : let's take the above array that i used as an example , there your code didn't use the operation on 2nd index(0 based) and hence in the answer array we get a 4 , instead if we had applied the operation then the answer array would've looked like [0 0 0 0 0 0 0 4] so just apply this operation on all the indices , and check in the end if it is sorted or no , lmk if you have any doubt , here's my submission : here

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

good contest , bad contest

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

My brute force is failed for C. Its was basic level question

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

The testcases for E couldve been better. I just thought we have to make both the graphs same but i guess thats what makes me a newbie

  • »
    »
    77 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i guess also thought the same after WA i thought another solution lol

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

thank for contest

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

man i dont know why my c is wrong .


#include <bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int score = 0; int n,k; cin >> n >> k; vector<int> v(n); for(int i = 0; i < n; i++){ cin >> v[i]; } sort(v.begin(),v.end()); for(int i = 0; i < n/2; i++){ if(*min_element(v.begin(),v.end()) + *upper_bound(v.begin(),v.end(),k -1 -*min_element(v.begin(),v.end())) == k){ score++; v.erase(upper_bound(v.begin(),v.end(),k -1 - *min_element(v.begin(),v.end()))); v.erase(min_element(v.begin(),v.end())); }else{ v.erase(min_element(v.begin(),v.end())); v.erase(min_element(v.begin(),v.end())); } } cout << score << endl; } }
  • »
    »
    2 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Maybe, you are erasing from the vector ,this will change the vector,so in future issues mayrise with the upperbound and lowerbound later.these upper bound and lowerbound may change and they may not the ones which you think they'll be..Try out a test case and try printing all the upperbound's and lowerbound's and see..

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

    It fails on this testcase: 1 2 4 2 3

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

why 301896773 gives TLE when submitted in C++20 but accepted when submitted in C++17

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

I'm quite new to graph theory problems, so please pardon any ignorance. However, for the life of me, I cannot understand why in problem E you cannot just count the number of pairs of (u, v) that are in G and not F, and the pairs in F but not G?

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

    consider the testcase

    1

    4 2 2

    1 3

    2 3

    1 2

    1 3

    the answer is zero

    but according to you answer will be 2

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

    If (u, v) does exist in G, but not in F, it doesn't mean that you can not reach v from u (u -> w -> v)

    • »
      »
      »
      118 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Aha! I guess I assumed that the problem only wanted one edge between (u, v).

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

    Consider F = 1-2-3-4 and G = 1-4-2-3

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

Can someone explain how for E on the second test of test 2 the # of operations needed is only 2? I'm getting 33.

  • »
    »
    112 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    oh as long as there is a path between them it works didn't realize that

»
2 hours ago, # |
  Vote: I like it +5 Vote: I do not like it

F was awesome

»
118 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Nice contest. D was pretty easy, though.

  • »
    »
    99 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    didn't you get it hacked ??

    • »
      »
      »
      90 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Nope, not yet at least. Might get hacked since I didn't really think much on it aside for my initial doubts about my approach being too simple to work.

»
117 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Jeez!! I got stuck on problem E. Now reading the tutorial I noticed that I had the idea but still have lots of problems on the implementation looool. Btw, interesting contest, good problems. Wanna upsolve rn!!!!

»
117 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

301778309 Can someone point out the error in this for B?

»
114 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Any good resources to learn combinatorics?

»
113 minutes ago, # |
  Vote: I like it +2 Vote: I do not like it

Self review no one asked for:

so mad that i sold around 50 penalty points because of the misread on a...

i lost a little time on b because of interesting construction

rushed on c, my mind was too disorganized

c-d turnaround was lowkey clean, i hit an instant mindsolve

e i sent two wa because i thought we needed to simply match the edge list, rather than the path. test case 1 seemed to support this. i sent another wa submission because i thought it was overflow

f and g were beyond me

  • »
    »
    93 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Quite same. Got stuck on A and thought I was screwed. Than tried D and bam! solved it in first go. C was also a smooth sailing, but got stuck at B again. I really don't know what to feel as A and B gave me more trouble than my whole college exams combined.

  • »
    »
    81 minute(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My man, at least you realize it in time.

    When I was realized I read the problem E wrong, the contest is already over.

    It only took me ~ 30 min of implementation so if I could realize I read the problem wrong, I can comeback easily (theoretically)...

    Ready going back to pupils and wait for Div 4.

  • »
    »
    34 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can I know the extension that you are using to predict the rating changes

»
113 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Why was d at d?

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

    Because we hoped that some people will prove the result instead of resorting to guessing that the obvious strategy works, and the proof is actually not so simple.

    • »
      »
      »
      87 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Hey can you tell me whethe my proof was correct?

      I started from the first index of array and started taking the mid of first two elements. Than I subtracted it from both. Than we will reduce one element to 0 and the next to whatever was left after subtracting. By the way this was done only when first element was smaller than second as otherwise if this operation is performed there is no way that array can be non decreasing as zero is the minimum element obtainaible and everytime we pair an element with 0 the min of them both will be zero. So if we get something like 1 0 than it's likely impossible but if we have smooth sailing till last index than you are good to go.

      Does it seem satisfactory or you have a better proof? I'd love to hear your take.

      • »
        »
        »
        »
        85 minutes ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        This doesn't tell me why it is optimal to decrease on the first element first. Perhaps it is better to do them in a different order. My proof is in editorial

»
112 minutes ago, # |
Rev. 7   Vote: I like it 0 Vote: I do not like it

There is an easier solution for G without dp and more straightforward to prove(?). Imagine $$$a$$$ and $$$b$$$ stacked on top of each other, draw an arrow pointing downwards from $$$a_i$$$ to $$$b_i$$$ if $$$a_i > b_i$$$ otherwise draw an upwards arrow from $$$b_i$$$ to $$$a_i$$$. Now doing an operation on $$$(i,j)$$$ is equivalent to swapping the pairs $$$(a_i,b_i),(a_j,b_j)$$$ then flipping their arrows.

Following from the editorial, the order of the pairs in the final sorted configuration is fixed and we can freely reorder the pairs. The question left is whether we can orient the arrows correctly?

Assume we already fixed the final direction of each arrow in the final state, the number of up arrows in the final and initial state has to have the same parity (parity of up arrows is invariant under swapping). So we now ask what possible parities of up arrows can the final state have?

First sort the pairs by $$$\min(a_i,b_i)$$$. For each $$$i$$$, if $$$\max(a_i,b_i) > min(a_{i+1},b_{i+1})$$$ then their arrows must share the same direction, otherwise they can be different or the same. Now we split the pairs into consecutive segments where each all arrows in the same segment must have the same direction. The parity of number of up arrows can be $$$0$$$ or $$$1$$$ iff there exist a segment of odd length because changing the direction of all arrows in an even segment does not change the parity of up arrows. The answer to yes or no reduces to these two conditions:

1) No $$$\max(a_i,b_i) > \min(a_{i+1},b_{i+1})$$$ exist

2)There exist an odd segment or the parity of up arrows in the initial state is even

  • »
    »
    70 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My solution is similar to yours, but I think you're missing one case.

    Even if all the fixed segments are even length, if there exists two consecutive i's where max(ai,bi)>min(ai+1,bi+1) is false, then you can flip the first of those two i's without changing anything else. This means you can always make the total number of flips even.

    (Also you still have to check that after ordering the pairs, one of the flips (or arrow directions) is valid — such as in the first example test case where the middle pair can never be valid.)

    • »
      »
      »
      62 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes that condition should be condition 1), I miswrote $$$\min(a_{i+1},b_{i+1})$$$ as $$$\max(a_{i+1},b_{i+1})$$$

»
111 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

In the tutorial of B, it says in general,

the i-th cow (where i∈[0,n−1]) must be able to place i,n+i,2n+i,….

but what if the input is

1

3 3

3 4 5

0 1 2

6 7 8

here there is still a possible permutation but not according to the tutorial ??

  • »
    »
    19 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No player can play consecutive turns, so suppose player 2 plays 0, player 1 plays 3, and player 3 plays 6, then player 2 can't play any of his cards since they are smaller than 6. (If you think that player 2 can play all his cards, then player 1, then player 3, then you might have misread the question) A player will only get his turn after all other players have played, everyone maintains the same turn order throughout the game

  • »
    »
    18 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    "Farmer John wants the game to be fair, so each cow should only be able to play 1 card per round."

    Maybe you read too fast or forgot about this part.

»
107 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem F solution 1, how are we calculating \begin{align*} \binom{n+1}{j+1} \end{align*}

since n is very large?

  • »
    »
    105 minutes ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    n is large, but j is small. You can compute in O(j) time.

  • »
    »
    104 minutes ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    $$$\binom{n+1}{j+1} = (n+1)(n)(n-1)\ldots (n-j)/(j+1)!$$$, there are only $$$j+1$$$ terms in the binomial

»
96 minutes ago, # |
  Vote: I like it +1 Vote: I do not like it

my downfall was A. I don't know why I was overthinking it so much when it was so obvious. Took me nearly one hour to solve. I really have a lot to learn...

»
94 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Amazing contest! I was able to solve A, B, C on whiteboard. Hope to see more contests like this!

»
92 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Is it just me or anyone else feels like there are a bunch of people using AI to solve the problems, given LLM's are basically on Master's level. Some low rank people just straight up solve E. I tried plugging the question into ChatGPT and it instantly gave me a working answer. What is the future of these types of contests?

»
84 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

For D I used a completely different approach, where the logic (at least if you have to prove it!) is simpler: starting from the end, find the allowed interval for the previous element. Then check that the first element fits in the required interval.

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

Although B is quiet easy there is better way to implement it(or should I say more efficient)(although the logic remains the same) , we could just find the modulo the elements of each row with n if they are all the same , then it is possible else it isn't . Finding the permutation is also easy , we can just create an array and append the remainders (if they are all equal for a row). Now the permutation would be the remainder+1 . The time complexity would be $$$O(n*m)$$$ here (This is what I did during the contest).[I know that this is fairly simple problem , but I thought this would be nice to point out nonetheless]

»
60 minutes ago, # |
  Vote: I like it +1 Vote: I do not like it

Damn... I've used DSU implementation from Algorithmica. And it was wrong all from the start. Spent 30 minutes to find a bug in my solution, and the only bug was my trust in this site.

»
47 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone explain why my solution of B 301795916 is giving wa.

»
40 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I solved G without using dynamic programming and I think it's a bit more intuitive (at least for me).

Using the same insights as mentioned in the hints, my solution builds out a possible answer and checks if it has enough degrees of freedom to end up with an even number of flips, or necessarily has an even number of flips.

Say you've placed the first n pairs (as the editorial mentions, this order is fixed by $$$min(a_i, b_i)$$$), then you take the next smallest pair and decide how it should be flipped. There are 4 cases:

  • it needs to be flipped (meaning the element from $$$a$$$ should end up in $$$b$$$)
    • for example, the previous is $$${1, 3}$$$ and the next to place is $$${4, 2}$$$, the 2 cannot come after the 3, so it has to be flipped first
  • it needs to stay unflipped
    • for example, the previous is $$${1, 3}$$$ and the next to place is $$${2, 4}$$$
  • it can be either orientation
    • for example, the previous is $$${2, 3}$$$ and the next to place is $$${4, 5}$$$
  • or can't be either
    • In this last case, you can early return a "NO". This would be like in the first example case where you place $$${1, 6}$$$ first and then have to place $$${2, 4}$$$, but no matter how you flip $$${2, 4}$$$ the number after the array with 6 will no longer be increasing.

You don't need to track the whole array, just the chosen state of the previous pair, which you can initialize as $$${-1, -1}$$$ (since the first actual pair can have either orientation).

If at any point you have two in a row which can be either orientation, then you can flip or not flip that fist one to make the total number of swaps even, regardless of how the total turns out. From this point on, you will return "YES" as long as you don't find a situation where a pair can't be either orientation.

You will also want to track the number of fixed orientations there are in a row. If you end up with a block of fixed orientations which is of an even count, then you can flip the pair just before this block (which is necessarily one that can be either orientation, otherwise it would be part of this block) which would flip the orientation of all the pairs in this block as well, which will have flipped the orientation of an odd number of pairs, meaning the number of total flips will have gone from even to odd or vice versa. This freedom will mean no matter what the parity of the other fixed blocks are, you can make the total number of flips even or odd.

After going through all pairs, if you found either degree of freedom (either two free pairs in a row, or a block of fixed pairs of even count) or the number of flips applied for the array you built is already even, then it's possible.

»
22 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Why is dp[3][1] = 1 in solution of question G? Shouldn't the dp[4][1] be equal to 1 since we flip the first pair and the total flips is equal to 1?

  • »
    »
    14 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Editorial author here. Sorry, just a really annoying typo, because I got confused between zero and one-based indexing! It's definitely meant to be dp[4][1].

»
13 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

in c we can count number of pairs using 2 pointers, i did so so maybe update tags

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

In problem F, why are we only doing (n,j), there can be sequence of repeated factors as well which will reduce the multiple.

i.e. example consider a sequence [2,3,3,4,4,4] and then (n-6) 1's for any n. The multiple should be n!/((n-6)! * 2! * 3!)