Hello Codeforces!

On May/21/2018 17:45 (Moscow time) Educational Codeforces Round 44 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.

This round will be **rated for the participants with rating lower than 2100**. It 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 **7 problems** and **2 hours** to solve them.

The problems were prepared by Adilbek adedalic Dalabaev, Vladimir Vovuh Petrov and me.

Good luck to all participants!

Congratulations to the winners:

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

1 | Benq | 6 | 143 |

2 | crhkr | 6 | 202 |

3 | mjhun | 6 | 210 |

4 | nhho | 6 | 210 |

5 | krijgertje | 6 | 223 |

Congratulations to the best hackers:

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

1 | step_by_step | 248:-25 |

2 | greencis | 31:-6 |

3 | zero-light-some | 15 |

4 | Necrozma | 12 |

5 | Codefocres | 11:-1 |

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

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

A | dotorya | 0:01 |

B | dotorya | 0:03 |

C | dotorya | 0:10 |

D | Benq | 0:21 |

E | SmsS4 | 0:07 |

F | DarkestLight | 0:49 |

G | Marco_L_T | 0:44 |

UPD: Editorial is uploaded

Finally, educational round, I miss you!

Same, my friend!

I also miss that :)

I love this round. As, educational, it teach me a lot.

What happened to BledDest? I have not see him in any educational contest for a while.

He just got a bit busy with his exams at university. Might be back soon when they are over.

What is an educational round? How is it different from a normal one?

It is meant for we to try multiple types of problems, even if they might not be very original. Each problem has not a specific score, but rather is just the solving time that makes your score. This means that, for example, solving A+B+D and solving A+B+C within the same exact time will give the same score, even if D might be more difficult than C. Finally, hacking is not enabled during the contest, but a long (12-24 hours) hacking phase takes place after the contest. After that, system tests are run, as for normal contests.

Please, choose more comfortable As, Bs and Cs in future rounds, so that they're not just silly implementation problems :)

The more you avoid it, the more you are unable to solve it later.

Very true and relatable. You don't lose anything by just implementing, if not anything it helps with speed and coming up with elegant implementation.

The third lucky number,

It's palindrome number,

Double the sum of it's digits equal to any digit of it square,

The number which product of it's digits equal to any digit of it square.

What about div.3 ?

There is one line in

boldin the post, read it again, it answers your question.Sometimes even

boldis not enough for some people to see. They need bold header.rated for the participants with rating lower than 2100Are the problems easy?I'm new in here.

The problems of Educational Rounds explore different topics. Yeah, there are difference of difficulty among Educational Rounds Problems. But the scoring is depend on the time you solve those problems. The faster you can solve those problems, the lower your penalty will be.

Thanks.

See the problems of previous educational rounds. Then you can get concepts about how the problems are

OK,I will.Thanks.

Thanks all the authors to put the great effort and valuable time for preparing this educational round, these rounds are very helpful for learning.

Is education rounds different than the normal rounds? What is special about it? Can someone explain this to me?

Can't you delay this contest by two hours PikMike

You must not a Chinese

agree you

sorry for my bad england

My boyfriend is the only one I can say.

*English

Are tasks sorted in difficulty order?

Usually yes

Yeah ! <3

Wish everyone high ratings :D

First educational round rated for purple :)

aaand 10 mins delay :/

:( was waiting for it and now have to wait more!!

But the participation has crossed 7000 :)

Yes! I hope their server does not gets down just like the first Div-3 where they had a huge number of participants.

it means slower judging queue :(

thats the sence of Codeforces... You wait... And wait... And then wait more... And finally the round becomes unrated :c

someone know why delay 10min ...?

Because the problem statements haven't be translated yet and KAN has to rush it! :D

Someone's girlfriend didn't register

I don't know why, but I was late to get breakfast and now I can participate in the round so I am thankful for it :)

lucky you ^^

Rly?

That moment when the round gets delayed and you suddenly have 10 minutes but you don't know what to do with them.

do what you are doing XD

I

't :PKANWhat is test case 7 in C?

Idk, but I changed my solution from int to long long and it worked, maybe you forgot long long?

I did take long long , but still failed.

i changed int to long long too, but my WA didn't change..

Try:

3 2 5

1 3 3 4 6 7

Answer is 10

I got the mistake thanks buddy

What was your mistake?

I was filling it from top to bottom!

I ran loop from 0 to n-1 instead of 0 to m-1 and got WA in test 7 once. Check it

Approach for C? I had thought to take the lowest number as one barrel with the least vol and then take another barrel such that a[i]-a[0]<=l and ai is maximum. Now if we have n-2 numbers between these such that a[0]<=a[j]<=x then we have an answer otherwise 0. Is this approach correct?

PS I failed on TC-#7

Well, you can't do that. Because solution isn't optimal. What you need to do (I did it in this way, maybe there are easier ways) is find maximum number p such that a[p]-a[0]<=l. Then, from p to what number left, "erase" numbers bigger than a[p] (make them join group where a[p] is last element) so res+=a[p] for every decreasing p that has numbers bigger and not used. (sorry for bad english..) When you finish with the big numbers. Go from i=0 to remaining numbers that you didn't used. And that's it. I hop you at least understand something. Check my submission for more details.

maybe the number of a【i】will exceed n-1

Why is hashing needed in F?

We can hashes subscripts for each letter within each query range.

Hello, can somebody explain the solution for F (Isomorphic Strings)? My guess is some form of hashing, but I could not come up with a way.

You need segment tree, but I don't know why do we need hashing. Isn't it enough to just check if length of sets is same or not? Appreciate counterexaple

for example, aab and abb are not isomorphic.

f(a)=b and f(b)=a , am I missing something UPD: I am stupid, nevermind

then f(s[1]) = b != t[1]

Yea, i misunderstood statments

What the problem meant is: If you replace every character in s with f(s[i]) you should get string t. Meaning that "aab" and "abb" are not isomorphic since running s through your function would create string "bba" and not "abb".

Your guess is correct.

For a given query {

x,y,len}, find the first occurrence of each letter which is after positionx. Now if this occurrence is after positionx+len- 1, we ignore it. Otherwise, let's say the position isx+p, then we know thatf(s[x+p]) =s[y+p]. This means that the occurrences of characters[x+p] ins[x, ...,x+len- 1] should be on the same positions as the occurrences of characters[y+p] ins[y, ...,y+len- 1].Well, to check if these positions are actually the same, we can keep an array

c[letter] for each letter wherec[letter][i] is 1 ifs[i] =letterand 0 otherwise. Then, using polynomial hashing on thesecarrays gives us aO(1) comparisons of the occurrences.E was such a nice problem.., although was unable to do it during contest!!

Nah, it was so standard.

Problem D. — I thought

h_{1}was a typo in`h_1 ≤ H: no sand should go over the fence;`

because of the`no one`

clause, but as reading whole statement and asking to judge, turns out it wasn't ;'(you could have sent question if you weren't sure.

Wait, so only the first pillar has to be less than H? The rest can be greater?

Yes. Now you panicked just like me.

LMAO, now I know why my solution was wrong

Just found out that. Wasted a lot of time on D and then solved E with huge penalty.

I think it isn't clear, but you should check that "h_1" <= H. If there were an example 1,2,1,0(H=1), It would be good.

Honestly, I don't really see any problem with this line. The formula says the right thing, the description extends it meaning. I probably could have added it to notes, I agree.

Chelslay says the right thing, you should have asked earlier if you thought we made a typo.

Oh, I added a couple words now, by the way.

Yeah, I also have to admit that I didn't read the statement carefully. What I'm sad is that I asked for it so late. If there were more time, I could solve it. ( since I got AC just before ;) )

for D, first condition that watched me h[i] <= H first time, after get WA on 7, h[1] <= H

Oh my god. I didn't even realize that until I see you comment...

ideas:

E: Sort, now the boxes can contain consecutive elements so we can dp

F: Let's calculate the hash for each character using a segment tree.

G: Sum the ranks of all possible teams (i,j,k), then for every edge (u,v) subtract the rank of (u,v,k) for every k. Finally add the rank of (u,v,w) for every triangle (u,v,w) in the graph

Read accidentally, got spoiled. :o

D?

Run two binary searches. one for 1,....,K and another one for K + 1, .... LARGEST_VALUE, ... K + 1

I currently submitted a solution only by mathematical manipulations, previously I was squaring a number bigger than 1e9.38513673

Oh, wow. That's a very impressive approach! Thinking final sequence as symmetry first, and removing redundant tail part. I really learned many things from your code. XD

Hey! Can you explain what you did ?

I firstly calculated the max height I can reach such that I have enough sand bags to come down, then I calculated how many sand bags are left from reaching that height and then coming down to the ground . After that I calculated the length of the plateau by diving the remaining bags with max height and if now there is some remaining bag , I just increase the answer by one because that can be compensated by a dual move of that height when we reach that height while coming down. We can prove that it will always be equal to one of the coming down heights.

Can you elaborate how to dp in E please?

f[i]=is possible to put in boxes the pencils from i to n?

Hash can also be calculated by maintaining a prefix array of hash

is it rated?

E solution... wrong.... so sad.... :( Is it rated...?

Can someone explain their solution for E? I was thinking about something involving cliques but couldn't figure it out.

first sort all numbers, now you just need to group consecutive elements, we can use dp to solve this problem. Let dp[i] indicate whether the first i elements can be successfully grouped, dp[i] is transferred by dp[l] | dp[l + 1] | ... | dp[r — 1] | dp[r]. l, r is the interval endpoint that makes dp[i] exactly satisfy condition, As i increases, l increase, r increase, so you can use deque to maintain.

Is finding all triangles in a graph something well known to the community? I managed to find this which works in

O(M^{3 / 2}) but this is my first encounter of this algorithm.It is an standard task. There is a simple sqrt-dec algorithm.

Can you give me some hint / any tutorial about that algorithm?

If you have time, you can just wait for editorial.

I have time, but unfortunately, I lack patience.

I came up with this algorithm:

Let's call a vertex heavy if it has degree >= sqrt(M).

Let's call a triangle heavy if it contains at least one heavy vertex.

We can count the light triangles as follows: Iterate over all edges (u,v) were both u and v are light. Now for every light vertex w adjacent to u, check if (w,v) exists in the graph.

For heavy triangles, let's iterate over every heavy vertex u, and mark its adjacent vertices as visited. Now for every edge of the graph check if it has both of its endpoints visited.

wow ._.

How to solve C ? I got WA on test 8 :(

Sort. The first element (in the sorted array) will be taken for sure so, find the maximum array index which is less than or equal to (first element + l), if there are less than n elements then print 0 and exit. Else, starting from this index move backward and pick greedily such that there are enough of elements ahead of it. Hopefully, it is correct.

OMG, in problem D i thought i CAN NOT make pillar higher then H...

me, too...... It isn't he say "no sand should go over the fence"?

Yup, same here. I need to learn to read statements.

Why everyone is doing hash for F? There is a 24-hours hacking phase await... (don't know if random power base can save us from this)

Is it possible to hash large subsets with one modulo? I thought about this during the contest but decided that collision probability would get too high...

Can you explain your solution ?

It works like this:

First we replace each letter in S with the distance to the nearest same letter on the right, or ∞ if there's no such letter. E.g. "abacaba" becomes [2, 4, 2, ∞, 2, ∞, ∞]. This takes O(n) time. Now instead of a sequence of letters, we have ≤26 interleaved linked lists — one for each letter type in S.

If substrings X and Y are isomorphic, then all elements of linked lists that form X must be identical to those which form Y, except the last elements, since they point outside our region of interest.

Therefore, X and Y are non-isomorphic, iff there is an index i, s.t. X[i] != Y[i] && (X[i]+i < len(X) || Y[i]+i < len(Y)). To find i, we quickly (using a lcp array) iterate over all j, X[j] != Y[j] and check X[j]+j < len(X) || Y[j]+j < len(Y). We will do at most 26 iterations, because X[j]+j >= len(X) means that j was the last occurrence of the letter at j.

[PROBLEM C] Could you tell me where i wrong? My solution got wrong answer on pretest 6 https://ideone.com/Xfb3Ek

Tets: 2 3 2 1 2 3 4 5 6 Your Answer: 6 Correct Answer: 4

please figure out my false

Problem E was a subtask of this problem : Here

also this problem: Here...

38507649

I made a stupid mistake in 985F - Isomorphic Strings.

Come and hack me >///<

But I still love ♥ 127 ♥

Can you believe it, I assumed that the positions in A were sorted. Couldn't figure out this till the end and got WA. Not complaining, but the examples could have been 'unsorted'? :(

Same for E, (cost me one WA) but to be honest it's up to the contestants to read the problems carefully.

How to solve E?

(My greedy solution got hacked)You fail on this case in case you were wondering:

6 3 3

2 2 2 4 7 7

Answer is yes.

Thanks :)

Seems that uwi is on a killing spree for Problem F...

I tried to hack solutions of rolling hash of 2 const modulo after waking up, but the contest had finished.

To hack rolling hash by 1 const modulo is very easy by birthday attack.

how to solve D?

1000000000000000000 1 For this case how the answer be 1999999999

1 2 ... 999999999 1000000000 999999999 ... 2 1

no sand from the leftmost spot should go over the fence; What does it mean then?

Only h1 must be less than or equal to H (so that it doesn't get over the fence). For other pillars they have no restriction on their absolute heights; their heights only need to have at most difference of 1 to their neighbors' heights.

I've been thinking wrong about this during the whole contest, and I had no idea why I was getting WA on test 7. Now I feel really bad that I couldn't realize this :(

Okay, then why the answer to the case 20 4 be not 6? here 1 2 3 4 5 5 = 30.

1+2+3+4+5+5=20.

If 1 is your h1, meaning that it is the pillar that is leaning against the fence, then the other side has to descend from 5 to 1. It can't just stop at 5 abruptly.

get it. thank you.

I got 5 wrong submissions because of this. Luckily I realized it during the contest. Misreading statements is one of my specialties.

Why are "acc" and "cac" not isomorphic for problem F?

because it is not bijective. f('a') = 'c' and f('c') = c(for 3rd character of 'aac')

Anybody idea for E.

Code

My solution for E:

first we sort all pencils.

we define dp[i]: is it possible to solve problem for pencils 1 to i.

and d[i]: greatest j (j <= i) that dp[j] = 1.

now we put x = d[i — k] and after that if a[i] — a[x + 1] <= d then dp[i] = 1 else dp[i] = 0.

and d[i] = i if dp[i] = 1 else d[i] = d[i — 1].

(sorry for bad English)

Why are you taking x = d[i — k]? Can you elaborate more on that?

UPD : Got it NVM.

In last box there are at least k pencils so we have to find rightmost j that

j <= d — k and dp[j] = 1 now check that pencils j + 1 to i can be in one box or not?

Yeah figured it out. Thanks for the help :)

You're welcome ;D

In Problem E,why is that if a solution exists, there exists partitions such that they form contiguous segments of the Array.Thanks in advance .

First we sort the array so in each partition (max — min) will be minimize.

-sort the array

-find a slow dp solution : O(n^2)

-try to optimize it to a faster dp solution : O(n * logn) or O( n )

-try harder to optimize it to O(n)

sure

Is it possible to do it without sorting the array at all then ?

I don't think there is

you can use radix sort. but i meant O(n) algorithm after sort.

If you mean On after sort, it can use deque to maintain dp arrays .

D was the worst possible type of tasks for me. It's a pity it appeared in the contest, even more that it was placed before E, which was quite easy for me.

Also I'm not sure that the round should be rated as I started coding D because at the time of making a decision, E was not solved by anybody (so E appeared to be harder than D), due to the error. Issues in E had impact on many participants. I believe I got 3 problems instead of 4 due to that.

Wait, this happened about half an hour into the contest. Wasn't that your fault to spend the rest of the time on the problem of your weaker topic instead of reading the other ones? I'm sure that the ranklist after half an hour tells nearly nothing about the difficulties of the problems.

I checked more precisely. At the time I was looking at the next task (after solving C), there should have been 23 E solutions accepted already, this was the last one:

http://codeforces.com/contest/985/submission/38494892

At the same time there was 0 accepted solutions to E and there were 11 accepted solutions to D, the last one: http://codeforces.com/contest/985/submission/38495105

I have no reason to lie, as I said I expect a positive rating change. If I had seen these numbers when I was making a decision I would have started with E.

I just have a feeling that the issue with E is sufficient to make this contest unrated. I was impacted indirectly but many people were impacted directly.

Besides — there was incorrect author's solution, this fact should make the whole round unrated, given ACM rules. I object to policy of making rounds rated just to please the maximum number of people. Rounds should be unrated unless they ran perfectly in 100%.

What do you think MikeMirzayanov?

UPD: My fault... See comments below.Well, it is a good round ... but problem D. (No offensive).

Even though problem D itself is a good one, but it is not very friendly to the CPPers.

We need to handle two long long multiplication carefully. (

Aha! I know it! I avoid this!)And then math functions bring floating errors! (

WHAT?)Should "handling floating errors" really be the part of the contest?

My key point is : D is a good problem, but it shouldn't make certain languages better than others.(Making D's limit into 10

^{9}would be a better choice, I don't know any brute force that can pass 10^{9}but not 10^{18}).We had a solution and didn't really want it to pass. It's like one step easier than the intended one.

All calculations in my solution are performed using only integer types and fit into long long.

Thanks for replying.

OK, then I have no problem with D's limit.

So, you mean that long double is intended to fail ? Should "using long long instead of long double" be a part of the contest ? Maybe it should be but I don't know ?

Really, worst time ever : getting WA on test 7 but the logic of the program is absolutely right, struggling whether to submit again or to give up.

If you have to multiply numbers that big then you are doing something wrong? I mean, use long double as much as you want to if you are sure in the correctness of the answer you get. Or you can think a bit more and get a much smaller estimation on the borders of binary search.

No, not that, I said I avoid long long mutiplications.

I got WA using

`ceill(n/X)`

but AC (preliminary) using following code:`for(; n>0; n -= X, ++Ans);`

I don't think it is wrong using

`ceill(n/X)`

.Actually, you output 2e+009 instead of 1999999999. Maybe this was the problem, not the precision of calculations?

Yeah, I just saw that.

Thanks. Sorry for bothering.

It's my fault.No problem, it happens :D

I pass it using long double...(after contest q_q)

...

I am getting WA using long double...I am pretty sure it's due to floating errors.38530049..Please help

only use long double when you dont need accurate number

Thanks for the help Jiburiru

To make it more clear — maybe it wasn't understood for the first time.

If there were no issues, that would have been my fault 100%. However in this particular case, my decision was biased by the bug in writer's solution.

I also think that it might be the case with more people as the difference in accepted solutions between D and E is very small, while it should be something like 250 for D and 450 for E, but I guess that many more competitors jumped to D as they saw that nobody was able to solve E for almost an hour.

Most people also do the problems in order because they expect them to be in order of difficulty.

The worst excuse ever.

It is not an excuse as I will probably get positive rating change after this contest (at least this was my knowledge when writing this post)... And I'd rather give it up for unrated round as I feel that this contest was interrupted by the bug.

It just demonstrates the subtle impact of the issue. I based my decision on the number of problems solved and I got stuck on D until the end of the contest and I have a reason to believe it would not have been the case, but for the mistake.

As regards previous comment — it is not true. After 40 minutes I should have seen comparable number of solutions to both problems. If I see around 30 solutions on D and 0 on E, it is a clear indicator for me that D should be easier than E (not everyone should follow this logic).

Why I got

RUNTIME_ERRORin pretest 7? 38505110The error is caused in this line:

`while(cnt && abs( *(s.rbegin()) - *L ) > l )`

You are trying to access to the value pointed by L, but a few lines before, you erased that value from the set. I saved

`*L`

in a variable before deleting it from the set, and the Runtime Error was gone, but now it gives Wrong Answer. I'm not really sure what's the idea behind your code, so I can't help you with that. I hope this comment helps you solving the problem :)PD: there is another error in that line: you forgot to check that the multiset is not empty before trying to erase an element from it. That may cause Runtime Error too. Bye!

can anyone help with a good test case for problem E ? cannot Figure out where it could go wrong. #noob

Hi, I just wanted to mention that it seems that users with rating above 2100 are registered as official contestants... or at least they don't disappear when I unset the "show unofficial" checkbox.

Hope that doesn't causes any problem.

Educational rounds are rated for users with rating below 2100, but it doesn't mean other users are unofficial. I think, In those rounds all users are welcome to participate officialy.

In contests page, the hacking phase for this round seems to be for 12 hours rather than a day.

Problem D is similar to SRM 721 Div1 Easy.

For problem F,if the size of alphabet is up to 10^5 or larger and other constraints remain the same,is there any approach to solve it?

Can anyone tell me Problem F why my solution get WA on test 16's 9259th query? I have been debugging for more than five hours. qaq. this is my submission code: 38512729

Don't write hashes modulo 2^64 link

The string in 16's test is Thue–Morse sequence

This is the first time I know that it looks so magical. Thank you very much for your reply.

As a novice, I have a question for everyone. Why did I submit the same code twice, but one got AC, another got WA. 38509969 during the game. 38524984 after the game

Editorial??

Submit with diagnostics. Perhaps you have some undefined behavior due to the overflow or memory access.

yes...thanks

emmm.. I think your code "if(n-que.front().w<k)" has a little bug. if the queue is empty, then your code will runtime error?

maybe you are right. modified code got ac...thanks...but i still can't understand why i got a different result

maybe it's magic..hah

Problem C:Why I got TLE Verdict?38494646

I didn't use while() so there are some troubles on sort?

qsort has worst case O(n^2) I think.

Oh... I understand thx

How to fix it?

Use inbuilt STL sort — sort(ar,ar+n) where ar ->array and n->size of the array.

Fix my code to use STL sort, I got AC. thank you! 38527514

The test was designed specifically to counter quicksorts

I was hacked with this once actually

System test has finished,so is it rated?

why not rated?

Issue of the writer's solution was wrong on Problem E

(And not clear words on Problem D?)

so it's unrated? but Problem E's tests are right?

The test case was fixed after 45min the contest started(and affected some verdict).

I think some contestants waste the time because of the issue, so it's good that this contest change to unrated (or semi-rated).

is this contest really unrated.

UR?My Rating was changed a few minute ago.

Why not wait 10 more minutes and then discuss whether it is rated?

:)

when will the editorials be updated?

The rating were changed so it's rated

does hacking a solution not effect our rating

In educational rounds, No.

then what's the fun of hacking other's solution

then why do Div1 participate in Div2/ Div3 or Educational rounds?

To educate others :D

For fun.

Is there any solution for F except

O(N * 26)?http://codeforces.com/contest/985/submission/38502880 O(nlogn)

Auto comment: topic has been updated by PikMike (previous revision, new revision, compare).When will you upload Editorial??

Soon

How could i optimize my submission which got TLE on 68the case ?

Thanks for div2 only contests !11!1

__i use ideone to run the code but the solution is copied and i get unrate. Does my computer have malicious code? Explain me, please.

ideone is by default public. you can see submissions in https://www.ideone.com/recent. Maybe someone copied from there. keep your submissions private from now on. Its an incognito type icon near stdin below input text box.

Thank you very much ! I ever never know :D

Where is the editorial ?

http://codeforces.com/blog/entry/59587?#comment-432798

Auto comment: topic has been updated by PikMike (previous revision, new revision, compare).In Question C,I had got time limit exceed in test case 19 in java while with same algorithm (same code) in C++ is able to pass all test cases.

Same issue

Same issue!

You made well-known mistake: Arrays.sort() -> Collections.sort(). Sort in Arrays has O(n^2) in worst case.

Solved,Thank you!

Why my output for large inputs coming 0 for question C ? https://ideone.com/0wQyKD

In problem D,

when I use round() function to round the division operation to nearst integer value it causes me WA in testcase 18 though the round function isn't making any difference!

accpeted sol: http://codeforces.com/contest/985/submission/38600567

wa sol : http://codeforces.com/contest/985/submission/38600584

round() is not making difference: http://codeforces.com/contest/985/submission/38600633

and all of this solutions provide correct output -1 in my local machine!

Thank you.