#Codeforces contest

51 messages · Page 1 of 1 (latest)

serene sedge
merry hatchBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

serene sedge
#

well crap

toxic quiver
#

Isn't the result just 2*max(a, b) ?

#

Well, almost, need some abs in there.

#

2*max(abs(a), abs(b))

serene sedge
#

oh

toxic quiver
#

2*max(abs(a), abs(b))-1 maybe, except for (0 ,0). Not entirely sure.

toxic quiver
#

2*max(abs(a), abs(b)) - a != b 🤡

#

Shit, still wrong

#

Omg

#

2*max(abs(a), abs(b)) - abs(a) != abs(b)

serene sedge
#

is that a condition?

toxic quiver
#

That is a reasonable interpretation of the formula.

serene sedge
#

damn

#

may i ask how did you figure out that equation just now?

#

like what steps do you take to reach it?

toxic quiver
#

2*max(abs(a), abs(b)) - (abs(a) != abs(b))

serene sedge
#

making out pseudos?

toxic quiver
#

So, imagine you only care for one direction, a. Then you need 2 * a - 1 steps because you can move one step in that direction and then take a break until you're there.

serene sedge
#

ok

toxic quiver
#

Now, b doesn't actually matter if it's smaller than a because instead of taking a break you just go in b's direction instead of waiting.

#

Except if they are equal you need the full max of the 2. For example if you want to go to 1, 1 you need 2 steps, but 0, 1 only needs 1.

#

And then add a bunch on abs to deal with the negative numbers.

#

Going outside the board never makes sense.

serene sedge
#

ohhhh

#

that makes so much sense

#

could you tell me more about your thought process when coming up with this solution?

#

sorry if im asking too much lol

#

im new so just wanna take notes from masters

#

if you dont mind sharing of course

toxic quiver
#

Eh, that was pretty much the extent of my thought process.

serene sedge
#

oh

toxic quiver
#

The core idea is 2*max(a, b) like I started with and the rest is just fixing off by 1 errors and dealing with negative numbers. Using examples helps. 0, 0 is a great example, the result of the formula must be 0 which is how I noticed some attempts being wrong.

serene sedge
#

oh ok

#

do you have any tips so i can like, think of ways to deal with a problem faster?

#

last question i promise 💀

toxic quiver
#

Not really. Often times you think of the trick and it's super easy or you don't and despair.

#

Practice helps I guess. Having done similar tasks for years and recognizing the patterns.

serene sedge
#

oh ok

#

any good website that is of help?

#

final final question

toxic quiver
#

Personally I dislike hackerrank and similar websites. They reward quick unmaintainable hacks which will make writing software more difficult later. Just make a game or something.

serene sedge
#

oh ok

#

will keep that in mind

#

thank you so much again for all the help you have given

#

really really appreciate it

#

10/10

#

would ask again

#

!solved