Hi all!

This weekend, at 16:05 UTC on November 12th, 2017 we will hold Codeforces Round 445. It is based on problems of Technocup 2018 Elimination Round 3 that will be held at the same time.

Technocup is a major olympiad for Russian-speaking high-school students, so if you fall into this category, please register at Technocup 2018 website and take part in the Elimination Round.

I want to thank MrKaStep, komendart, veschii_nevstrui, bixind, AndreySergunin and DPR-pavlin, who authored and prepared problems for Technocup, and Lewin, who kindly suggested the last problem. I also want to thank zemen and AlexFetisov for testing the round.

Div. 1 and Div.2 editions are open and rated for everyone. Register and enjoy the contests!

**UPD:** We apologize that we run into technical issues during the round. The round will be unrated. I hope you liked the problems.

Anyway, congratulations to winners!

Технокубок 2018 - Отборочный Раунд 3

Codeforces Round 445 (Div. 1, based on Technocup 2018 Elimination Round 3)

Codeforces Round 445 (Div. 2, based on Technocup 2018 Elimination Round 3)

Editorial is published.

This round will be my first blue-name-contest. Good luck.

We don't care

This round will be rotavirus's eighteenth purple-name-contest. Good luck.

I’m from

Chinaand I had a bad round because of the terrible Internet.502 Bad GatewayMikeMirzayanov All of my classmates also met this problem for half an hour, could you plz give us a unrated?

Hope that there would be no issues like the last "rated" contest...

We did have issues though

Too bad things are not destined to be as we have wished... :<

.

iS iT rATED !?

First contest I'll have time to participate in for 2 months. Hopefully I'll be able to reach expert!

Better luck next time!

I will be expert if this is rated. pls........

another contest! thank you!!

By the way, this contest round number is 445, and this contest ID is 890 in Div.2 one. (889 in Div.1) Finally, Codeforces achieved to a host

y= 2xround. (Letybe the contest ID, letxbe the round number)Nice observation ;)

good one

And can you make graph of y-2x vs round number? ;)

Yes!To make the graph more easier to see, I made the graph of 2x-y vs round number, not y-2x vs round number.

you freak _/_

That sudden fall of 30.. Isn't it strange? What exactly happened?

Well... the value of 2

x-ydecreased, while 2xincreased, which means thatyincreased faster. It means that there were rounds that are not regular CF rounds.If we have a look at contest list, we can see that there was whole bunch of non-regular rounds between Round 340 and Round 350.

So exciting about this contest! Goodluck fam!

Happy 11.11 festival! :D

KAN's contests are very interesting, hope for everyone a good time and high rankings.

I wish all of

newbies to bepupils. It is time to change colours. Good luck to all!and all pupils to be specialists finally ;)

And all specialists to be experts finally. ;D

Chinese students have finished the Noip.So I'd like to enjoy this contest instead of caring my low score.XD

Will hope that the contest will not have any glitches and the contest will remain rated :) KAN

Yes please

These days codeforces contests frequency is very low :(

A correction indeed, Codeforces

RATEDcontest frequency is low.I don't want unrated contest ;(

I'm also :(

502 Bad Gateway500 Internal Server ErrorI also had these two issues.

2 back to back unrated contest would be too bad

Why there is no extra registration for Div.1 ?

laggforces

It Will be unrated :(

am I the only one who has problems to load the contest area?

Servers of CF , during the contest !

This image is an upvote machine. Every time servers are down people are racing to post this.

WTF is going on with the server???

Will the contest be made unrated?

This contest should be unrated. There are way too many server issues for this round to be fair

Shouldn't it be unrated? Some people may take a web on the computer, and they write it when the web does not work, it's unfair~

KAN will this round be unrated? I really hope not but it probably will.

New version:

is it rated?

My whole contest f**ked up due to servers issue.

Many people couldn't submit for 1/2 hour because of "502 Gateway Timeout" and various other connection errors.

Is it rated?

I believe it was a sitwide problem, so it affected everybody. Maybe because everyone was affected equally it can remain rated?

i got very low score because I had to wait more than 30 minutes to submit A and B. There's no way it can be fair at this point. Within that 30 minutes, there can be huge differences in ranking if order of submitting is different for everyone.

That can be adjusted though, I'm sure they have logs of when the site was down, surely anyone who submitted after it can have their time penalty adjusted to what it would be as if no issues occurred.

"anyone who submitted after it can have their time penalty adjusted to what it would be as if no issues occurred"

How would one know what this adjustment should be? I understand you had a good contest, doesn't mean it was fair for the others, man.

The adjustment should be the amount of the the site was down for. It's not as if some people were only unable to access the site for 5 minutes, it was the same for everyone. As for some people not being able to see problem statements, I've already accepted that is a grey area in which some people were affected more than others. That is something the contest runners will have to decide upon. But if we're simply talking about time penalties, then yes, it can be adjusted fairly for everyone.

Also, I accidentally closed the problem page and was unable to open it for the next half an hour. There's no way this contest should be rated.

`ɔopǝɟoɹɔǝs˙ɔoɯ is temporary unavailable`

Codeforces in a nutshell

My upvote is on the way.

I skipped free pizza for this :|

I have class tomorrow QAQ . I should go sleep.

Two unrated in a row? PLEASE GOD NO.

The good old Codeforces seems to be back, the way we remember it. I like the problems, doe.

Problem C, div2. Test 2.

What about answer: 1 -> 1 -> 1 -> 2 -> 1 -> 2

I suppose this is correct for sequence "0 1 0 1 3" in journal but requires only 2 rooms instead of 3 in official answer.

emmm,in the 3rd second,the number 2 can't refer to 0

Quick tip: Never discuss a problem during contest time, regardless it is rated or not, man.

Codeforces round

502504 too

You can't say everyone was affected equally .

Suppose server was down from t=x to t=x+30. One solves at t=x-1 and submits it at t=x-1. And one who solves at t=x will submit at t=x+31.

Further imagine if First guy has access to read the next problem and second guy doesn't havve since he hasn't loaded the problem page of next problem .

The first point can easily be fixed by simply subtracting 30 from all submissions made after x. The second point is a more complicated matter, and could go either way.

The first point can't be solved either. Say the servers went down at time t. Someone may have solved a problem at time t + 5 and had been wanting to submit his code, but only got to submit it at t + 30 (when the servers were back up). However, he would receive a score equal to someone who solved it at t + 25, and submitted at t + 30, by your logic.

And there were others like me who stopped the contest assuming it would be unrated for sure (as it was only natural to assume so).

Is it only me or someone else get 502 error during the contest... Just managed to log in.

let's take into account that many of us left the coding arena when the site was not working only to come back later to find out that contest was extended. it's not fair at all to make this contest rated.

Codeforces Should Really Buy A New Server To Work When The Current One Is 502. Codeforces Should Really Buy A New Judger As An Alternative For The Stuck Judge System In The Contest. Codeforces Should Really Buy A New Set Of Problems In Compensate For Several Unrated Problems These Days.

I hope admins realize that extending the contest by 30 mins does not make up for the issues. Everyone was affected differently so it would be completely unfair to rate it.

make codeforces great again

Internal Server Erroragain :( Leaving the contest.The contest should be unrated. As many others, I thought that the codeforces is down, so I gave up. But now I can see they extended the time, which doesn't fix things.

You can't just extend 30 minutes and say it's rated. What about all those people who left in the middle of the contest to do something else? What about the people who solved the problem at the beginning of the downtime interval vs. at the end, are they all the same?

Codeforces teaching me more about Servers Breakdowns than Algorithms and Data Structures.

going rated anyway?)0))))

Yes they should not make two consecutive contests unrated .... But Codeforces is down these days which ruins fun of contests :(

read this

That's not a valid reason at all to make the contest rated.

1 — While the server was down some people left the problems opened hence they got extra time to find a solution.

2 — Some open lots of Codes to hack and generated test cases while the server was down.

3 — Some just left the contest since the servers were down for 20+ min ( Most will think " For sure it'll be unrated " and do so.

It's still impossible for me to perform a hack... The server is just too slow and will stuck at the hack page...

Alright it's time to vote.

http://www.strawpoll.me/14385815/r

I am not sure if it was a DOS attack or the servers crashed for an unknown reason, if it was, we can't let the terrorists win, make it rated!

I am just saying this because I think I will go up, so don't take it seriously :P

Sh*t. I opened movie when CF servers gone down, and then my friend told me they are back, then wrote something for B and it is hacked now by Um_nik. Now I have to do binary search on movie for finding where I was. Really sh*t.

How to solve C? I can only think out some kind of DP that can't even fit memory limit.

I think we can fix the value which we can get maximum value and count how many way to achieve it, i need 1 more second to submit and know whether it's correct or not

1) Brute force it

2) Search for the first two columns on OEIS

3) Find a pattern

4) ???

5) Profit!

A 9gagger, I see you're a man of culture as well.

I wonder how many contestants solved this problem without OEIS.

In my opinion, greedy algorithm can be a fine approach. I used an array (I'll name it A): element with index i is used to store the index of the room which was last visited in minute i. (if this room is visited again in the future, the value of this element is changed back to 0).

Then I did a linear check over all numbers in the notebook:

Assume that the number written in minute i is x. If there was a room which was last visited in minute x, we could assume that that room is visited again in minute i (it's the easiest way to handle without adding new rooms). Assign A[x] to A[i], then assign 0 to A[x]. Otherwise, since no room was last visited (until minute i) in minute x, the man must have enter a new room. Increase the room count by 1, and assign the index of the new room to A[i].

Hope this will help. And sorry if my expressions could be complex though...

With all due respect that is very nice but he asked about Div1 C

Ouch... sorry then. Should I delete this for now?

Well, some will find it useful anyway

Hmm okay, provided that they ended up seeing this long comment and figure out my misunderstanding... :< Anyway, thanks, just for having a nice response ;)

To solve Div1 C, Div2 E

Let's calculate two functions:

dp[i] — How many [i] permutations exists, where last element is i and will return correct maximal value.dpsum[i] — How many [i] permutations exists, where element i is in one of the last k positions and algorithm returns correct maximal value.Then we can calculate these functions in linear time:

To calculate

dp[i] we simply append i to the end of all the [i-1] permutations, wherei- 1 is located in one of the last k positions and algorithm will return correct maximum value.dp[i] =dpsum[i- 1]To calculate

dpsum[i] we must remove all permutations, where maximum value will be located outside the last k elements of permutation fromdpsum[i- 1]. Then append new element to the end of permutation, it must be less than previous maximum value. So multiplying by (i- 1) we add this new element and increase all larger, equal permutation element values by one, so we get [i] permutations, where i is located in range [i-k+ 1,i- 1]. Lastly, we must append all permutations which have maximal value i in the last position of [i] permutation, we calculated it indp[i].Then we can calculate the number of all good permutations, where correct maximum value is returned by algorithm.

Lets fix position

i, where maximum valuenwill be located. Then firstielement prefix of permutation must return correct maximal value and maximal element is in the last position of permutation formed by prefix, so we usedp[i]. We choose order of lastn-ielements in (n-i)! ways. Suffix of last (n-i) elements forms a permutation.Then we must merge these two permutations together by merging all elements except maximal

ntogether. This can be done in ways.Then the number of bad permutation is count of all [

n] permutations minus good permutation count;answer=n! -good_perm_cntThis round must be rated

Hi, I submitted A (incorrectly) just before the website crashed, and I had to waste about half an hour waiting for it to come back on. As a result, my A was submitted 30 minutes later than it should have been, and my rating will likely fall is a result. Can this contest be unrated for me?

Actually I finished coding div 2 C in 32-33 mins mark. I was about to submit and the site went down then. I tried to submit for for the next 20-25 mins but coudn't due to the issues.

Also, the site was down and up,down and up at least until the 1.15 mark, and I managed to crunch in a submit during the 2-3 seconds the site was working between the lags around the 58 min mark.

And I see some people have already submitted on 28-29 mins mark. I guess this is kinda unfair.

Rated Please

Second consecutive contest of codeforces that is very bad :

not clear question

bad pretest and anyone can hack easily

Bad Gateway

Why ?????

it was not bad really . problem were pretty clear and pretests were not too weak . i was busy coding div1 B for almost the whole contest so i didnt get that gateway error at all ! however hacking was almost impossible

Actually it was a good contest except the bad gateway problem. Problem statements very fairly clear and some hacks are always expected in div2A.

That's right. but those could be very better. codeforces is a good and popular site as a result anyone have high expectations.

I hope codeforces be better in the future like always! :)

Great contest plagued by server issues :(

I was unable to hack in the last 6-7 minutes, but still, let's not make the round unrated. Even the last rated round was unrated. Looks like, system issues are becoming rather common, so this way, who know when we'll have an actual rated round. Please don't make it unrated.

How to solve E?

f(1,x) can be computed inO(log^{2}), I'm not sure it has anything to do with real solution, though. I tried some randomization stuff but couldn't pass pretests.I thought of the same thing (you're using the fact that X halves or stays the same at each step)? You can also do something like: "if (a[i] <= a[i + 1]) delete a[i + 1] and increase the coefficient of a[i] by 1" and you get a decreasing array, with some extra coefficients. Still not very useful though:(

Yep, I did both of them but they were'nt very useful :(

I hope they consider making it rated for those with positive rating gains and unrated for those who lose rating (as they've done in the past). This could satisfy everyone?

Edit: I don't understand why a reasonable suggestion is being downvoted.

That's a good idea. emmm....

nah, the rating inflation will be skyrocketing if that were the case.

Well, they've done it for a few contests in the past and it seemed to meet most people's demands.

Can you point which ones to me?

I would, but I don't precisely recall the exact contest. I could dig around the previous 100 contests, but that would be painful. I'll just leave my suggestion as is.

This idea was applied in csacademy round 37

My attempt on E (Div 2.):

We will construct a permutation that has the following structure: Starting with

`a`

values, then place the value, namely`false_max`

, that will be the answer of`fast_max()`

procedure, then`k`

values after that, then the rest of the number. Note that the first`a + k + 1`

elements in this array will be <=`false_max`

. The number of choices can be decomposed into:Choose

`(a + k + 1)`

elements from the set of`[1, 2, ..., n-1]`

-> the answer is`combinations(n-1, a + k + 1)`

Place the maximum element,

`false_max`

, from the above step at`array[a + 1]`

.Re-arrange the remaining numbers of the chosen elements into

`(a + k)`

spaces -> the answer is`(a + k)!`

Re-arrange the remaining not-chosen numbers into

`(n - a - k - 1)`

spaces -> the answer is`(n - a - k - 1)!`

That is for one

`a`

.`a`

will be ranged from`[0, n - k - 2]`

. Calculate the sum of all intermediate values gives the final answer.Here is the pseudocode:

I got Wrong answer on pretest 15. Is there anything wrong with my solution, or just that my implementation is so poor that it can't handle the mod part?

Oh wow what a coincidence, we posted the same wrong solution at the same time!

"temp *= mod_fac(a + k, mod);"

its actually not (a+k)!, since in the first a numbers there must be no k consecutive decreasing values, otherwise you will stop at them and not reach the a+1th value.

to calculate this number, let dp[i] be the number of ways to permute first i numbers such that no k are increasing. dp[i]=(dp[i-1]/(i-1)!+dp[i-2]/(i-2)!+...+dp[i-k]/(i-k)!)*(i-1)! (i is from n-k to n-1)

Can you please explain this dp? I struggled for the whole contest to find this.

Let's find dp[n]. Obviously, you can place the number n only in the last k spots, otherwise you would have more then k numbers smaller then n after n. Lets say you place number n at position i (so you have i numbers, then n, then n-i-1 numbers) (n-k<=i<=n-1). The first i numbers also have to respect the condition (of no k decreasing consecutive numbers), so there are dp[i] ways of arranging them. Also, there are C(n-1,i) number of ways of choosing the first i numbers out of the n-1 other numbers. We can arrange the last n-i-1 numbers in any way, since n will be bigger then all of them, so there are (n-i-1)! ways. Final formula:

dp[n]=sum(dp[i]*C(n-1,i)*(n-i-1)!)=sum(dp[i]*(n-1)!/i!)=(n-1)!*sum(dp[i]/i!), where i is from n-k to n-1

I think your problem might also have overlap issues. Consider the step when n = 10 and k = 1. For the permutation {1,2,4,3,5,6,10,7,8,9} and a=3 your solution would consider false_max=5, whereas the false_max should've clearly been 4.

How do you solve problem E? I got WA on test case 15 with this formula so I want to know if the formula was wrong or if it was something in my code.

For example: n = 5, k = 1 You will count this permutation twice: 2 1 4 3 5

Hacks for Div 2 a?

Many people checked sum/2. It get WA when sum is odd.

one guy in my room checked d+e+f == c+d+e. Hacked.

for who used sum/2 for checking ... 1 1 1 1 1 2

for sorting and then grouping (0,1,5) — (2,3,4) ... 0 1 3 4 7 7

There was a solution in my room which checked a[0]+a[4]+a[5]==a[2]+a[3]+a[1]. I hacked it using 1 6 7 9 10 11. Several other hacks are possible.

All right, go rated

What is the reason of this server break downs? Poor servers, DDOS or smth? Can anyone explain it?

How to solve Div2-D (Div1-B) ?

It'd be nice to give hints before the complete solution.

Hint : Will the result contain a character more than once ?

yep! you are right!

How the initial strings look like?

I was wrong, i thought ans for 3 aa bb cc would be aabbcc. but the ans is no.

Thanks

implementation

is there is a solution if a character occurs twice in a string?

no

sm1 hold me, captain obvious is striking so hard

solution will be a forest of linear trees

Well i couldn't solve Div 2 D but here are some of the things that i had thought of during the contest. If someone has solved with similar assumptions then please help in how to construct a solution from here.

Can anyone help me create a solution from here or if my assumptions are wrong then point em out please? Thanks :)

Construct from strings graph

symb- >nextsymb. This graph must be:1) uncycled;

2) from each vertex there must be at most one edge;

3) to each vertex there must be at most one edge.

So from that graph you must iterate over vertexes that have no one edge points to them and create answer.

Example:

ab

bc

cd

da

Answer is NO since graph a->b->c->d->a is cycled.

kas

kad

Answer is NO since from a there are two edges to s and to d.

Thanks for this but i dont quite understand how the graph is being made. Can you please explain for this input

Thanks! :') Update: I've understood thanks!

Here's how I did it (With the same assumptions as you did): - Put in all the strings in a set S. - If any string has a repeating character, print NO(since this character will have more counts than the entire string). - For every character c in the alphabet, do the following: Make a set of all strings that contain this letter, say T, and while the size of this set is larger than 1, pick two strings from this set, merge them, and insert result in the set S. (Remove the original strings from S and T) If it is not possible to merge any two strings, then print NO (because the final answer has any character appearing atmost once.) To merge any two strings, check the prefix and suffix from c's position in the two strings. - Finally, you have only disjoint strings remaining in the set S. Concatenate them lexicographically and do a final check for repeating characters.

suppose if the set is ab, ba then i can construct the string abba, in which all the substrings in the set occurs once and all occus exactly same amount of time. Also if it is kas and kad then kaskad is a good string right ?

No..Because occurence of k is more than occurence of kas and kad.

Wonderful explanation !! Thanks a lot :)

Lagforces servers be like

Let's run the system test, if i passed the D the round should be rated.

I wanna pass ABCD

Situation of the last two contests in Codeforces

Some of us have problem with the round being rated. Because if the server wasn't down, we could have submitted our code early. But as CF was down for approximately half an hour, we got huge penalties :( which will brutally decrease our rating. If we could submit codes just in time, our rating would not be this massacre. So please make the round unrated. :(

CF server trying return

Let's run the system test. For one I'd like to know if I messed up on div. 2 ABCD. For another, I really wanna upload my updated version for problem F just to see if I did it correctly lol

Either rated or unrated, the system test shall run lol

I do not care if this contest is rated or unrated. I only wish discovery test case 4 for D.

UPDATE: Got AC with this case.Try: 2 ab ba

omg. Thanks. sad ;/

How to solve DIV2 D ?

Construct a directed forest as follows. Nodes are letters. If one letter right after another in one of the words, then there is an edge from the first letter to the second one. There must be as most one outgoing edge and one ingoing edge on every node, otherwise answer is NO.

Tricky thing: some words have only one letter in it, one should care about that.

Once you have a valid forest, just print the letters in the order given by the forest.

Yeah, you also need to make sure there are no cycles; as an example, the answer for

2 ab ba

is NO

and the answer for

1 aa

is also NO.

Indeed, I forgot to mention that as well.

Codeforces became one of the most searched today websites on websitedown.info!

it hurts when you expect a positive rating and the round ends being un-rated.

i got a notif that its undated :( Please make it undated but not unrated ;_;

On a more serious note, how to unregister my account? I don't wanna come here anymore...

Or you can just not visit the site, instead of unregistering the account altogether. As for receiving mails regarding contest announcements, you can just unsubscribe them. Is this idea that difficult to come up with?

Actually I had to make a choice : 1) write a lot of true and bad things about the situation, 2) show anger and protest subtly.

Is this that difficult to see that yourself :)

My story on problem A:

Thought one couldn't stay on one vertex twice.

Got WA

An announcement said something like "1->1->1 is invalid because of t_2 can't be equal to 1". Thought it meant "because you can't stay on one vertex twice".

Never questioned my understanding, found that I couldn't pp, and gave up.

You could have seen in the explanation for example 1 they give 1 -> 1 -> 2 as a possible solution.

I misunderstood the statement and tried solving a slightly different problem-

On visiting a vertex the second time, any integer between

`[last_visit_time, i)`

can be written on that vertex.Rated round:

Unrated round:

Wut, noo, now I can't make round 446 :(

In Div1C

I needed to calculate number of permutations

p_{1},p_{2}, ...,p_{n}satisfying .On Oeis it said that this is equal to the number of permutations where all cycles have size less than or equal to

K.I tried proving both these conditions are equivalent but found a

Counter TestK=3,

`1 2 3 [10 6 9 7] 4 5 8`

Does anyone know why these two set of permutations have equal size?

Think about it this way. For your condition tu hold, the value

nmust within the lastKpositions. And you can choose the following values in ways, where is length of the suffix starting in valuen. Then you have to multiply by the number of good permutations of size . That is, . This is exactly the same as choosing a cycle for elementnof size at mostK, and then multiplying by the number of good permutations for the remaining elements.I'm not sure if I understood what you mean by counter test. It's true that the permutation you show should be counted as good for the problem statement, but it does not comply with the condition you mentioned.

although there where a lot of technical issues and despite that i spend more time reloading pages than the time i spend on reading problems, it was one of the greatest contests i ever participated in,thank you for your efforts it was totally worth it to participate even though it wasn't rated in the end.

I have given up on the contest when there was more than an hour left and almost got to top 100. Suspicious.

How many participants from this round will be chosen to the final?

Some Div.2 solutions using regular expressions (in Perl):

A— 32278803,D— 32280926.