358.md (4364B)
1 Source: https://codeforces.com/blog/entry/9334 2 3 ### [358A - Dima and Continuous Line](/contest/358/problem/A "Codeforces Round 208 (Div. 2)") 4 5 Author — [Berezin](/profile/Berezin "Expert Berezin") 6 7 If our line has self-intersections, that some pair of semi-circles exists, which intersect each other. 8 Let points *x*1 < *x*2 are connected with a semi-circle and points *x*3 < *x*4 are connected with another semi-circle. Then this semis-circles intersect if one of the conditions is true: 9 10 1). *x*1 < *x*3 < *x*2 < *x*4 11 2). *x*3 < *x*1 < *x*4 < *x*2 12 13 Let’s iterate trough all pairs of semi-circles, and check if the semi-circles intersect each other. So, the solution will have complexity *O*(*N*2) what satisfied the constrains. 14 15 ### [358B - Dima and Text Messages](/contest/358/problem/B "Codeforces Round 208 (Div. 2)") 16 17 Author — [Berezin](/profile/Berezin "Expert Berezin") 18 19 It’s clear, that adding new random symbols means, that we can simply omit them, they don’t change the structure of the phrase: < 3*word*1 < 3*word*2 < 3... *word**N* < 3. Let’s determine the phrase before inserting random elements: *s* = " < 3" + *word*1 + " < 3" + ... + " < 3" + *wordN* + " < 3". Lets *i* —is an index in *s*, we are waiting for. At the beginning *i* = 0; we will iterate though the sms and when we will meet the symbol which equals to *s**i* we will simply increment *i*. 20 21 if at some moment |*s*| ≤ *I* we found all needed symbols and answer is yes, otherwise – no. 22 23 ### [358C - Dima and Containers](/contest/358/problem/C "Codeforces Round 208 (Div. 2)") 24 25 Author — [Berezin](/profile/Berezin "Expert Berezin") 26 27 We know all the numbers at the beginning, so, it’s clear, that we want pop three maximums. We can “precalculate “ maximums with finding next zero and iterating through all numbers between two zeroes. 28 We should do pops from different containers, so let’s save maximums in the top of the stack, in the beginning of the queue and on the beginning of the dek. (you can do this in some other way) We should determine, where will be stored the 1st, 2nd and 3rd maximum. For example, the first(the biggest one) – in the stack, second – in queue, and the third – in dek. “trash” – other numbers we can save into the end of the dek. 29 Also you need to catch cases, when two or less numbers are between zeroes. 30 31 ### [358D - Dima and Hares](/contest/358/problem/D "Codeforces Round 208 (Div. 2)") 32 33 Author — [Sereja](/profile/Sereja "Master Sereja") 34 35 Let’s look at the first hare: we chose them befoe second, or after. If it is chosen after the second, than the solution from the 2nd hare to the last doesn’t depend on the first one, otherwise, we will receive the same but before the second hair will be obviously the feed hair. So, we have two dinamics: 36 1). *d*0*i* — answer for suffix as a separate task. 37 2). *d*1*i* — answer for suffix if the previous hair for this suffix is feed already. 38 Movements: 39 *d*0*n* = *an* 40 *d*1*n* = *bn* 41 *d*0*i* = *max*(*ai* + *d*1*i* + 1, *bi* + *d*0*i* + 1) 42 *d*1*i* = *max*(*bi* + *d*1*i* + 1, *ci* + *d*0*i* + 1) 43 answer is *d*01; 44 45 ### [358E - Dima and Kicks](/contest/358/problem/E "Codeforces Round 208 (Div. 2)") 46 47 Author — [Sereja](/profile/Sereja "Master Sereja") 48 49 The first thing to understand is that the answer is the divisor of maximal-length sequence of standing one by one ones. (1111…11) 50 Let’s iterate trough this number. Now we should check the table knowing the value of *K*. Let’s find the most left of ones, and choose from them the most top. Let it be (*X*, *Y*). then after each step Dima can appear inly in cells which look like: (*X* + *K* * *a*, *Y* + *K* * *b*). Let such cells are the vertexes of the graph. And sequences of ones – the ribs. We will build the graph. We should check that there are no additional ones in table. We should also check if the graph is connected and has en Euler’s path. The value of K is the next answer under the all conditions. The correct implementation will have the complexity *O*(*N* * *N* * *log*(*N*)). In reality it will be never achieved.