I am so sorry about very long gaps between the contests but I really don't have enough time to prepare the problems. So...
<copy-pasted-part>
Hello!
Codeforces Round 521 (Div. 3) will start at Nov/16/2018 17:35 (Moscow time). You will be offered 6 or 7 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. Probably, participants from the first division will not be at all interested by this problems. And for 1600-1899 the problems will be too easy. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.
The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.
You will be given 6 or 7 problems and 2 hours to solve them.
Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.
Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:
- take part in at least two rated rounds (and solve at least one problem in each of them),
- do not have a point of 1900 or higher in the rating.
Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.
Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round.
Good luck!
I also would like to say that participants who will submit wrong solutions on purpose and hack them afterwards (example) will not be shown in the hacking leaders table.
</copy-pasted-part>
UPD1:
Congratulations to the winners:
Rank | Competitor | Problems Solved | Penalty |
---|---|---|---|
1 | diolG | 7 | 173 |
2 | lyzqs | 7 | 228 |
3 | pvviet001 | 7 | 241 |
3 | LVL | 7 | 241 |
5 | lukameladze1 | 7 | 250 |
Congratulations to the best hackers:
Rank | Competitor | Hack Count |
---|---|---|
1 | awoo | 153:-6 |
2 | ______-__________-______ | 186:-85 |
3 | knowbody | 128:-6 |
4 | Laggay | 113:-6 |
5 | MarcosK | 66:-6 |
1359 successful hacks and 755 unsuccessful hacks were made in total!
And finally people who were the first to solve each problem:
Problem | Competitor | Penalty |
---|---|---|
A | Laggay | 0:01 |
B | Laggay | 0:03 |
C | ilya_kuzmin | 0:05 |
D | Laggay | 0:12 |
E | ilya_kuzmin | 0:12 |
F1 | Greninja. | 0:29 |
F2 | Radko | 0:32 |
UPD2: Editorial is published!
What happen for Div. 3 contests if we haven't vovuh ?
Thanks vovuh and also thanks creator of copy-paste (Larry Tesler) :))
earlier i used to think that i could solve 4-5 problems in div 3 rounds as it would be easy with div3 tag , but now i knew one thing "dhoka hai ye , ek trah ka jaal, shajis hai hamein nicha dikhane ki, haha div3 tag XXXDDDD", don't take it offensively it's just a joke, i love codeforces.
What a nasty comment...
haha, same, man
Translation?
Meh, languages used are part of the joke. You'll have to believe me that it's funny and highly relatable)
So i opened the refrigerator, took a tomato, a cucumber,a greenery, wanted to make salad. It is obvious the salad should be made with mayonnaise (else who who would eat it?). I cut all and realized I forgot the mayonnaise. i opened the refrigerator again, took the mayonaise and suddenly realized that there is some lard in front of me. I have never eat the lard, but i suddenly i wanted it. While I filled the salad with the mayonnaise , cut the lard, ate it and suddenly all (*something in Ukrainian)
This could be used as a problem statement starter XD
haha classic
Pardon me this is my first rated(hopefully) Div 3 contest. Why is this rule there?
I also would like to say that participants who will submit wrong solutions on purpose and hack them afterwards (example) will not be shown in the hacking leaders table.
They will be considered in leaderboard table though?
If they solve problems fairly then yes, they're will be shown in the leaderboard. This rule is there just to exclude the people who want to be top-5 by unfair hacks.
what's the benefit of hacking someone's submission ? does it increases rating or points?
I don't know but I'm sure that X3NNY knows (but I think that he was framed and this is just coincidence)
I just want to lose Rating, no harm.
How to get reminder for this type of contest?
i just set https://clist.by/ as my browser home page
I hope this div3 A will not be harder than div2 A as always
edit:finally it's not
today I'll become blue. screen it
oh! really ? 乛◡乛)
Good luck, I hope u can achieve it.
I will become green B) screen it
I too will become green this time :P
You lied. No rating change for you ;)
I will next contest don't worry
lol, guys, 2 rating units. I got 113 out of 115 needed))))
so,why u create flag before the contest ? 乛◡乛)
it was my purpose. I feel like I could turn blue.
1598 so close XD
After Hacknig xD
Don't post these kinds of shitz next time >(
this is not shit, this is good for all
Hell stop it -_-
Thanks, vovuh !!
Can someone please tell me why my submission for F is getting TLE on test 41 ? Used deque and dp.
I can't believe I wasted that time on C that feels incredibly stupid XD
edit: and it's WA XD
Is E binary search?
No, but D is
How to solve D?
Observation: Suppose from an array you can remove a number of value 'v' X number of times, you can also remove it X — 1 number of times,
Basic division and function check on this monotonic function gives you AC. Didn't code this because my implementation skills are bad. But pretty sure this approach is correct.
I have solved this greedily using priority queue with sorting on the basis on how much more copies of a number we can get if select the current number since we have to maximize the minimum frequency of taken number Code: http://codeforces.net/contest/1077/submission/45823855
it is.
I solve E with lower_bound in c++.I think it's the same as binary search.
Can you explain your approach?
is your solution have two logs ? Is it works by using binary search(or lower_bound) in every possible numbers of competitions?
Yes,there are two logs,one is the number of problem ,one is lower_bound
I solve D and E with binary search,but I am not sure it will not be hack
What is the solution for problem C ?
Start from left of the array and if there is a zero in between two ones, remove the right one. Let this be ansA, do the same for the reverse array and let the answer of that be ansB. Final answer is min(ansA, ansB).
Sorry this is for B
This is the solution to problem B Not C
Sorry,
For C: Let sum of whole array be S, then in a vector store pair of <value, index> sort this in descending fashion,
if you are removing first element of this vector, your remaining sum is S — v[0].value. remainingSum — v[1].value should equal to v[1].value.
else your remaining sum is S — v[i].value. remainingSum — v[0].value should equal to v[0].value.
Can you please Illustrate more ?
essentially there are a couple ways to create a good array, both can occur though.
type1: removing the largest value, hence the second largest value will have to be the sum of the remaining digits, excluding the originally biggest number (and the second largest of course).
type2: removing a value (that is not the largest), to make the sum of all the other values equal to the largest.
you can check for both types, which is what i did.
For B, I think ansA will always be equal to ansB, so there's no point in calculating both of them. If I'm wrong, can someone please suggest a test case where ansA ≠ ansB?
Observation: We are checking if removing an element from the array can make the max element equal to the sum of other remaining elements. And in case we are removing the max element, we are just checking if we can make the second max element equal to the sum of other remaining elements. (Since there is no element with -ve value) So, we just have to find out the max and semi-max element and then iterate the array removing each element at a time and checking the above criteria.
for example, a= [5,2,1,3] Max= 5, Semi Max= 3 Removing 5(Max), a=[_,2,1,3] makes Semi Max, 3= 2+1 Removing 1, a=[5,2,_,3] makes Max, 5= 2+3 These two are only bad indices in this example.
How to solve the hard version of problem F ?
dp[number added][last added]
Naive transitions work in O(n) for a total of O(n^3). If we use sliding window for each layer, we can transition each layer in O(n), for a total of O(n^2).
Did anyone manage to AC E with dp in O(nlog(109)log(n)), something like this?
For E: Store the frequency of each topic in array and sort that array. Then let say we fix the no of topics in first contest be i, then binary search on this array to find if there exists a topic with frequency greater than i, if yes then take the leftmost topic and set it as new index (initially index is 0) and then check for 2 * i and repeat the process. If not found, just break at that index. Repeat the process for new i. Code: http://codeforces.net/contest/1077/submission/45834476
Relief :)
How to approach D? what i did, first i count the frequency of every number and then i put them on a pair, but then i could not find any way that how to go further!! i could come this much :(
I think recursive find() function that continuously divides possible region for k in half might solve the problem in O(nlgn), but I ran out of the time...
It's easy to find an array that can by cut out x times. So just do a binary search for the biggest valid x.
Is it intended in F2 that using segtree gives TLE but other data structure like sparse table gives AC?
No.
AC with segment tree (1731ms).
I think O(n^2) solution with a queue which supports amortized O(1) maximum extraction was intended.
Why on problem F the condition if((k*2-1)*x<n) cout<<-1; isn't enough to detect if it's impossible to solve?
condition is (x*k + k -1 < n) print(-1)
C Wrong answer on test 3, but I got right answer local.... Why?
maybe because you need to write bool exist=false;
if you don't it will take arbitary value
Mike bhaiya meri rating kyu nahi badh rhi? ye codeforces hi bekaar hai
Plz someone explain me, why 45840553 is TL 16 and 45840575 is RE 1 ?
Your
cmp
function does not define a "strict weak ordering", whichstd::sort
requires. The short version of the explanation is that your predicate should behave like<
and not like<=
.Failing to meet this requirement causes undefined behavior, which basically means that the verdict may vary arbitrarily.
P.S: there might be other problems with the source, this is just one I have noticed.
Thanks a lot
What is the hack for C? A lot of C's solutions are getting hacked.
Answer:
The reasons for WA are various as for all of the following outputs I found a solution that produces that output:
It seems that I was the only one who misunderstood the statement for problem B. Can anyone tell what is it really asking for ??
me too bro :(
The question asks for the minimum lights you have to turn off for all peoples "sleep well".
If only I had known that before. I thought they were asking how many different pairs of lights I needed to turn off (turning off a single pair), in order for no people to be disturbed.
same, the pairwise distinct stuff confusing me, i think that for sample test 1 answer should be 1 because it only need 1 pair to make not disturbed array,
wasted so much time understanding this problem >:(
What's the benefit of hacking someone's submission in Div 3? Does it helps in increasing rating?
No, it doesn't help to increase the rating.
But you can overtake some peoples and then your rating will be higher
Their code will fail at main tests anyway :)
Some people enjoy this :) And for cf: you don't need to test some solution if it already failed
I tried to hack a solution (It makes 10^12 operations worst case) but I got unsuccessful hacking however the code I tried to hack takes 128s on my machine itself (with T = 100 , it is 1000 in the test case). I want to ask if hacks are only successful if the code gives WA ?
EDIT : here is the link https://codeforces.net/contest/1077/submission/45824799, he is looping from 1 to k/2 when a != b.
WoW ! Looks like CF is real fassst.
Can you give the link of solution?
added
Then you have a different version of the compiler. On my machine with GCC 7.2.0 it runs almost instantly.
EDIT: Actually, you need to have -O2 as a tag for the compiler to make the solution fast, compiler version doesn't matter.
Did it run instantly on a case where k ~ 10^9 and T ~ 100/10 and a!= b?
Yes. Did you add -O2 as a compiler tag?
Yes , I added that tag and it took about 10s(for t = 100).
Though I still dont get that how can it not give TLE since he loops from 1 to k/2 (1e9/2) for every case with a != b.is CF insanely fast or something since I dont see this passing anywhere.
See my reply, and learn compiler theory.
-O2(at least on my machine) notices that the program increases a number "sum" by a-b l times, so it replaces that part of the code with increasing "sum" by (a-b)*l.
:O nevermind. Thanks for your help.
You can see the optimised assembly here: https://godbolt.org/z/piYeZH
Compiler optimizations. P.S. This is what happens when a person jumps right into the programming, bypassing the CS.
I read some code and want to hack them. But now my head are getting hacked...
Can any one tell me why my solution for E is getting TLE on TestCase 51 I think its Nlog(n). http://codeforces.net/contest/1077/submission/45845419[Link to submission].
You're using unordered_map; if you replace it with map, you should get AC. unordered_map can sometimes be slow, you can read more about it here: http://codeforces.net/blog/entry/62393
Thanks a lot.
why sometimes there's 3600 participants and sometimes 5000 :/
that's not the first time this happens
In problem E: why is this approach is wrong?
please tell me that why this 45850644 passed and this 45850660 failed ..they are almost please help!!
Problems like Dick
What's wrong with std::list? I used sliding window algorithm for F2 and I used std::list to implement it but I got MLE. So I tried to cut down memory by making D[2][5000] instead of D[5000][5000] and I got accepted. But when I changed std::list to std::deque, it was accepted and even faster! In another OJ sites I usually use, std::list is faster than std::deque so I thought it would be same here. Can anybody tell me why?
MLE code : 45823888 AC code : 45852635 Here is my code.
Maybe list need some extra space to save pointer?
I think so. According to my short experiment using both std::list and std::deque, std::list is faster than std::deque but drains tons of memory. std::deque, on the other hand, uses less memory but slightly slower. There might be something wrong, so if somebody finds anything new, please let me know.
Well... std::list is a doubly-linked list, so for every element in it of type T is uses two pointers and one field of type T.
std::deque on the other hand is basically a linked list of increasingly large vectors and uses (more or less) the same space as a vector.
As a very rough approximation, if T has the same size as a pointer, std::list will use more or less 3 times more memory than std::deque. Nothing wrong with it, it's just the way the structures are implemented.
P.S: Bjarne Stroustrup (the creator of C++) has a very interesting talk on why you should avoid using linked lists. They have their uses (mostly when deletion in the middle is involved), but you should avoid them whenever you can use pretty much anything else.
If there is any one want to hack somebody, you can try to hack HunTer's problem C solution, he didn't use long long instead int lol
I did 42 successful hacks but didn't get increase in my rank....how it'll be beneficiary for me?
in div1/2/1+2
this is education mode, you can't get any beneficiary from successful hack
Comment not applicable
in few hour i guess
it seems it is already release
I was solving the 3rd problem of round 521 div 3. Problem Link: http://codeforces.net/contest/1077/problem/C As mentioned in question's description that a[i] <= 10^6 but test cases don't follow so. I used frequency array and got runtime error. On the other hand, using map got me AC. Please clarify if I am wrong. Diagnostics: https://imagebin.ca/v/4MtAcprEnUbw RE sol: http://codeforces.net/contest/1077/submission/45860663 AC sol: http://codeforces.net/contest/1077/submission/45862293
Even though a[i] <= 10^6, sum can be greater than that, so your line 42 where you tried to access pre[(sum-a[i])/2] would make you RTE
faced the same issue.. thanks a lot :)
I was solving the 3rd problem of round 521 div 3. Problem Link: Problem C I don't know why I'm getting wrong for test case 86. But getting right on my local machine here is the code link Solution.
ThankYou.
Magic has been hided after the dots, last number of the input is 532704.
But still getting right on my machine.
Then it isnt that testcase, but you're wrong because m is mapping from int, m[temp/2] will be truncated to m[int(temp/2)].
Thankyou The map is taking some random key with 0 value. Just handled and got ac.
But why it will take random key instead of taking only the int part(maximum bits that can hold by int type)
For his code the error is int overflow only, just change m's type to <ll,int> and that will AC.
the constrain allow to 10^6 why change this give AC?
individual element is is under 10^6 but theirs sum may be not.
this 45822434 gives me correct answer for question D in my IDE but this is wrong answer.
can any body say why?
Huge difference between cf-predictor & actual rating change!! What's wrong today?
if you "hack" someone by sending inputs that are meant to fail the code you get 100 points if that attempt was successful, likewise the person that was "hacked" will loose their points for the question, as their attempt will be considered a failure. I got hacked and dropped a rank because of it i feel.
Any of my solutions wasn't hacked here...
I think it's because the predictor is considering non-trusted participants on the calculus
MikeMirzayanov in predictor, my increment was +98 but i was increased by +77 in change rate why ??
Same for mine too...it was showing +61 but actual increase is +39
In this round CF predictor shows my rating would be +103 but actual rating increased by +73 :( :( can anyone please tell me the reason why it happens ???
vovuh I get WA on problem C with solution 45813685 , but get AC with 45865201. The map might taking some random key with 0 value as I declared map<int,int> and the data can be long long. But why it will take random key instead of taking only the int part(maximum bits that can hold by int type)??? I have checked in the Codeforces custom test section with that test case. It gives same answer as jury's
same with my solution 45813690 why this fail, and when change map to ll get AC?
can any one tell me why my solution for E is getting TLE on testcase 54? complexity O(n log^2) http://codeforces.net/contest/1077/submission/45868358
http://codeforces.net/contest/1077/submission/45868135 Accepted used multiset.lower_bound instead of lower_bound can anyone help why lower_bound is slower in the documentation both function complexity is O(log).
No, you are wrong. For non-random access iterators lower_bound is O(N) in complexity so lower_bound on set/multiset will be O(N) while set/multiset::lower_bound would be O(log N).
Read Complexity section of the cpp reference http://www.cplusplus.com/reference/algorithm/lower_bound/
Where can I find the editorial/tutorial for this contest?
as for now not released yet
when will it be released?
In a few minutes, bro, just wait a bit :)
Can somebody explain O(n^2) solution for F? I've seen solutions with sliding windows using deque but I don't quite understand logic behind it.
I explained it some time ago on stackoverflow: https://stackoverflow.com/questions/12054415/get-min-max-in-o1-time-from-a-queue
I don't see the tutorial.Can you give me ?
My solution to D without binary search passed — https://codeforces.net/contest/1077/submission/45884322 Are the hacks not included in the final test cases when the problem goes into practice section?
Hmm, it is really weird. I will add the test on which your solution will got TLE. It is very strange that nobody do it during the hacks phase. (And even more strange that I don't do it before the round start. Sorry about that.)
UPD: Woops, this solution got TLE now.
Weird :p Does this mean that this solution would have gotten Accepted in the main contest?
Yes, it was accepted in the main contest, unfortunately. I have nothing to hide. Sorry :(
HI in the last two contests thst i've taken a problem that i solved correctly got hacked.does anyone know why?45824931
i think div 3 and div 2 contests are same in quality except problem A
Whats wrong with my logic for A here:
You have to use integer division (
//
) instead of float division(/
)