Hello Codeforces!

On October 12, 17:05 MSK Educational Codeforces Round 30 will start.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

The round will be **unrated** for all users and will be held on extented ACM ICPC rules. After the end of the contest you will have one day to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given **6 problems** and **2 hours** to solve them.

The problems were prepared by Ivan BledDest Androsov, Vladimir 0n25 Petrov, Mike MikeMirzayanov Mirzayanov and me.

Good luck to all participants!

Congratulations to the winners:

Rank | Competitor | Problems Solved | Penalty |
---|---|---|---|

1 | irkstepanov | 6 | 141 |

2 | SPFA_THE_BEST_ALGORITHM | 6 | 169 |

3 | KrK | 6 | 199 |

4 | chemthan | 6 | 200 |

5 | Shik | 6 | 214 |

Congratulations to the best hackers:

Rank | Competitor | Hack Count |
---|---|---|

1 | jhonber | 75:-6 |

2 | halyavin | 31:-8 |

3 | Zaher | 6:-2 |

4 | Khaled_Mohamed | 4:-1 |

5 | silicon_lover | 2 |

123 successful hacks and 96 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem | Competitor | Penalty |
---|---|---|

A | I_love_Maria_Ivanova | 0:01 |

B | gritukan | 0:04 |

C | eddy1021 | 0:08 |

D | unused | 0:14 |

E | irkstepanov | 0:44 |

F | xjlinyueru | 0:23 |

UPD: Editorial is published

Why isn't it on the main page?

UPD:Now it is on the main page.Don't

`HACK ME`

, uwi!Why there are so many people talk about uwi[user:uwi] when an educational round begin? I DONT think you will get an ACCEPTED just because of no hacks from others.Is it a joke?

You don't know uwi? Check this

You (yaowan).

Sure I know who uwi is, because I GOT A HACK from uwi just before...

I(cai de kou jiao...)

You dalao...... I can't understand English well.... I (chizaoyaowan) QwQ

Great!

Great!

Great!

Great!

Is all educational round is unrated??

Yes, the goal of Educational round is rather to practice than to compete

The round will be unrated for all users and

will be held on extented ACM ICPC rules.All Educational Round held on ACM ICPC rules.

UPD:Educatonal Round for educating your mind. F**c logic!what is the subject of this round?graph?greedy???what?

Physics.

what the C question Saying?? i don't get it....!!

"that is, if the current column is j, then he will find minimum i such that ai, j = 1"

see if we take the current value of i and calculate the score for current j it may happen that we can do better if we escape this 'i' and move to another 'i' and start at this (suppose that at some position we have continuous 1's and so, that position will be better for our answer).

so, to move at that position we have to escape some i's which have 1 (i.e. we need to invert them).

Now, it may happen that various i's may give same contribution to our answer and fro all those we have to choose that i for which we can minimize inversion ! Clearly greedy solution works here!

It can be solved using precount for each column and greedy algorithm. The main difficulty in this task is to carefully check when you meet 1. You can see my solution for reference.

does anybody know how does the 5th test look like at problem E? L.E:i thought that is 2 have the same score,they should recive the same grade,but i was wrong

My best round ever! Shame that it was educational and unrated(( (also toughest b ever)

Why my idea is wrong on test 24?

my wrong code is here

The idea is using binary search to get the answer

you don't need binary search dude

what does it mean?

it means that you can solve the problen without using it

You

can'tuse binary search for this problem because the objective function (the length of the substring in your case) is not monotonic. Consider the example: 00111100. You can make balanced strings of lengths 2, 4, 8 but not 6.so are data weak?

so I just find out the answer "4" that is right I think.

The answer is 8.

I saw it...So binary search is surely wrong.

I also had wrong answer in test 24. I realized this after the contest finished :/. you can't do binary search. try this case 10 1110000011

will there be any editorial?

How to solve B ?

change array a[]==0 to -1.find prefix[]=prefix sum

find two indices of maximum difference for which it is same value.

take example. 1001

1 -1 -1 1

prefix[]=1 0 -1 0

there are two.so between these two maximum length found...!! my submission:31249578

Thanks Doaremon , But I think This is called prefix array and not suffix Correct me if I am Wrong.

Haha.i don't know why i used suf[] at that time.....

happens.

How did you know u can solve it using this way ? Does it have a name , this method ?

by solving more and more problems...triggered this logic in mind suddenly...

I couldn't AC my O(n*sqrt(n)) approach for problem F.

Test cases were very strong!

How to solve D ??

If

kis even, then no solution because you always make 1 (main call) + 2·mcalls wheremis the number of times you pass from condition 1. Ifkis odd, then there exists a solution ifkis less than the maximum number of calls.You can solve the problem recursively by calling a function that takes the current subarray endpoints and

kand the integer to starting filling the array with in this subarray (if the integer isxand the subarray size isL, then you will fill it with the integersx,x+ 1, ...,x+L- 1. These integers are the subarray values. The main call will bef(0,n,k, 1).If

k= 0, then put all the numbers sorted in the subarray so you do not make any mergeSort() call. Otherwise, split the subarray according to the rules. The left part will take the largest subarray values and the right part will take the smallest values. In this case, we guarantee that we will make 2 mergeSort() calls. Then you callf() for the left part giving itk- 2 to be maximum number of mergeSort() calls it can use and it will return the remainder ofk- 2 (the unused calls). Then you callf() for the right part giving it this remainder. Finally, you return what the right part returns back. For a solution to exist, the returned value of the main call must be equal to 0Thanks

How to solve F?

Let's reverse string and build suffix array. Since we have sorted suffixes, string 'a' will be a LCP of some consecutive suffixes in suffix array, next we should get LCP array (lcp[i] = lcp of suffix[i] and suffix[i + 1] when i and i + 1 indexes in sorted order). If we represent LCP array as columns along axis, our task transformed to 'find rectangle with maximum area', and it can be solved with two stacks: for each lcp[i] find nearest left and right index j, that lcp[j] < lcp[i], after that we should relax the answer with lcp[i] * (rightJ — leftJ), because there are (rightJ — leftJ) strings, that have lcp[i]. So the last question is how to handle forbidden cells? we should merge all lcp (in lcp array) into one between each two consecutive non-forbidden cells.

PS. If you not familiar with suffix structures, I hope it can be solved with the same aproach with replacing suffix array by hashing+binary search for sorting suffixes.

How can you sort the suffixes with hashing???

To compare two strings you need to find LCP (binary search LCP and check that hashes are equal) and just compare the next characters. (each compare will be in O(logN) so sort will be in O(nlog^2n))

5 ababa 00100 in this test case LCP[] = {1,3,0,2,0} then how can i calculate final answer from here?

We always should try to relax the answer with each separate suffix itself (in this case it will be ababa), so it's special test case.

yes got it. but O(nlog^2n) gives TLE. http://codeforces.com/contest/873/submission/31433595

Can Someone Explain me how rajat1603 solved B ?

logic is same as my sol just implemented in easier way....

You just need prefix sum to solve this question and realize the following : initially sum = 0

add 1 to sum if you encounter a '1' subtract 1 from sum if you encounter a '0'

Suppose you are at current index 'i' and your Current sum is S. You are encountering this sum S for the first time. you map i to S. i.e, map[S] = i... Now suppose for some later index J you encounter S you just update ans as max(ans, j — map[S]) because if you observe carefully you need the best possible sum to be 0.

if you have current sum as 0 at index 'i' then you keep updating the answer with 'i' + 1

Could you please look into unknown verdicts for hacks 360797 and 360798?

Problem is fixed, hacks will be rejudged by the end of hack phase.

Could you please explain to me how does hacking work?

How to solve E?

I tried with a DP approach but it didn't work.

Good day to you,

Well hope it won't be wrong, since it is not "proved yet" :)

Firstly, sort all "heights" (yet still remember their original position to be able to reconstruct at the end). Now, it is pretty easy to assign a value to each position (it is the height on the position minus the height on previous position [potentionaly 0]).

So not lets consider how would "brute-force" solution work? Well kinda simple.. just try EVERY triple in the array (check whether the x*2>=y is fine) and then take MAXIMUM from these (what is maximum is written in the "rules" — note tht the rightmost is always best diploma :) ). Now as you can see, it will obviously TLE, anyway as you can also see, it is just

O(N^{3}) which is not bad.So now we can "simply" focus on reducing of the third cycle. As the other two iterations are fixed, we know pretty well, where the segment (if any) for the third cycle might be. EXAMPLE: N==10, i=7,j=9, we know the length of first segment is 2 and of second is 1, so the length of third segment must be between 1 and 2 (which begins on position 5 or 6). We are interested in the biggest number there so we can use some "RMQ" structure, which could get it. One way is for-example Sparse Table which can get maximum in

O(1) making the total complexityO(N^{2}).So in short: Iterate with two (the best) diplomas and find the third by

RMQ.Good Luck And have Georgeous Day ^_^

Hope it was a little bit undestandable and hope I didn't lead you wrong way ^_^

"it will obviously TLE" — not so obviously, I got AC with brute force only suitable indices in third cycle (Code) And this solution can be optimized more if brute force only suitable indices in second cycle also.

Good day to you ^-^

Well seems you are right (yet I would still be a little bit afraid). Seems taking only "interesting" seps makes it "766 149 050", which might be suitable (not sure what (whether) are your other optimalisations)

So well thank you, seems it is a little bit easier approach ^_^

GL & Have Nice Day

Can someone explain to me how does hacking work?

can anyone please explain how to solve E?

When will the editorial be published?

Auto comment: topic has been updated by PikMike (previous revision, new revision, compare).