On March 18 Samara Interacademic Programming Contest was held. It is one of two Collegiate Programming contests, which are organized in Samara every year.
Everyone can take part in this contest as a Codeforces Gym contest. Like any train, this contest uses ACM ICPC rules.
Problem writers are Alexey Dergunov(dalex), Nikita Glashenko (Hohol), Pavel Semushin (craus) and Andrey Gaidel (Shlakoblock). Testers are Natalia Bondarenko (natalia) and me (I_love_natalia).
Contest will be most interesting for participants with color from green to orange (Difficulty is 3 stars). Red participant most probably will spend much less time than 5 hours for solving all problems (both of testers finished it in about 3 hours).
Train will be held on Saturday at 16:00 MSK. Everyone is welcome to participate.
Please, do not use any prewritten code and any internet materials in token of respect to ghost participants who will compete with you ;)
Upd. Time was changed to 16:00 (MSK, UTC+4).
Upd2. Don't forget to use input.txt and output.txt files instead of stdin/stdout.
Upd3. Do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Not a rated contest?
It's a training, not even a contest (created with Codeforces::Gyms). And yes, it'll be unrated.
Handlers of 2 testers look alike :)
I just wonder...Who is the girl in the photo of your profile? She is so cute...
His younger sister, I guess... Yours is also cute :x
interesting to see natalia and i_love_natalia to be tester team :D
Registration is opened.
Please note that you must read from file input.txt, not from stdin, and write to file output.txt, not to stdout.
If you use GNU C/C++ compiler, don't use
%lld
to read or write 64-bit integers. Use%I64d
orcin
/cout
.In problem K, Does the problem ask "Deleting the minimal number of digits such that the string "13" won't appear as a substring?" If so, I suggest a better problem description next time, especially for non-Russian readers like me. I really hate figuring out what to do in such kind of problems.
> Does the problem ask “Deleting the minimal number of digits such that the string ”13“ won’t appear as a substring?”
Yes, it does. It was clearly written in the output format. Many people, and non-Russians too, understood the statement and solved it — I don't know why you couldn't do the same.
Could you point out which sentence including this? I was confused at the beginning, then decided to search the problem's title on Google and got its meaning.
Well, it doesn't explicitly say it, but it says that Kostya is afraid of the page's number, and it is written on the page between 12 and 14, labeled "!#". This is what made it clear to me.
Legend:
he is afraid of this page's number
Output format:
minimal number of symbols that should be removed from the text such that Kostya's unpleasant number will not occur in it as a substring
"Kostya is sick of triskaidekaphobia , i.e. he is afraid of this page’s number." This is what I can read from English statement and I still can't recognize any "13" in it.
It's not a big deal to me, yet making the statement clearer would be better I think :)
Any PDF reader says that the page's number is 13 :)
Sorry, that was entirely my fault. However, I'm not sure if Kostya had nightmare in his dream or not, but I'm sure I had nightmare for wasting 3.5 hours just reading this problem and didn't know what to do until I looked up at the page number (only now did I know that the page number was abnormal :( )
And my Foxit PDF reader doesn't show the page number until I drag to the end of the page, which I have never done before :(. I always use my keyboard to scroll up/down or turn the page, which doesn't show the page number. Maybe next time I should prepare against Russian joke.
Hm, my Foxit Reader shows "13/14" at the bottom panel. Anyway, it is not so hard to calculate the page's number by yourself.
Is there an editorial of the problems that we can read somewhere for the ones we didn't solve?
We didn't write the editorial, especially in English; maybe you better ask your questions here? I think many people can answer.
And if someone writes the editorial, we will very grateful to him :)
Thanks, I just didn't want to bother everyone with too many questions. What was the intended solution for A? I know you would need cycles that would have an LCM of k, but I couldn't figure out how to factor k since it could be so large.
Usually, when you factor a number, you check all divisors up to square root of this number. In this problem you need only check divisors not greater than 105 — because if factorization of K contains prime number greater than 105, sum of numbers in factorization is surely too large.
Ahh of course, thank you! It seems so obvious now.. Any hints on L?
It is obvious that the best amount to donate is some b[i]. Lets sort a and b and precalc sums a[i]+...+a[n-1]. Then for every b[i] we find with binsearch number Ab — how many a[j] are bigger than b[i]. Let Bl be the number of b[j] less than b[i]. So the number of money we get is precalc[n — Ab]+b[i]*(n-Ab-Bl).
Why is the best amount to donate some
b[i]
? I had to assume that when I solved the problem, but really didn't get that fully. Any hint? :)If p is not one of b[i], increase it by 1, and sum will not become less than before.
D'oh. You are right! Thank you all, guys!
If p ≠ bi, we can increment p by 1 and the total sum doesn't decrease.
too late :(
If not, we can always increase p until it reaches the first b[i] and this surely gives a more optimal result.
Edit: too too late :((
Let
x
be the best amount to donate. Ifx
is not someb[i]
lets look atx+1
. We cannot get less money then we got atx
because no interval ends atx
. So we can get the same amount if there is noi
such asa[i]<=x<=b[i]
and more money otherwise. Sob[i]
is the best choice.too too too late =)
Obviously, optimal value of p is equal to one of bi. So let's find answer for all of them and get maximum.
Solution is sweep line. Sort all events (ends of segments) in increasing order and process them in this order. In any position X you should know two values: cnt — number of currently opened segments, and curSum — sum of ai which are greater then X. Initialization: cnt = 0, curSum = sum of all ai. In any event update this values: if this is start point:
cnt++, curSum -= X
. If end point:cnt--
and find answer for X — it equals tocnt*X + curSum
.You can also implement the solution with 2 fenwick trees.
One of them you will know how many intervals are open at each point, and on the other how much money you get from intervals that start above that point. pretty simple to update and read.. and for the answer you just go through every data read and get the best !
ops: don't forget to compress coordenates because 10^9 is too big for memory..