Hi everyone!
The sixth round of COCI will be held tomorrow, April 9th at 14:00 UTC. You can access the judging system here. If you are not familiar with the COCI contest format, we encourage you to read the announcement.
The round was prepared by ominikfistric, Bartol, pavkal5, and me.
Feel free to discuss the problems in the comment section after the contest ends.
Hope to see you tomorrow!
It clashes with Educational Codeforces Round 126. I have tried to ask the author of the Educational Codeforces Round for rescheduling but maybe I am just a CM, there was no reply.
It consides with CF edu round, Can you change the time of it? keko37
The dates for all COCI rounds are known from the start of each year, and it doesn't make sense to change it last second for a cf educational round (also applies the other way around, since much work and effort is put into each contest, and you wouldn't want to disrupt the schedule of thousands of participants — for iamttm's comment)
If you favor one of the contests you can complete the other by yourself later, which I know isn't the same, but I think it's the best you can do right now...
Of course it would be nice if the scheduling of contests on cf will be done with accordance to other major contests and events (which I think is already the case, at least partially), but there are simply too many contests for it to be possible :/
Anyways good luck on whatever contest you choose to participate in!
Friendly reminder, the contest starts in less than an hour :)
seems i was the only full scorer this time :)
here are my solutions:
EERTREE
Let's say we know the set $$$S$$$ of palindrome in range $$$[l,r]$$$ and we want to extend it to range $$$[l,r']$$$. We will maintain an array $$$rp$$$ where $$$rp_i$$$ is the longest palindrome whose right endpoint is at $$$i$$$. Using binary lifting on back edges we can find the longest palindrome whose right endpoint is at $$$x$$$ and is totally contained inside $$$[l,x]$$$, then we simply add it to the set $$$S$$$.
Using small to large trick, it is easy to solve in $$$O(n \log^2 n)$$$.
For pairs of
((
, we always take the first. For pairs of))
, we always take the second.Now, we have to handle those of type
()
or)(
. Let's take those with)
for now, then we choose which pairs we will change to(
.Notice no matter whether it is
()
or)(
it does a suffix increase on both $$$[a,\infty)$$$ and $$$[b,\infty)$$$. So we can treat them as the same object, lets just denote them as ranges $$$[a,b]$$$.Now, let's maintain array $$$p$$$ where $$$p_i$$$ is the "balance" of $$$i$$$-th prefix where we only consider taken brackets ("balance" is count of
(
minus)
). Obviously we want all "balance" to be non-negative.Let $$$i$$$ be the first index where $$$p_i<0$$$. If there is $$$[a,b]$$$ such that $$$b<i$$$ then it is optimal to take it. Otherwise, take any range $$$a \leq i$$$ where $$$b$$$ is minimized. If there is no such pair that $$$a \leq i$$$, it is impossible.
My solution for D:
Let's first solve the problem if we only have to print the answer after all the concatenations.
You can simulate the concatenations using a DSU by storing a deque of characters in each component.
Then after you have the final string, you can build a palindromic tree on it. The number of distinct palindromes in the string is just the number of nodes without the two roots.
To support answering after each concatenation, you can store a palindromic tree in each component in the DSU.
To do the merging, you only need to modify the palindromic tree so that it can add characters to the front and the end, and then you can merge two palindromic trees just like deques.
Notes for implementation: Normally, a palindromic tree supports adding a character to one of the ends. To support adding characters to both ends, you can store two pointers, the first points to the longest palindromic prefix, and the second points to the longest palindromic suffix. When merging, you need to be careful to preserve the order, e.g. when merging $$$x$$$ and $$$y$$$ you have to put the characters of $$$y$$$ after the characters of $$$x$$$ if $$$y$$$ has more characters or $$$x$$$ before $$$y$$$ is $$$y$$$ has more characters.