Hey, Codeforces!
Hope that the last few days were quite productive for all of you in terms of rest and pleasure. Time to forget about messing with handle colors and get back to coding!
I'm proud to usher the first contest of the year — Codeforces Round #456, which is going to be held on Friday, 17:35 MSK. The round will be rated for all division 2 participants. Anyway, we will be glad to see whoever decides to join us out-of-competition :)
The authors are — GreenGrape and rek (don't worry, it's all about New Year magic ^^). My heartfelt gratitude to Kolya (KAN) for his invaluable help in round coordination, Grisha (vintage_Vlad_Makeev) and Oleg (xen) for testing and correcting statements, Dima (cdkrot) and Gleb (Glebodin) for preliminary solving, AmirReza (Arpa) for close reading and Mike (MikeMirzayanov) for awesome Codeforces and Polygon platforms.
We look forward to brightening up your cold winter evening :)
GL & HF!
UPD. There will be five problems with the following scoring:
500 — 1000 — 1750 — 2000 — 2500
As usual, it's strictly recommended to look through all problems :)
UPD. Please note that the registration was delayed for a few hours.
UPD. The contest is over.
It turned out to be a little bit more complicated than we expected. Still we hope you learned something new :)
UPD. Editorial!
UPD. Congratulations to the winners!
Div. 2:
Div. 1 (unofficial):
The announcement is made early for once :)
For some of us it might be morning
Where are the other Grapes?
BlueGrape and GrayGrape seems like poison, no?
they were used in grapefruit
Here I am, hybrid grape...
You can just dip in nutella
Hopefully it doesn't impact the registration statistacks
I always check statistacks at right time
For some of us it's summer (yay, southern hemisphere). I'm guessing some peole even have it as summer AND morning!
"Time to forget about messing with handle colors and get back to coding!"
If the registeration was by color ... there would be no div.2 participants, the whole scoreboard will be painted in red :D
Meanwhile the contest-setter himself also messing with handle colors
Don't skip the opportunity to hack legendary grandmasters
Thank you for remaining this moment)
Thank you GreenGrape for one more contest, also I'm really thankful to MikeMirzayanov for giving us chance to have fun.Good Luck and Have Fun)
Thanks for protecting Subaru. :)
He would re:spawn anyways :/
And thanks for not killing Ararararagi.
At first, I freaked out seeing the authors' handle colors...then I looked at my handle color xD
Wew!@ Time to do what I once didnt/couldn't:)
Welcome to the first contest in 2018. Sure fun for us.
First one in 2018 ;)
IsIt0.5Rated?
a lot of Legendary grandmaster will participait in this contest sounds like very intresting :)
hacking might get confusing!
don't worry, now colors are deceptive, but during the contest they will be returned to the real state if I'm not mistaken.
Wishing everyone high ratings and lots of green AC this year
LOL
i don't understand the context????
Fool or genius?
http://codeforces.me/contest/484/submission/8757420
OMG ,How did he/she do that?:|
Did you just not asume he's / she's gender?
Lol
Ofc he/she is a genius dude :)
fooooooooool
ostad bebakhsid ;)
When you are a doctor , but you want to code :p
I think Microsoft Word was help him!)
cryptography seems to be professor's research area :D
Maybe an ingenious idea to prevent hacks!
Perhaps Huffman coding can be done to compress the code size...lol
But if someone cheated using this technique, it will be hard to detect with human eyes. And i think this is not hard to implement.
What if the the code was scanned for cheating after all the defines were preprocessed out?
My solution was caught in plagiarism with another of my own solution in the last educational codeforces round. The problem has not been rectified yet. Can somebody help ????
Upd: The solutions have been accepted but the rating change has not been reflected. P.S I am a div2 contestant . Don't look at my color.
Upd2: I saw mike's blog post . The issue has been resolved. Thanks
A contest where newbies and pupils will hack grandmasters codes. :P
Old handles are appearing in the contest registrants page instead of new ones, is it a bug? Or its meant to be ???
Fastest score distribution ...!!! :)
Took us three days of furious debates, huh :)
My new year's resolution : "Become a candidate master". Wishing for ratings, not colour. :)
RUSH B!!!!!!!!!!!!!!!!!
a Russian playing CS GO .
I hope D and E will be very difficult so nobody can solve them
There are so many Red Coders participating this time!! :P
especially in div 2
and many newbies in div 1
I have a bad feeling, looking at the long queue 3 minutes before the contest...
I hope D and E will be very difficult so nobody can solve them
Should've hoped for a Million dollar.
HAHA Looks like problems D and E are very difficult.
Easier than C
Would not be surprised if more people solved both D and E than C
Hey, you were right.
Seems like people of codeforces do not like reading essays.
I believe the problem setter has set the questions seeing the color of participants and not ratings. :(
Now I realize, how tough it is to be a LGM.
does Problem C refers to Dota2? Lol
Lol
In Slavic mythology, Perun is equivalent to Zeus, so yes, it does :)
Feels good when I know a reference to something and not anime xD
I don't even understand C
Balancing the difficulty of problemset is the ground rule for preparing of contest.
How to solve E?
Meet in the middle and binary search
Can you explain your approach. I just hoped that bitmask will suffice.
Okay, understood. I actually thought about MIM but didn't think bitmask would be tle.
Divide array two parts and calculate answers for them as you do in MITM. Then binary search answer with counting numbers which satisfies condition. Be careful with overflow, it cost me 3 WA and a lot of time
Is intended solution for E is binary search + meet in the middle?
Yes.
Can you elaborate more? I didnt catch the exact idea man.
Can anyone help me with D? :(
Linearity of expectation
Can you please elaborate
Expected number of fishes caught = Σ P(catching fish at (xi,yi))
Now, select k distinct (xi, yi) such that sum is maximised.
P(catching fish at (xi,yi)) = (#Net positions covering (xi,yi))/(#All Net positions)
We can start by selecting middle element, and adding neighbors in the order of decreasing probability (using priority queue)
How do you compute the probability for each of the individual cells of the matrix?
That moment when all you do in life is play DotA 2 and you can't even solve problem C which discusses the Hero Zeus' ulti.
My thought process while trying (and failing) to solve C:
At first I was overwhelmed by all the information, but then I realized I can probably store times where regen graphs cross the damage threshold in a treeset and process them before/after each query as needed, and simply ignore everything with maxhealth <= damage, as they will always be killable, so as a result if everyone's max health is less than damage you can kill them anytime (infinite bounty).
An hour of spaghetti later, I submit and get WA
"Oh, obviously! I forgot the case if regen of an enemy is equal to zero!"
WA again same test case
"Oh, of course! I forgot the case if increase = 0, then bounty can never be infinity"
WA again same test case
"Oh, right. He can only do integer values, so if it's not evenly divisible I have to consider integer value right before crossing the threshold and right after..."
WA again same test case
There are too many special cases and other things to consider in this problem in my opinion. Maybe Dota2 players who code are super familiar with the algorithm because they do it in their head every time they play, but for the rest of Div2 Codeforces it is not quite as easy. That's the only way I can think of this problem being selected as a C problem.
Anyway reply with elegant approaches/solutions if you'd like, they will be much appreciated.
Important realisations: 1) If bounty increase is >1 and the max_health of any enemy is <= damage, the answer is -1 2) If bounty increase is >1 and health increase of any enemy is 0 and the last updated health of an enemy is <= damage, the answer -1
After taking care of those special cases it is just easy time_line problem where you mark all the +1/-1 points (new enemy I can kill/since this point I can not kill some enemy).
I used multiset at first, map later ended up with sorting a vector of time-line points, however always got TLE on the 8th test-case.
Overall nice problems, but really pissed by the distribution of correct solutions of the tasks (compare C to D or B).
C is annoying to code even if the solution seems elegant while thinking. Maintain 2 sets (RIP and non-RIP, RIP for heroes whose current health <= damage). Maintain an event priority queue. There are three kind of events: -1 (compute bounty), 0 (transfer a given hero from RIP to non-RIP set, to account for regen), 1 (Set current health of a given hero). Process the events in priority (-time, type). There are still annoying edge cases to handle (For example, future events of type 0 can be invalidated by events of type 1).
Wait for the authors' solutions, they are much more elegant :)
missed the case when increase = 0 but still passed pretests :/
I'm sorry to break it to you. But this is nothing like Dota2. The mechanism are totally different. The idea is only about Dota 2 nothing more. Examples:
1) No hero has 0 regeneration
2) Bounty is not this way
3) You don't care how much gold you get and the bonus will never become infinity So, knowing Dota2 will completely change nothing.
1) Ancient Apparation's ult or Spirit Vessel effect
2) That's true, I must admit :)
3) You actually do care about the amount of gold you get when you play Dota 2
Though you are right that Dota 2 experience would not really help with solving this problem :)
Well, what's important is general agreement.
The statement implies that there can be a hero with 0 regeneration throughout the whole match, and that's impossible.
You can't deny the fact that when you can kill, you'll kill. It doesn't matter how many you kill (AND YOU DON'T WAIT TO +INF TO USE YOUR ULTI)
What's important is playing Dota 2 won't help you solve the problem, practicing will!
B is a b!*ch -_-
Didn't even read C
Any idea what TC4 is in C?
increase = 0
Oh right, answer will never be -1 in this case.
Thanks
Idea for E?
split array into two parts (I had 6 and 10)
calculate all possible numbers for every part with dfs in two arrays L and R
then do binary search for answer and you must for mid calculate how many are there i and j that L[i]·R[j] ≤ mid
that can be done with two pointers
works 1.5 sec
In div2.B I didn't read "no more than k", I thought I had to choose strictly k. :c RIP rating.
in B i thought it was saying about exactly k element need to take.
but after 1 hour i saw that not more than K.
I thought it was exactly k too, but I don't think it matters for me because I couldn't solve it anyway
Just set all the bits.
Oh yeah, I think "at most k" is easier, because it is guaranteed to find two numbers in range 1..n who are 1's complements of each other ..
is the answer 2^( ceil(lg(n)) )-1 ?
find the right most set bit of n and set all the lower bits. If x is rightmost set bit then ans is = 2^x +2^(x-1)+...+2^0
Base case if K=1 then ans is n
Is D just hard work with cases and formulas or there's some elegant solution?
Maybe mine
I had Dejkstra algorithm. Just start from (n + 1) / 2, (m + 1) / 2
take each time point with largest cost
cost can be calculated like this
Ohhhh, that's nice
will it not give TLE as n,m<=100000
No. It works in 4·K·log(4·K). Or maybe faster)
Can anyone tell me what's wrong with this hack?
The fact, that only you can see it =)
Oops, sorry. It will probably be available after systests.
It's a hack for problem C:
It seems me, that Python and accuracy are incompatible http://codeforces.me/contest/912/submission/33928268
Not just python, I've seen some C++ solutions using log2() failing on the same test.
Devil made this test by himself)
a similar thing happened to me... still scratching my head where i went wrong
code
log2() and pow() work with doubles, not ints, so there will alway be some inaccuracy.
I also failed it the same way, with cpp.
will math.ceil work?
Problem A: very funny...
After reading Problem C
I read it twice and gave up and started to be dubious about my English reading ability...
Problem D: Use linearity of expectation.
For a cell (i, j), number of squares can be calculated like this: https://ideone.com/KbWoW7 (For upper left corner You find a valid range for lines, a valid range of columns and then you multiply the ranges lengths)
Now we have 2 vectors L(i) = the length of range for line i, C(j) = the length of range for column j. So number of squares that contain cell (i, j) = L(i) * C(j);
Sort vectors L and C in descending order. So L(0) >= L(1) >= ... >= L(num_of_lines) , C(0) >= C(1) >= .... >= C(num_of_columns)
Now at each step we need to choose a line i and a column j which gives the best L(i) * C(j).
Mantain a vector Last(i) = For the line i, what is the best column avaible? At the beginning Last(i) = 0;
We'll keep a multiset where we insert all lines, and we will keep the multiset sorted by L(i) * C(Last(i)) descending order.
Now, we do this k times: Extract beginning of set = A line i, add that L(i) * C(Last(i)) Value. Update Last(i) = Last(i) + 1 Add i to multiset again.
Can you please explain the thought process behind the formula to calculate the number of squares for a cell.
If you solve E with only bitmask (and reverse sorting the given list of primes), what's the complexity?
Still won't pass. I did my best putting in tons of heuristics ( that I even used to accept similar problems before), and always got TLE on pretest 5/6. Test cases are strong, good job to the testers/authors.
Interesting. I thought as the masks grow, the number of values we need to try decrease significantly. Probably some randomization will be needed. What's the complexity anyway
E passed, time to back Div.1! :-)
Well done & congrats.
Congratz bratan. Well done
I used tenary search for problem C, i still dont know where im wrong Here my code : https://ideone.com/grWZlx
The function must be convex or concave for ternary search, this isn't.
Today I realized,
Problem C. Test case 4 is wrong 2 0 1 0 1 10 1 1 2 1 0
The second enemy has start health = 1, regen = 0. So I can wait forever to kill him (I have damage = 1), so I can have infinitely gold. The answer is -1. But Jury's answer is 2.
My submission. 33945948,
Gold increase is 0 as well, so it means that the bounty will be constant.
Thanks GreenGrape for really quickly answer
Shouldn't they be disqualified because of cheating?
http://codeforces.me/submissions/Combi/contest/912
http://codeforces.me/submissions/Cinzaderius/contest/912
Upd: Only 1 submission was skipped, really?
Wow. :( @MikeMirzayanov
Wait Wait! there's no cheating there, they have a huge difference in problem B, one declared int and the other declared long ;o ._. haha. now on a more serious note :/ come on guys this is to improve over time not just for the ratings.
I'm send my apology to everybody scerely because of that cheating.I won't send my code to him anytime in the future.Please excuse me!
Why this formula (pow(2,floor(log2(n))+1)-1) failed for #test 48 (n=288230376151711743, k=2) in problem B
There are issues with built in logarithmic functions. For example, in python, the log of that number is 58.0000001 while the actual log is 57.9999...
But same code got accepted when I changed long long to long double for n and k. Why is this so?
log2
and friends (log2f
andlog2l
), as in the C standard library, accept onlydouble
,float
andlong double
parameters. So what happens when you pass along long
to it? C++11 (and future versions) explicitly say integral types get converted todouble
(notlong double
!) before calling functions from<cmath>
. Since the values in this testcase are not representable as adouble
, you get precision issues.Below's what the standard says in §29.9.1. Rule 2 applies in your case.
"For each set of overloaded functions within
<cmath>
, with the exception ofabs
, there shall be additional overloads sufficient to ensure:If any argument of arithmetic type corresponding to a
double
parameter has typelong double
, then all arguments of arithmetic type (6.9.1) corresponding todouble
parameters are effectively cast tolong double
.Otherwise, if any argument of arithmetic type corresponding to a
double
parameter has typedouble
or an integer type, then all arguments of arithmetic type corresponding todouble
parameters are effectively cast todouble
.Otherwise, all arguments of arithmetic type corresponding to
double
parameters have typefloat
."I use type conversion. Even after it will not work.
a = ((double)log2(n))
Casting the return value cannot provide you with more precision (since the value is already calculated). That would be CSI-level enhancing :)
We want to ask the function to calculate using type
long double
. There are two ways to do that:log2l(n)
orlog2((long double)n)
.Thanks for the reply. Now it is working. Thank you again.
The same condition happens to me and this is the very worst thing. Else we also get contest rating as well. 48.....
I also faced the same problem and got wa only for this issue. i tried to get log2 by doing log10(n)/log10(2) but got wa.. while debugging the only thing i got was a precision related issue which i'm experiencing for first time in a built in function.. calling log functions with an extra 'l' at last(taking long double as arg) worked fine..
why is rank of some users different from what their rating indicates? this probably happened during Goodbye 2017 coontest.
http://codeforces.me/blog/entry/56732
Users can change their handles and ranks. after 10 of jan ranks will become normal
Now that's normal for many people's :|
that's strange. Now I'm again grey.
Muggle spotted . :P
prob b http://codeforces.me/contest/912/submission/33945293 test 5 works on the csacademy compiler, but its not the correct answer here?
1UL
has typeunsigned long
.(unsigned) long
on 64-bit architectures is a 32-bit type on the Windows ABI and a 64-bit type on Linux (LP64 ABI). Codeforces runs on Windows. You wanted1ULL
:(Where did the editorial go?
My solution for A works more than 1 sec. On this test 10^9 10^9 0 10^9 0 Weak tests...
the round was trash never problemset again
How can you be sure if you didn’t even solve B?
plus ur a pupil so you shouldnt set problems at your level
I’m a candidate master, open your eyes :/
Hi, Could anyone tell me why Jury's answer for case 11 of Problem C is 1 ? Since I see there is a horizontal line (value = 1), my answer is -1. [input] 1 0 1 0 1 1 1 1
oh, I missed that increase is zero. TT