Hello Codeforces!

On May 15, 18:05 MSK will be held Educational Codeforces Round 21.

Series of Educational Rounds continue being held as Harbour.Space university initiative! You can read the details about the cooperation between Harbour.Space and Codeforces in the blog post.

The round will be **unrated** for all users and will be held on extented ACM ICPC rules. After the end of the contest you will have one day to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given **7 problems** and **2 hours 30 minutes** to solve them. We hope that everyone will find something interesting in this contest.

The round was prepared by Mikhail PikMike Piklyaev, Mikhail MikeMirzayanov Mirzayanov and me.

Here is message from Igor Maksimov, Harbour.Space University.

* I want to make an announcement of the upcoming 2nd Hello Barcelona ACM-ICPC Bootcamp that will take place in Barcelona from the 27th of September until the 4th of October 2017, in collaboration with Moscow Workshops ACM ICPC, is an opportunity for teams of different levels to prepare for successful participation in ACM ICPC. *

* The Bootcamp will be split in two divisions: *

*Division A. Designed to prepare students to excel and win medals in the next ACM-ICPC World Finals.**Division B. Division B. Designed to help teams prepare for the next season of ACM ICPC Regionals and international competitions. This is an appropriate introduction for teams and students new to the world of ACM ICPC and competitive programming competitions in general. The Division B curriculum features thematic lectures and contests.*

*Harbour.space University introduce the video about the 1st ACM-ICPC Programming Bootcamp held in February, 2017.*

Take a part of the upcoming 2nd Hello Barcelona ACM-ICPC Bootcamp that will take place in Barcelona from the 27th of September until the 5th of October 2017.

Good luck to everyone!

UPD: Editorial is out.

is it rated?

Educational rounds are Unrated.

Problem E is something interesting...

Maybe just servers are too busy or simply too slow... Of course I am kidding!

W=[1,2,3] ??? Oh shi!...

You are downvoting me badly implying the task is actually EASY. But see, even DIV1 coder did not solved it by his/her own, but just COPYPASTED solution http://codeforces.com/contest/808/submission/27140269

Honestly I am surprised more people didn't do this. It was linked to in the first result I found for "knapsack with small weights", link.

But also the code is super sketchy, it didn't work until I added a bunch of dummy elements so that there were always 200,000 elements.

So I guess most D1 coders are too smart to try this :)

It seems that there are infinitely many knapsack problem variations...

C problem, I'ts either I'm not understanding the problem or I'm making an erroneous assumption in my thinking that is making me get WA. I'm happy to learn about my mistake once the contest is over.

You can just overflow cup with maximum volume.

Test:

3 12

4 4 4

Thank you. That was the last piece... ahh I can't believe I missed that last part :)

How to solve E ?

Lets pick K souvenirs with W=3, so we can take souvenirs with sumW <= m — k * 3 (if negative, skip this K). Lets store souvenirs with w=1,2 in one array sorted by decreasing value c / w. So, if we should choose some souvenirs from this array with sumW = x, we greedily takes souvenirs until sumW <= x (after that sumW == x or x — sumW == 1 — in this case we should take largest souvenir with w=1 or remove smallest souvenir with cost w=1 and take with w=2). So, if we iterates over K in decreasing order, we can maintain second value by two pointers technique.

Where is option to hack a solution.

how to solve D??

Not sure if my solution is the best, but it worked: So left part is 0, right is whole sum. Go through the array subtracting from right and adding to left. Add current element to set. Check if left is equal to right — solution is YES. When left is greater than right, check if difference between them is even. If yes, check if difference / 2 is in the set. If yes — we have the solution. (I also made the same thing moving right to left, but I guess it may be unnecessary)

Lets store two multisets(left, right). sum(set) — sum of the all elements in set. Lets add [1, 1] to the left and [2, n] to the right. On the next step there a 2 main cases:

1. sum(left) = sum(right) -> YES

2. sum(left) > sum(right) (if opposite swap the sets). if left set containse value (sum(left) — sum(right)) / 2 -> YES

After this step we remove a[i + 1] from right set and add it to left set.

First of all, maintain for each element y the first and last appearance in the array. Now fix the position i where array will be split.

If sum(1, i) = sum(i + 1, n), we are done.

Else, if sum(1, i) > sum(i + 1, n) we need to remove a element x from (1, i) and add it to (i + 1, n). We will have that sum(1, i) — x = sum(i + 1, n) + x <=> sum(1, i) — sum(i + 1, n) = 2 * x, x = (sum(1, i) — sum(i + 1, n)) / 2. Also x must be integer, so sum(1, i) — sum(i + 1, n) must be divisible by 2. To check if x appears in (1, i), just check if first appearance of x is <= i.

If sum(i + 1, n) > sum(1, i) we use same idea, but now x = (sum(i + 1, n) — sum(1, i)) / 2 must appear in (i + 1, n).

Also check that after moving an element, both parts will be non-empty.

I have never hacked solutions. Tell me please, where to start?

On top of the window with accepted solution source code there is link "hack it!".

I found it) The question is "In what ways I can find weak spots of solutions?"

Hacking is code analysing. You can find weaknesses in usage of data structures, e.g. see thread http://codeforces.com/blog/entry/51989?#comment-360480 kunparekh18 at first for problem D used (just like me) set instead of multiset. I managed to hack mine and his (second) solution with input 6 19 6 5 13 6 13 He uses multiset in his second solution, but it was hacked, because of wrong .erase() function usage (see my comment above). There are known hacks on certain algorithms, e.g. I got hacked http://codeforces.com/contest/792/submission/25847128 because of quicksort. You can probably find generator that generates an array corresponding to the worst case for quicksort (I got TLE on such array). During that contest there were participants intentionally looking for quicksort in solutions and hacking them. You can also observe some rare cases that solution doesn't cover (solution weaknesses). To do that you have to clearly undestand the problem and the code of analysed solution. So hacking skills come with experience.

Thank you so much!

Problem D

t.case 6 5 5 4 4 3 3

Here My output is NO I tried to hack my code, it shows unsuccessful. Also another codes output is YES, I tried and also Unsuccessful! what is this?!

answer for this testcase is NO and your code is giving right answer

Thn why NO?!

In problem A,Can someone suggest why this is wrong. Its giving correct answer on my system but wrong on codeforces custom invocation. Code HERE

It's most probably pow().

http://codeforces.com/blog/entry/21844

I had the same problem, It works when pow is replaced.

How to solve B?

The following link will be useful to solve the problem : http://www.geeksforgeeks.org/window-sliding-technique/

what is the solution of E?

Editorial is published.

any suggestions how this solutions for D was hacked?

http://codeforces.com/contest/808/submission/27138172

Check case

5

1 1 4 1 1

Did anybody else notice that problem E was exactly this problem?

Read statements + constraints again carefully. Also if you look at the editorials, you will see they are very different.

It was more like this one

Output 1E10 for problem 808B - Средняя продолжительность сна is acceptable?

How was this hacked for 808D - Разделение массива ? Is there some test case I missed? Please help. 27143749

you need to use a map or multiset

because when you insert some element in a set 5 times for example and then erasing it once

you are erasing it completely , not decreasing it's frequency

Thanks a lot... I totally missed this!

Function erase(val) of multiset erases all the entries of the element val. To delete an elemnt you have to specify its position, i.e. use iterator.

I am facing a problem ... http://codeforces.com/contest/808/submission/27151049 -- C++ 11 http://codeforces.com/contest/808/submission/27151003 -- C++ 14 Same code, gives WA on case 3 and case 2 respectively, but on my PC, both cases give correct answer.

Hacking STL Hash set/map is ridiculous: even if this time unordered_set/multiset/map receives TLE (because of collision), next time in a normal CF round I'll continue using unordered_map/set. It's ~4-5 times faster than ordinary map/set (in normal cases — test data is generated before I submit my program.)

I haven't read the problems but surely most of the time, whether or not you use unordered_set/map is largely orthogonal to the main point of solving the actual problem. So if you choose to use a data structure which is known to have a bad worst case, you really have no one to blame but yourself (and yes, even normal CF rounds have anti-hashing cases).

But if for some reason you need the extra speed, you can just generate a random number and xor your usages of the unordered_set/map with it to prevent it from breaking on specific known cases.

My O(N) solution for the problem B failed with TLE... Apparently reading from 'cin' into a double variable is slow enough to make it potentially fail even on 2*10^5 reads.

Reading from 'cin' into an integer took 124ms: 27174013

Reading from 'cin' into a double took 842ms: 27174024

Also my solution 27126612 failed on system tests with TLE. Exactly the same code 27174040 got accepted later in the practice mode.

Why there is no Contest materials box in Educational Round 21 page? (http://codeforces.com/contest/808)

UPD: fixedI want to hide myself so that no one can see me in online.

is there any system to do this??????? How??????