https://codeforces.com/contest/1804/problem/A
I am trying to figure how to do problems the fastest way but couldn't figure out this out, anyone able to help?
I included a link to the problem above, thanks a lot :D
#Codeforces contest
51 messages · Page 1 of 1 (latest)
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.
well crap
Isn't the result just 2*max(a, b) ?
Well, almost, need some abs in there.
2*max(abs(a), abs(b))
oh
2*max(abs(a), abs(b))-1 maybe, except for (0 ,0). Not entirely sure.
its a lil off
2*max(abs(a), abs(b)) - a != b 🤡
Shit, still wrong
Omg
2*max(abs(a), abs(b)) - abs(a) != abs(b)
is that a condition?
That is a reasonable interpretation of the formula.
damn
may i ask how did you figure out that equation just now?
like what steps do you take to reach it?
2*max(abs(a), abs(b)) - (abs(a) != abs(b))
making out pseudos?
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.
ok
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.
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
Eh, that was pretty much the extent of my thought process.
oh
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.
oh ok
do you have any tips so i can like, think of ways to deal with a problem faster?
last question i promise 💀
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.
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.