Привет, Codeforces!
15 мая в 18:05 MSK состоится Educational Codeforces Round 21.
Продолжается серия образовательных раундов в рамках инициативы университета Harbour.Space! Подробности о сотрудничестве Harbour.Space и Codeforces можно прочитать в посте.
Раунд будет нерейтинговый. Соревнование будет проводиться по немного расширенным правилам ACM ICPC. После окончания раунда будет период времени длительностью в один день, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.
Вам будет предложено 7 задач на 2 часа 30 минут. Мы надеемся, что каждый найдёт для себя что-то интересное в этом раунде.
Раунд вместе со мной готовили Михаил awoo Пикляев и Михаил MikeMirzayanov Мирзаянов.
Анонс раунда — это не единственная новость к этому часу. Передаю слово Игорю Максимову, представителю Harbour.Space.
Мы рады анонсировать второй Hello Barcelona ACM-ICPC Bootcamp, который пройдет с 27-го сентября по 5-е октября 2017 г. в Барселоне. Мероприятие организовано совместно с Центром развития ИТ-образования МФТИ, хорошо известным по сборам в Москве и первым сборам Hello Barcelona ACM-ICPC Bootcamp.
Основная цель Hello Barcelona ACM-ICPC Bootcamp — помочь командам подготовиться к новому сезону ACM-ICPC. Учебная программа рассчитана как на начинающие команды, так и на профессионалов. Сборы будут проведены по двум дивизионам:
- Дивизион A: для команд, претендендующих на медали финала чемпионата мира ACM-ICPC;
- Дивизион B: для команд, которые готовятся к участию в полуфиналах ACM-ICPC. В этом дивизионе участников ждет интересная объемная учебная программа.
Примите участие во втором Hello Barcelona ACM-ICPC Bootcamp!
Желаем удачи в Раунде!
UPD: Разбор задач.
is it rated?
Educational rounds are Unrated.
Problem E is something interesting...
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://mirror.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 :)
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
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://mirror.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://mirror.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.
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://mirror.codeforces.com/blog/entry/21844
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://mirror.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 - Average Sleep Time is acceptable?
How was this hacked for 808D - Array Division ? 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://mirror.codeforces.com/contest/808/submission/27151049 -- C++ 11 http://mirror.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://mirror.codeforces.com/contest/808)
UPD : fixed