Whalica's blog

By Whalica, history, 6 weeks ago, In English

IT'S YOU!!! CODEFORCES ROUND 1091 C!!!

IT'S NOT FUN AT ALL!!!

IT MADE ME SUFFER!!!

YOU DON'T NEED ANY ALGORITHMS FOR THIS!!!

YOU JUST NEED TO BE GOOD AT MATH — OR JUST GET LUCKY AND GUESS!!!

YOU MAY HAVE SPENT A LOT OF TIME TRYING TO PROVE IT, WHILE OTHERS JUST GUESSED THE SOLUTION!!!

  • Vote: I like it
  • +92
  • Vote: I do not like it

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

This problem is actually a fill-in-the-blank. Code is ONLY used to output the answer.

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

Hey, I am not really that good at math, but problem C is a classic. I have seen it before in different forms. I think that's totally acceptable for a C, especially since you can write a bit of code to test behavior and update your intuitions (which imo is a highly valuable skill for divs)

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

    Math problems are part of programming contests. But I think it is not good if the code only prints the answer. In a programming contest, a problem should at least need code to do some calculation.

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

      I can see that being valid, but for the most problems the main difficulty are the thinking and intuition in order to get to the solution, not the coding itself. Maybe I am just biased cuz I find elegance in problems that need a lot of work behind but very little code for the implementation

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

    But most people guessed the answer, I promise.

    Both guessers and solvers got ACCEPT on problem C, which I think was unfair.

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

      Maybe I haven't thought about something. I had to calculate 3 things in my solution. Was there an easier guessing method?

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

        I think the condition involving gcd(n, m) was quite hard to prove. Some people just observed the examples and guessed the condition without any proof.

        BTW, I want to stress again: this kind of problem should appear in math contests, not on Codeforces.

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

          Took me an hour of scribbling on paper to find the gcd(n,m) condition. Even then, I did not prove it but just sort of observed the pattern.

          I agree that I think it should've included more of an algorithm or been harder to guess, but I think the problem was an interesting one to solve regardless.

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

          I completely agree. During the contest, I correctly deduced the conditions on gcd(n, a) and gcd(m, b), but I made a crucial mistake by assuming gcd(n, m) > 1 instead of the correct condition gcd(n, m) > 2. It was quite disheartening to realize this after seeing the top submissions.

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

      guessers, solvers and cheaters.

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

    where have u seen different forms of it? its my first time seeing something like this

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

but isn’t cp and mathematics deeply correlated? so i think cpers should be willing to accept any kind of mathematical problem as a challenge, whether or not it directly contains algorithms. and the announcement itself already said that this round took a year to be fully made, and was also refined by many well known and highly rated members of the community, or is cp more like just applying algorithms that were already invented by some genius? either way, i’m learning a lot from this community in the hope of improving my problem solving skills, so i was genuinely curious about this

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

    I think this kind of problem should appear in math contests, not on Codeforces.

    Of course Codeforces can have math problems, but I really think this kind of "guess-the-conclusion" problem should appear less often.

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

they should have a goofy edge case to troll the guessers

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

I can understand why it's so frustrating to be honest, I have to admit I am one of the guessers as well, especially the part about gcd(n, m) <= 2 was not so easy to observe. Had there been a need for proof I am sure more than half of the people including me would not be able to answer this correctly.

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

i think it was quite fairly easy to see that you need the two GCDs to be 1 but the gcd(n,m)<=2 thing may be based more of RNG

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

It didn't seem like that much guessing for me, but maybe because I have solved similar problems before.

Here is how I thought about it:

Assume you only move vertically; at the second $$$i$$$ you are at $$$(i \cdot a) \% n$$$. to be able to pass by every possible row, $$$gcd(a, n)$$$ must be equal to $$$1$$$, the same goes for horizontally, but then it's $$$gcd(b, m) = 1$$$.

Now to check if we will visit every possible cell we calculate the number of steps it takes us to get back $$$(1, 1)$$$ (and reach a cycle); we return to the first row when $$$(i \cdot a) \% n = 0$$$, this happens when $$$i \cdot a$$$ is a multiple of $$$n$$$, and of course $$$i \cdot a$$$ is a multiple of $$$a$$$, so we need to find the smallest number that is both a multiple of $$$a$$$ and $$$n$$$ and that $$$i \cdot a = lcm(a, n)$$$, $$$i = lcm(a, n) / a$$$, we can notice that we go back to $$$1$$$ at every $$$i$$$-th move.

Similarly, we calculate when we will return to the first column using $$$j = lcm(b, m) / b$$$, at each $$$j$$$-th move, we return back to the first column.

Now to find out when we will return to $$$(1, 1)$$$ it's simply $$$(lcm(i, j))$$$.

Here in each move we either move down then right, so we multiply by $$$2$$$, the number of cells we visit before we return to $$$(1, 1)$$$ is $$$2 \cdot lcm(i, j)$$$.

We compare it to $$$n \cdot m$$$ (the total number of cells).

Doing math (that I'm lazy to write) can get you to the gcd formula, but you don't really need to do so.

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

    Nice conceptual proof, now it seems obvious

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

    how do you prove the cells you visit before returning to (1,1) are pairwise distinct when gcd(n, m) = 2

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

      For my solution, we go back to the first row every $$$i$$$-th move, and the first column every $$$j$$$-th move, For each time we return to one of them before $$$lcm(i, j)$$$ the other will be a different number (for example if at the first time we returned to $$$(1, 2)$$$, the next will be $$$(1, 3)$$$ and so on until we reach $$$(1, 1)$$$ again.

      Since each time you follow the exact same path with a different start, it always must be pairwise distinct.

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

You have to practice to guess.

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

why are you blaming the problemsetters tho? id just remember the trick for next time and move on

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

    Pure math problems like this, where the implementation is basically just reading input and printing output, should be much rarer on Codeforces and left more to math contests.

    Obviously, Problem C has no algorithmic design at all — it’s just full of number theory. That makes it feel far too math-heavy.

    CODEforces should focus more on the CODE and algorithm part, in my view.

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

      i guess, but you can't have competitive programming without math, so to me it's not inappropriate to have a math question every now and then. codeforces rounds aren't end-of-year exams, you can have oddball questions sometimes, why not?

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

Man can anyone guide me on how to solve that type of problems? like I was able to get A,B but C was over my head

Any ideas, or resources or thoughts

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

    You could try themecp website or solve at Ac daily website choose rate and solve general problems for general training For learning, for learning topics you could try assuit sheets for phase 1 and 2 it’s very useful or ultimate topic

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

When I tried to guess this task, I got wa2. I needed to prove the conditions and I was satisfied with the solution, it was a good task for its position.

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

why couldn't you simply guess the solution?

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

    The point is that guessforces problems aren't inherently bad, they just shouldn't appear on codeforces because of the format (speed is important and proofs are not required). it has nothing to do with whether or not one solved this particular problem.

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

      speed is important

      The cf format rewards speed; it isn't the problem's fault.

      proofs are not required

      ok, is that a bad thing? the only way i can think of requiring proofs is: here is some artificial operation i just invented and you will now be forced to find and and prove my observation.

      I don't see the bad in using your intuitions to skip the need for a proof for a problem. You can develop such intuitions with solving more problems / developing mathematical knowledge. It's what this platform is about.

      guessforces problems aren't inherently bad, they just shouldn't appear on codeforces

      If they're bad, why shouldn't they appear on codeforces? Where should they appear?

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

        The cf format rewards speed; it isn't the problem's fault.

        I agree that it's not the problem's fault. that's why i said the guessforces problems aren't inherently bad.

        the only way i can think of requiring proofs is: here is some artificial operation i just invented and you will now be forced to find and and prove my observation.

        Mathematical olympiads are a thing. in fact, in combinatorics problems (basically the closest thing to cf in MO), getting the right answer/construction is (most of the times) only a small part of the problem, usually earning less than 30% of the total score.

        If they're (not) bad, why shouldn't they appear on codeforces?

        Because they are not appropriate to the format, as i said. The same way that a problem that requires advanced knowledge isn't inherently bad, but it can't appear in IOI.

        Where should they appear?

        In mathematical olympiads.

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

        Maybe guess is a part of the CP. Just like in most greedy problems we need intuitions instead of proving it strictly. I think the key point is whether such pure purely mathematical problems are suitable for CP. And at least in my opinion, the "print answer" math problems are more suitable in MO.

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

      I disagree with you, guessforces problems are bad. Programming contests are meant to test your problem solving skills, and it should rewards problem solving abilities. Your ability to guess the correct solution right doesn't reflect your ability to solve problems.

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

        Answer intuition is a problem solving skill that, similar to other problem solving skills, can be improved through practice and is part of the ability to solve problems. There are some problems that could be solved just by guessing the answer, without any observations on the problem, but I think this problem is not one of them.

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

          You don't need to guess the solution for this problem, and you don't need to rely on your intuition much to solve it either. It's a step by step observation based problem.

          I have explained the thought process step by step here, https://mirror.codeforces.com/blog/entry/152775?#comment-1358632

          Intuition is not the same as guessing. Yes, it's a problem solving skill, one that you can grow through practicing. But even intuition shouldn't be enough to find out the answer. If the problem requires you to intuitively guess the solution, and having you implement it without properly understanding why the solution worked, then it's a bad problem. Intuition or not, one should understand the solution one implemented, that's the essence of problem solving.

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

i agree, pure math questions should be minimized

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

Mathematical forces!!

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

I'm weak in abstract math like things about mod,xor.Maybe it's educational,but is it suitable for D2C?Is it closer to a CP problem or a math problem?This round is absolutely a horrible memory for me.I'm trying hard to approach GM,but eventually I failed to get back to Master and unexpectedly receive a newbie performance.Worstly,I think some problem in the round are TOO CLASSICAL IN MATH THAT AI CAN SLOVE WITHOUT EFFORT.

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

    The main focus of authors is not to create problems that are "anti-gpt", it's to make problems that are interesting to solve. Also, if you're weak in a specific area, it's not the author's job to make problems that don't involve that topic, rather it's your job to practice in those areas.

    In regards to problem C, while I will admit it is somewhat standard (first two conditions are especially well-known), I see no reason why it doesn't test one's problem-solving skills. Coming from someone who is admittedly bad at math, mathematical reasoning is still important in competitive programming.

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

      You are right,but that problem didn't meet the difinition of "interesting".It's for classical mathical trick but not a lot for mathical logic,it's a kind of "anti-human".

      A former problem involve CRT with reflection,I think that math problem is interesting enough,but not that problem that without decoration.

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

bro fell for the ragebait

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

    Because in China, team managers see CF rating as a significant index to evaluate a team member’s skill level.So continuous unsatisfying rounds can really make a person upset and mad.Pure DS problems are not allowed,why should pure math problems be preferred?Having a most well-known rating system of CP in the world,CF is irreplaceable currently.When an important rating system is broking,as an involver,I think I can’t stay calm.But honestly,AI using issues are really hard to tackle.One day AI that having GM level will be easily fetched.

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

take a chill pill

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

Wow, I noticed one set is half of the needed set. So the size of needed set must be.... LET ME GUESS.... Twice of the size of first set? I am so good at math

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

All feelings aside, were there any set of skills (other than outputting the answer) unique to CP that the problem tested? Either way, I can't help but feel that this is just an Olympiad math problem forced to be in a CF contest.

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

To be honest, a large portion of modern CF problems requires no algorithm (especially first half of Div.2). And it might be healthier to think CF round as discrete puzzle contest rather than DS&algo contest.

If you really just want to solve algorithmic tasks, try ICPC or atcoder beginner contest. Though you would still meet such "mathy problems" but with less frequency.

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

No lol

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

I think it would be better if they start separate mathematical rounds.

It would also make it easier to find and practice problems with "pure math no implementation"

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

Although I guessed the part gcd(n,m)<=2 but then proof came naturally

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

I have seen fair share of bad problems, but C is not one of them. It's an observation based problem.

1) You need to visit each row and column, so n and a must be coprime, similarly m and c

2) If n and a is coprime, We know that after exactly n moves we will be back to row no 1. Similarly, other rows are going to be repeated every n moves

3) Now the problem becomes simpler, if we can prove that we can completely finish one single row, we can definitely finish every other row, since row and column movements are independent.

3) Let's assume that we go d->r->d->r.... after n down steps and n right steps we will be at a certain position in row no 1. let it be x1, just before the last right step, we will be at another position in row 1, let it be x2 = (x1 — b) % c. We can notice that this process will keep repeating after every n steps, shifting the values of x1 and x2 by the initially found value of x1. Now you get another subproblem, you need to figure out if given these conditions we can complete a row or not, which is not difficult to do. You can calculate for both possible ways to start, but proving for one is enough.

This is not a very math heavy problem. It's a number theory based problem, which is well within the bounds of CP and it is a topic you need to master to get good at CP. It is not very easy, but not too mathematically complex for CP either.

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

The tutorial of C was wrote very bad ngl

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

One way to guess is brute-force small cases and find something xddd

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

I revieved the problem 1091C and I think it's mostly not mathforces and CERTAINLY not guessforces. First of all, guessing the appropriate condition in this problem seems extremely unlikely, especially as you suggest for hundreds or thousands of participants. The solution is too specific for anyone to guess it without at least partial solving and only then "guessing" that one of the conditions is gcd(n, m) < 3 (which still seems pretty unlikely to me). In particular, my thought process in this problem followed a path very similar to the editorial: start by observing 1D case (that's how you get a sufficient condition gcd(n, a) == 1 and the other one), consider when in 2D going by diagonal, you arrive again to the row 1 at some offset coprime to n.

I understand that you think the problem is guessing, because the condition like gcd(n, a) == 1 seems pretty ad-hoc, but if you think about it, it's just a shorthand to writing "each column in the row is visited at least once". You don't have to formalize this idea using gcd, if you just start to think about when hopping by a constant jump allows you to visit all spaces. For a master like me, this is trivial that it's gcd(n, a) == 1, because I immediatelly see this as "when does $$$ak \mod n$$$ cycle through all values if $$$a$$$ is const?", which then I immediatelly see this as equivalent to "when is $$$a$$$ invertible $$$\mod n$$$?" which is again equivalent to "when is $$$a$$$ coprime to $$$n$$$?" to which the immediate answer is $$$\gcd(a, n) = 1$$$. So as you can see, this is a very natural way of thinking and requires 0 guessing skills.

I understand that this line of reasoning I used here may seem like I know some number theory, but in fact I just saw this many times in my life. You equally can just play with some examples and see the patterns without knowing any of this. Just pick a clock, start from 12 and jump by constant step, when you will visit all the numbers? You will quickly see, that jumps 2, 4, 6, 8 and 10 are always looping through even numbers, jumps 3 and 9 are looping over multiples of 3, and you are left with coprimes. Now you can generalize this immediatelly: if $$$n$$$ and $$$a$$$ share a divisor, this process always loops over multiples of this divisor, so you will never visit everything.

So really I don't see how you can say this problem could use any guessing? I think it's an OK problem, especially for D2C; actually I'd even say it's a pretty easy problem, because it's just a 2D variant of the classic clock game I described in the previous paragraph.

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

Agreed, a little now and then is fine, too much is uncomfortable.

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

Obviously the problem is not a guess problem. It is a knowledge check on Bézout's theorem.

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

If you didn’t solve problem C, then you simply don’t know the definition of gcd.

This was absolutely trivial for a problem C, and not solving it should be a reality check for you. Maybe study math?

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

Not sure if this is rage bait…

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

    Absolutely not.

    I’ve been suffering from these “guess the condition” problems for a long time. While I was working hard to actually prove the correct solution, other people had already guessed it, which in turn pressured me into guessing as well — but I’m just not good at that.

    I know this isn’t really the problem’s fault. What I mean is this:

    One obvious trait of this kind of problem is that it only takes a few lines of code and a few conditions to get Accepted. The bad part is that the key condition is somewhat hard to derive, yet still easy enough to guess, so it ends up rewarding guessers while making everyone else struggle.

    If a problem is mostly about determining some conditions, then why not just make it a fill-in-the-blank problem? You would only need to fill in the necessary conditions.

    That’s why I want this kind of problem to appear less often on Codeforces — not disappear completely, just be a bit less common.

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

Mathforces classic. I found this one to be quite fun, however. Math is a fundamental part of many competitive programming tasks, especially GCD.