Автор Kuyan, 8 лет назад, По-русски

Всем привет!

Рад пригласить вас на общий для Div.1 и Div.2 раунд Mail.Ru Cup 2018 Раунд 2, который состоится в следующее время: 10.11.2018 17:35 (Московское время). Задачи готовили мы — Kuyan (Фёдор Куянов) и Jacob (Яков Длугач). Большое спасибо Дмитрию cdkrot Саютину и Ильдару 300iq Гайнуллину за координацию и подготовку раунда.

Также большое спасибо majk, Lewin, vintage_Vlad_Makeev, demon1999 за тестирование, а также Михаилу MikeMirzayanov Мирзаянову за системы Codeforces и Polygon.

Этот раунд — второй раунд нового соревнования Mail.Ru Cup, подробнее о котором можно прочитать по ссылке. Раунд будет рейтинговый для всех!

В трех раундах чемпионата разыгрываются ценные призы:

  • Первое место — Apple MacBook Air
  • Второе и третье место — Apple iPad
  • Четвертое, пятое, шестое места — Samsung Gear S3
  • Традиционно топ-100 участников чемпионата получат классные футболки!

В каждом раунде лучшим 100 участникам начисляются призовые очки в соответствии с таблицей. Итоговый результат участия в чемпионате — сумма двух максимальных результатов из трех раундов.

Участникам будет предложено 7 задач и два с половиной часа на их решение. Разбалловка будет объявлена ближе к началу раунда.

Надеюсь, вам понравятся предложенные задачи. Желаю всем повышения в рейтинге!

UPD1: Разбалловка:

500 1000 1500 2250 2750 3500 4000

Раунд завершен, поздравляем победителей!

  1. aid
  2. LHiC
  3. V--o_o--V
  4. mnbvmar
  5. tourist

Текущие результаты Mail.Ru Cup по сумме двух раундов опубликованы по ссылке.

Опубликован разбор.

  • Проголосовать: нравится
  • +180
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is there any AI Cup this year?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -116 Проголосовать: не нравится

Memes and more memes . . .

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

NOIP2018(National Olympiad in Informatics in Provinces) is being held in China now.So we will miss a great contest.What a pity!

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

Cleshes with Asia champions league-final

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Very few users registered for this round :\

»
8 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

why would my second hacking attempt gets counted if its the same input to the same person ?

I just pressed backward in the browser and accedintally it got sent again :(

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

How to solve C,D,E?

Cool problems btw

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

any idea what pretest 5 of C might be?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -15 Проголосовать: не нравится

If I had 10 more seconds I think I would have solved D! ouch

Also, how do you solve C?

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится -22 Проголосовать: не нравится

    If I had an undefined number of seconds I would have solved F... I'm getting WA for some unknown reason.

  • »
    »
    8 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    never mind, i wouldn't have solved it with 10 extra seconds either

    probably 10 more minutes

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +6 Проголосовать: не нравится

    My solution for C.

    I'll try explain as best as I can. Pretend array a is fixed. You can offset b by increments of gcd(ta, tb) relative to a (since the arrays are periodic). Start with the offset such that la - offset ≤ lb and la - offset is as close to lb as possible. Now push a rightwards increment by increment and check and store how many lucky days are shared each time. As soon as the number of shared lucky days stops increasing, break and print the maximum number of shared lucky days. Maybe this could be done with ternary search too, but my linear search was well under the time limit.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

In D pretest 8 is something like

2
abab
ba
aaab
ba

Unfortunately, I've came up with this too late.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -14 Проголосовать: не нравится

I swear to god, that motherfucking test 8 in Prob D...

Any idea what that test might be? :/

»
8 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Will the following solution for F work?

Let A be an array of size n. Ai = xor of path from root to ith node. Now answer is just the kth smallest pairwise xor in A.

To do this do a binary search for value of xor. Say x is your current value. Find number of pairwise xors less than equal to x (this should be easy to do with trie). And so on...

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Test 13 in problem D???

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

How to solve C?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

How to solve problem c? Is there any kind of geometry involved?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Test 7 in C?

»
8 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +20 Проголосовать: не нравится

I have passed pretests on C with this :)

long long ans = 0;
for (int step = 0; step < 1e8; step++)
{
	ans = max(ans, segments_intersection_size(l[0], r[0], l[1], r[1]));

	if (l[0] < l[1])
	{
		l[0] += t[0];
		r[0] += t[0];
	}
	else if (l[1] < l[0])
	{
		l[1] += t[1];
		r[1] += t[1];
	}
	else
		break;
}
»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What are the edge cases for problem D. I was getting WA on pretest 8.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +64 Проголосовать: не нравится

hey, this is cruel to set such tight constraints in F! Why couldn't you at least allow memory pass? :(

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Who can explain why low number of votes?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve problem B

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +35 Проголосовать: не нравится

Used a char array to store the lcp calculated by Z-algorithm on D.
How come I can't find this bug using more than 1 hour during the contest, but spot this instantly after contest......

»
8 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -15 Проголосовать: не нравится

was my comment invisible or what :P

I don't understand the logic of counting the same hacking attempt when someone send it accedintally .. why it's not like when someone send the same WA solution twice they don't count the second one

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +97 Проголосовать: не нравится

Thanks for the contest! I liked the problem ideas but thought limits on problems D and F were unnecessarily strict.

D is a very nice conceptual problem, but limits require linear-time string matching (and fast-enough input to read 18 million chars in 1 second). IMO, linear-time matching does not add any depth -- a limit of N ≤ 300, wi ≤ 300 would have all the same conceptual value without requiring book code.

F is similar. Requiring linear-time bucket sort or trie traversal makes the problem much harder but not much more interesting. N <  = 105 would allow map / sort / unordered_map solutions to pass without changing the core of the problem. Also, the complexities are hard to distinguish: I've heard of some log-time solutions that snuck under TL as well as some constant-time solutions that went over.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +36 Проголосовать: не нравится

    I agree 100%.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I actually thought about a randomize string matching solution after trying to hack the test case (and fail) :D

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    IMO, linear-time matching does not add any depth

    I saw some depth there. For example, linear-time string matching using hashes or KMP? Hashes are faster and maybe simpler since we're only checking the first occurrence. And do we really need it, isn't there a stupider algorithm we could use? After all, the problem is quite specific and, more importantly, the lengths of strings are small. How long does it take to write KMP, what are the chances of making bugs compared to other ideas, is it worth risking anti-hash tests, is it worth risking TLE with an optimised bruteforce... all factors to consider. I decided for KMP because it's actually very simple and turned out to be a good choice.

    Plus there may be some more straightforward solutions (or parts of solutions). Consider just that the number of forbidden substrings is O(N|w|2).

    D was a very evil problem in that there are so many ways to approach it.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

What's the solution for problem C ?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

debugforces

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +29 Проголосовать: не нравится

Earning a macbook air with 30 seconds. Glorious !

»
8 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +11 Проголосовать: не нравится

Apparently pretests in C were very weak. My code even fails to something really simple like

1 2 4
0 0 6

because I shifted by ta instead of the gcd after taking mod gcd :/

»
8 лет назад, скрыть # |
← Rev. 12  
Проголосовать: нравится +41 Проголосовать: не нравится

Why isn't the contest open for practice? EDIT: it is now.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve F? Kind of seems impossible to a noob like me

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +19 Проголосовать: не нравится

I dont give a sh*t if people down vote this but ive seen 2 round of this contest and both of them sucked.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

Interesting, for E problem S3 * log(N) is passing easily — 45540761 :)

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Here is a more intuitive and simple explanation for solution to Problem C which i found after struggling for a day,

Pre-requisite : Understand what we have to do

First of all, if one can make an Alice's interval and a Bob's interval coincide (in the sense that both begin in the same number) then the answer is just min(rb - lb + 1, ra - la + 1) (the length of the shortest interval).

However, this may not be possible. Sometimes it isn't possible for them to perfectly overlap ever(think about it, if you don't get it, continue reading anyway).

We intend to choose lucky intervals(one of alice, one of bob) so as to minimise the difference of the start points of the intervals of alice and bob. Now convince yourself that this will give maximum intersection.

Now the easier part, the solution :)

Consider the start points of two general intervals (one of alice, one of bob).

For alice, start point of general lucky interval is : la + k1 * ta

For bob, it is : lb + k2 * tb

Difference of start points, diff = lb- la +  (k2 * tb) -  (k1 * ta)

Now, I want you to focus on last two terms of the above expression, they are : (k2 * tb) -  (k1 * ta) where k1, k2 are general integers. That's a linear combination of t1 and t2 which always happens to be a multiple of gcd(ta, tb). In fact any multiple of gcd(t1, t2) can always be written as a linear combination of t1, t2(see Bezout's lemma for both these facts).

So we can say that the difference is of the form :

diff = lb- la + k * gcd(ta, tb), where k is yet another integer.

We intend to minimise the absolute value of diff; so we solve the equation, diff = 0(minimise diff) for k. (Note that it may be not be possible for integer value of k, i'm coming on it)

We get after rearranging,

k = -(lb- la) / gcd(ta, tb) (Don't do integer division here).

Of course, since diff = 0 isn't always possible because the start points of alice and bob may never overlap. So this k we have here must be calculated as a float value (use long double), its floor and ceiling are two integer candidates one of which will make the diff value minimum.

So with ceil(k) and floor(k), we obtain two different diff values. For both of these diff values, we calculate the intersection length of intervals [la;ra] and [la + diff; la + diff + (rb — lb)] and print the maximum intersection length for two diff values. (If you don't get this last part, think about it, it's easy, you can ask if you don't get it)

You can refer to my solution here. 45568612