Привет, Codeforces!
В Dec/18/2021 18:35 (Moscow time) состоится Educational Codeforces Round 119 (Rated for Div. 2). Пожалуйста, обратите внимание на необычное время старта.
Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.
Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.
Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.
Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов, Максим Neon Мещеряков и Роман Roms Глазов. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.
Удачи в раунде! Успешных решений!
Также от наших друзей и партнёров из Harbour.Space есть сообщение для вас:
Привет, Codeforces!
Почти 5 месяцев прошло с тех пор как мы организовали Harbour.Space Scholarship Contest 2021-2022. Это был довольно сложный вызов для более чем 15 000 человек, принявших участие в раунде. Однако мы смогли отобрать тех, кто был готов воспользоваться возможностью и присоединиться к Harbour.Space в этом году. Помимо этого мы внимательно рассмотрели все заявки на стипендии и наградили в общей сложности 11 студентов.
Мы хотели бы представить вам наших обладателей стипендии, которые уже прибыли в Барселону:
aniervs, MaksymOboznyi, 244mhq, Meijer, bthero,amanbol, DimmyT, 998kover
Мы с нетерпением ожидаем достижения невероятных высот нашими новыми командами ICPC. Одна из них, Harbour.Backspace (MaksymOboznyi, 244mhq, 998kover), уже занял З-е место в Moscow Workshops. Желаем им всего наилучшего во всех предстоящих раундах.
Как и всегда мы будем очень рады видеть участников сообщества Codeforces как наших студентов здесь в Harbour.Space.
UPD: Разбор опубликован
Excited for the contest, Wishing everyone high ratings in last Educational Round of 2021.
> last Educational Round of 2021
he doesn't know
-_-
No please don't say that
liar
forward Kazakhstan
alga kazakhstan
Always love educational round.
Please, note the unusual start time.
ok at this point I got lost, what's the actual usual time!?
17:35(Moscow)
unusual unusual time(you know,usual unusual time means before 17:35)
The start time in China is too unusual!
.
Shouldn't it be BYE BYE educational 2021 XD...
cheaters who registered in this round: nitin_05 ashokesen02
Why you just keep on posting same thing again and again in every contest's announcement.My advice to you is not to focus on others whether they are cheating or not rather you should practice more and more to surpass those cheaters. And for cheaters they can become expert or CM by cheating but ratings without having knowledge is of no use they can't use it anywhere be it in Online tests,interviews.
So just focus on developing skill and you can see positive outcomes after sometime :D.
He is a spammer posting about scammers
SIUUU
Wasn't this time the usual one now it became unusual
Why so negative?
I hope this round will be excellent! (as usual <3)
Hope this time my rating will increase and my contribution rating will not go more negative.
C should not exist
A was harder than C, change my mind lmao
I m not able to understand the 3rd test case of the C problem we can at max replace all '*' with 'bbb' and then also the rank will be 16 but it is asking for 20? Help me understand it. Be merciful on me.
If I am not wrong for the third test case of C
6 3 20
**a***
output -- babbbbbbbbb The strings are --btw was not able to solve it.. RIP
The number of possibilities is not 16. In the first group of asterisks, we can have at most 6 'b'. In the second group of asterisks, we can have at most 9 'b'. So, the total number of possibilities is (6 + 1) * (9 + 1) = 70.
You can fix the first group of asterisks with some number of 'b'. Then, you can have 10 different strings as you can adjust the number of 'b' in the second group of asterisks.
C is in a difference lever :v
Please any one give me a hint to solve E ??
linked list
its actually just basic implementation [too easy for position E, I think].
For each query of type-1, find the nearest to the right query of type 2 which has the same $$$x$$$ and add an edge between these two indices. For each query of type 2, find the nearest to the right query of type 2 which has $$$x$$$ as the $$$y$$$ of current query and add an edge.
this structure forms a forest.
Then the value of each type 1 query in the final array is just the value of the root of the tree this index is a part of.
Try to build array by performing actions given in input in reverse order and store some useful information.
You can store for each x, all indices that have value equal to x in a vector, let's call it v[x].
For the queries: set all elements equal to x to y, you can move all the elements from v[x] to v[y], use small to large to do this.
So it will be O(n^(3/2))?
No, it will be $$$O(N\cdot\log{N})$$$, each time you merge two vectors, the resulting vector will be at least two times the size of the small vector, so each element will be moved from a vector to another at most $$$\log{N}$$$ times.
Note that you swap the vectors if needed to move always from the smaller to the bigger, just using swap is $$$O(1)$$$ for most stl containers, like vectors, sets, maps.
Wow, interesting, thanks. And in this problem we could kinda do it in O(n) using deque instead of vectors, right? Since merge of deque is O(1).
Are you sure that deque's merge is O(1)? cppreference doesn't mention it, and considering how deques work, I think it is complicated to do it in O(1), I am not sure tough.
With a conventional double linked list you can do that, but I think deques are something more complex.
Crap, I thought deque in c++ IS a conventional double linked list. Thanks for pointing out. Now I need to go and check if deque id double-LL at list in my python... :)
I think simplest solution is to iterate the queryies from last to first. We maintain a transision table, no tree or something complecated needed.
see 139792544
My solution uses array of linked lists.
For query of the form
1 x
, we add index ofx
(which is equal to current number of appended elements so far) to the end of the linked list located atarray[x]
.For query of the form
2 x y
we move all elements of the linked list located atarray[x]
toarray[y]
.At any given point,
array[val]
stores all the original indices which ended up holding the value ofval
. https://mirror.codeforces.com/contest/1620/submission/139814623If you execute the operations from the last going backwards you can keep&update a mapping for each number quite easily. At the start, mapping[x] = x for every x. Then:
then print reversed(result)
I didn't have time but I think problem G can be solved using inclusion-exclusion for each mask of subsequence [where the value of each mask represents the number of strings which are subsequences of all strings which have bit set in the mask]. Is it the right idea?
Yes, I solved it in this way.
I tried to do it using inclusion-exclusion.
Struggled with MLE
Used vector of size 1<<23 * 26. Got MLE https://mirror.codeforces.com/contest/1620/submission/140442689
Changing vector to arr(local variable) didn't work. Again changed the vector to global array. It got accepted
https://mirror.codeforces.com/contest/1620/submission/140443390
Can E be solved with some modification to dsu?
Yes, you can solve the queries in reverse by storing the most recent parent of each integer $$$x$$$, then whenever you find a query of $$$type$$$ $$$1$$$ you should add the parent of $$$x$$$.
Solution code: 139832507
thamks so much. what does this mean:
if(~qr[i].second)
what does '~' do?if (~qr[i].second)
is equivalent toif (qr[i].second != -1)
Can I improve my delta by hacking someone else's solution?
No
Actually, you can , if you hack someone else's solution whose ranking above yours.
OK... If predictor is right I need 5-7 more delta to become expert. Roughly, how many solutions should I hack to get it?
all of them :)
I eagerly wait to know the author of problem D
I just needed one more minute to submit my solution.. ://///
I didn't get AC for B until there was exactly 1 minute left because I used int instead of long
It's because Base*Height may exceed int range.
HELP nitin_05 cheated again!!!!!
139758679 139767791 139800928 139812299
The attempt was so blatant lol, Dude commented the block of code and then wrote the same code and thought that he wouldn't be caught by the CF plag system.
The first thing any plag tool does is to wipe off all the comments, spaces and indents and read the code as one single line.
How dumb can one be.
Was I the only one who found E much easier than both C and D.
No.
12 wrong submissoins on C. I just want to die
please don't die
metoo.. still don't know why the 4th test case doesn't work out -.-
My 4th test case is wrong due to integer overflow.
I am doing suffix product of an array which lead to runtime error
https://mirror.codeforces.com/contest/1620/submission/139859032
Handled the overflow here
https://mirror.codeforces.com/contest/1620/submission/139860338
Thanks, it was helpful.
I learned that lesson ones or twice (or more?) and now I try to avoid the guess game — today (again) I had to write a tests with brute force function that generates all possible strings for a small templates, that can be easily understood. Sorted them and compared to my solution for every X. 15 extra minutes was enough to find I had >= instead of > in some place. Some times I search for this 30 — 45 — 60, but it is definitely giving me more than wild guessing.
My approach for Problem E: Replace the Numbers
The idea is pretty similar to 365A: Knight Tournament
Suppose an element $$$x$$$ is appended to the end of the array at the $$$j^{th}$$$ query. We can make the following 2 observations:
So, if we process the queries in reverse order, then by the time we reached the $$$j^{th}$$$ query (counting from zero), we would have all the information to restore the value of $$$x$$$, if we keep overwriting the values of $$$x$$$ in case of overlapping Type-2 queries.
So, if we define $$$sink[x]$$$ as the value that $$$x$$$ should be currently converted to, we can process the queries as follows:
Finally, reverse the $$$result$$$ vector.
Implementation
I tried using DSU (along with a hashmap and a pointer array), but am getting WA on Test 4 itself.
What could be wrong with my code?
My Submission.
Thanks.
Try this simple testcase
1
1 5
The output's 5, as expected...
How to solve E?? is there any way to pass test case 5??
no, there is no way to pass test case 5
I took more than an hour to solve C but only 7 minutes for E.
Please, help me. Why I get WA on C: https://mirror.codeforces.com/contest/1620/submission/139816488 ?
I think many people passed G with $$$O(26*n*2^{n})$$$, but it wasn't intended right?
Unfortunately, it was hard to cut all of them off. The model solution works in $$$O(2^n \cdot (n + A))$$$, but its constant factor is kinda big so I couldn't set $$$n = 24$$$. In retrospect, perhaps it would be better to swap F and G and set something like $$$n = 20$$$ instead of $$$23$$$.
Yeah, my complexity is the same. Yes, swapping F and G could have been better.
How do you do it with that complexity? Is it even easier than $$$O((n + 26) 2^n)$$$? I can't imagine a solution where it is not immediately clear how to optimize.
Lol me too, but I think what some people did was to calculate for each mask, the contribution of each alphabet by iterating on all set bits instead of using the precomputed values and taking the low bit of mask.
One of the approaches I tried to cut off was based on the following dynamic programming:
$$$dp[i][mask]$$$ — the number of different strings consisting of the first $$$i$$$ characters of the alphabet such that they are subsequences of every $$$s_i$$$ from the mask, and are not subsequences of any other $$$s_i$$$, with $$$O(A \cdot 2^n)$$$ states and $$$O(n)$$$ transitions from each of them.
I used dsu like you in E but m getting mle and I have no idea why
can anyone look into this .This would be a great help I encountered such thing first time my submission
For starters, you can look at this testcase
thts ok but I was getting mle constantly , I dost know its reason
same here. my solution. https://mirror.codeforces.com/contest/1620/submission/139812356
Not entirely sure about the reason for MLE, but your code does produce SIGKILL runtime error on the following input.
I see a lot of contestants getting MLE on TC4, I wonder if they are making a similar mistake or it's the nature of the test-case. Do let me know if you figure out the reason.
infinite recursion in happening which is leading to stack overflow which is the reason for mle ig
Thank you. That makes sense.
thnku very much
Getting ready for a -100 LOL :p
I don't understand the gap
I don't understand the gap
I'm curious what's test 2 here that's causing WA.
https://pastebin.com/41BJXM9H
how to solve A?
Please don't ask me :((
Let $$$cnt$$$ is the number of $$$N$$$ between $$$s_i$$$ and $$$s_{n-1}$$$.
Try to simulate some test cases to figure out why this solution works:)
Why so tight constraints! :/
solved D after contest ended 3min :D
Same dude, 1 minor mistake let maxx be the biggest element in array i didnt check if there were any maxx-1 — s elements in the array if maxx%1=3
No greedy,that I cannot solve any problems.
One Doubt , I submitted 1st Accepted Solution to C at 1:08 and second at 1:18 if the first one gets hacked or FST , the second one's final verdict will decide my rank ?
The second one will contribute, the first one is kind of nullified by your second submission.
Thanks , In non educational Div 2 Rounds , Penalty for multiple submission (correct or incorrect ) is added in the standings while here no additional penalty is showing currently .
I would have expected 10 minutes penalty per submission, the first one is free. But not sure.
Why is there TL on 5 test? Submission: https://mirror.codeforces.com/contest/1620/submission/139803575
Because your complexity is not good?
can you tell me what is the time complexity link of this solution, according to the constraints shouldn't this give solution gives tle?
It's $$$O(q \log q)$$$.
It uses small-to-large merging, unlike the person I replied to. Basically this line is very important:
if (y.size() > z.size())
. It can sound unintuitive but in total, every element gets copied from one vector to another only $$$O(\log q)$$$ times (it's similar in the idea to HLD and union-by-size in DSU).If an element gets copied from
y
toz
andy
has $$$k$$$, then after copyingz
must have at least $$$2k$$$ elements. If this element is later copied fromz
tox
, then after copyingx
must have at least $$$4k$$$ elements and so on. Basically every time an element is copied from one vector to another, the size of its container at least doubles, which means that it is impossible for it to be copied more than $$$\log q$$$ times.So in total it's $$$O(q \log q)$$$. Also
y.swap(z)
takes constant time (I didn't know this) so no worries there.Really hard test case 3 in problem C for my small brain :(
WORST round EVER!
Emplemetionforces and speedforces combined
bruh
Actually this is more or less the defintion of educational rounds. If you do not like this you should not participate in them.
lmaoo, no bad comments today because you performed well, sucker!
I love you, too, idiot :)
bruh
that was my third educational round for the last year or so
I didn't get D... Somebody please explain the third and fourth case
4th test case: 2 * 3 + 3 * 257=777
Why not 3*259=777
That way you can't buy 7
Then you can't buy the bag that costs 7 or the one that costs 77
C has an overflow issue.. I got too many WAs because of overflow issue
Same :( I spend like an hour trying to find what to issue was, only to realize after the contest that it was overflow :(
D drove me mad...qwq
Why my solution got Memory Limit error? I couldn't see what is the problem. https://mirror.codeforces.com/contest/1620/submission/139812356
very cool problems! managed to solve A,B and C, and it somehow felt like A stumped me the most. thank you for a good round.
I'm surprised nobody mentioned a solution using DSU for E yet. It's the first thing I thought of, could there be something wrong?
I solved using DSU. But somehow my solution got Memory Limit error. And i don't know why. Here is my solution. https://mirror.codeforces.com/contest/1620/submission/139812356
I processed the queries online with DSU. https://mirror.codeforces.com/contest/1620/submission/139790412
I think D and E should have been swapped. E was as simple as simulating the process backwards.
Is there an etalon solution for problem E in Python3? My solution is O(n) but it exceeds time either on test 13 or sometimes on test 17 sometimes, even with fast IO
Tried it in Python first too, got 2 TLEs, wrote the same code in C++, got AC.
Damn Python :)
There is a lot — check out submission stats for a problem — and you can just switch to pypy3 sometimes it helps. is yours code AC in pypy3.
PS. And to add: you are creating a lot of objects (lists) to encode input. Try to simplify it and get rid of them.
P.P.S. Or maybe not and I am wrong (about creating a lot of objects) — cause your solution is faster than my when I run it on PyPy :)
PPPS. Oh, no, I was right, but you have reall-really-really good "fast-input". My solution become twice faster with it — thank you very much!
Can someone help with this submission?
https://mirror.codeforces.com/contest/1620/submission/139828156
I think you have overflow issue.
Why is my code for C TLEing? 139829242
I think my complexity is O(n*k), where n<=2000, k<=2000
A given string may have b, but your program did not consider it.
"...that consists only of characters 'a' (a lowercase Latin letter) and '*' (an asterisk)."
You are overflowing LLONG_MAX (9e18) on the line
temp *= (v[i]*k)+1;
. This is undefined behaviour and you are TLEing because of this. Be sure to make sure thattemp
is not overflowed.Thanks, took care of it and it passed. My dumb ass wasted too much time on this foolish mistake during the contest ;_;
This "hack" is borderline hilarious.
haha~
C >> D
I don't know if the intended time complexity of the solution for D is $$$\mathcal{O}(N)$$$, but checking only 7 possible patterns for cost of each bag receives AC verdict.
(maxm, 0, 0), (maxm, 1, 0), (maxm, 0, 1), (maxm, 2, 0), (maxm, 1, 1), (maxm-1, 0, 2), (maxm-1, 1, 1) where maxm is value of the maximum element divided by 3 and each tuple represents the number of coins of denomination 3, 1 and 2.
Can anyone hack this solution? Submission:
That is correct, in the optimal answer you get at most one 1-token and at most two 2-tokens.
That is because you can always break two 1-tokens into one 2-token and break three 2-tokens into two 3-tokens thus getting a better answer always:
1) (1+1) -> (2)
2) (2+2+2) -> (3+3)
Also, whenever cost of any bag is 1, we need to ensure atleast one 1-token is present.
Can anybody tell what I am doing wrong in C. solution link — c
Your answer gives
abaa
. Correct answer should beaaa
.Thanks bro.
Can someone explain why my memory limit is exceeding in my solution for C 139817111
How to solve problem F?
I passed C after the contest when i used unsigned long long rather than long long. Codeforces doesnt support cry emojis
Thank you, too good to goodbye for 2021.
Am I the only one who found C much easier than D and E?
Why are contestants with ratings greater than 2100 being shown as official participants? will they be removed from the official list and then acc. our rating change will be calculated?
yupp.
E can be simply solved by small to big technique. just merge. here is my submission 139852514
Oh great i didn't knew that it is some technique. Well i discovered already discovered technique.
Well, it only becomes "technique" when you prove it's complexity.
The Rating Result?
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
looks like problem A was the only problem nitin_05 could solve without buying solutions. XD
he got skipped except A
That problem not being skipped has worked to his disadvantage.
If all the solutions would have been skipped then he would have no valid submission and the round would become unrated for him. However the solution for problem A not skipping means that the round is rated for him and due to only 1 correct submission , there's a huge negative delta.
Hello
I was suspected to cheat on the problem A with Shanto65 and atau004.
As you can see in this problem, it is very probable the everyone use this idea(and use a variable called cnt).
Dear codeforces please review this again(by the way i didnt use ideone or something like that).
Fake Plagiarism check to ban me from my own account. TheThinker_08. This has now happened several times. What you cant even write your own code now. And The other guy @Paul_Liao_1457 got no penalty just cause his score is greater than mine. please just look into this I didn't do anything wrong or copy from anywhere still got a plagiarism check and got banned just what is this
Why I didn’t get penalty is because I solved the problem earlier than you.
I have a question about E. in my opinion i have O(n) solution, but it gets TL at 5th test, can someone tell me what's wrong? Is it solution or it's just Python can't make it.
https://mirror.codeforces.com/contest/1620/submission/139826532
You are right about time complexity of your solution. What you are missing is that using input() for 500_000 of entries is too long. Look into other solutions to see "fast input" for python. Here is your solution with 1 variant of fast input: 139998877
PS. And this fast-input: 139999694 I have just found in sur's solution is even better — it just made my solution twice faster. Thought, you should be careful with what you get — there will be unprintable symbols in your input.
Thanks a lot, really appreciate it!...missclicked upvote(