**안녕하세요, 코드포스!** (Hello, Codeforces!)

We're glad to introduce you to Codeforces Round #578 (Div. 2), which will start at Aug/11/2019 15:35 (Moscow time). The round is **rated** for Div. 2 participants.

You will be given **6 problems** and **2 hours** to solve them. The score distribution will be announced later.

The problems are prepared by no_ng and me.

Thanks to pllk, Learner99, Rox, mohammedehab2002, cheetose, jh05013, rkm0959, edenooo, and alex9801 for testing the round. We would also like to specially thank to KAN and arsijo for coordinating the round, and of course, MikeMirzayanov for Codeforces and Polygon platform.

This is our very first round, so I hope you enjoy it a lot!

**UPD**: The scoring distribution is 500 — 1000 — 1250 — 2000 — 2000 — 2500

**UPD2**: The contest is finished. Thanks for joining us! Here's the editorial.

**UPD3**: Congratulations to the winners!

**Div. 2**

2: oliviahye

3: ccf_n0i

4: 2om_neek

**Unofficial Div. 1**

1: kcm1700

2: uwi

3: square1001

4: kmjp

5: KrK

Waiting for a good round.

You are also waiting for some upvotes, aren't you

You definitely should participate, every contest coordinated by arsijo is an ACE (absolutely cool event).

that's true, there are so many Supreme Hilarious Ideal Triumphant contests coordinated by him.

You’re just another hater. All you can do is to write hateful comments.

Why can a user with rating $$$-40$$$ be the tester of a round? That's totally unfair! I don't want to take part in this round!!!!!!

If you think it's unfair, you shall try to get your rating to -40. You'll find it very difficult.

https://atcoder.jp/users/jh05013

Mean no offence, but does this kind of behaviour give any joy

https://petr-mitrichev.blogspot.com/2019/01/and-best-problem-of-2018-is.html

BTS bring me here!!

lol

I'm your fan

It's a friendly contest time for us Chinese :)

agree，同意同意

don't agree，不同意不同意

Yeah , Not too late

Haha, I also think so. I hope we can enjoy the contest.

I can't agree more!

Absolutely Correct.

agree

It's a human race.

But there aremany Chinese .

Wow! Korean Round!

Since our hopes were shattered last time, we hope that this time is different.

Shattered again :(

Man, such a friendly time for us Chinese!

agree

Agree++

the success key for this contest is to avoid "string" word.

Hope the difficulty distribution is reasonable this time :)

I hope the problems are enjoyful.

Winner Winner Korean round dinner!

BST(Binary Search Tree) bring me here!

I want to become purple！I've been waiting for it for a long time!

Good luck to you!

You'll never become purple!

Hey guy, stop dreaming, you become gray instead of purple.

Hey unrated guy, stop dreaming, you'll never let others become gray.

Aren't you the same people?

yes, they are

Wish your high rating!

Too much new problem setter rounds recently.

Good tester

It was all done intentionally ; look at his max rating (1700+) .

some people dream to be 1700+ ,and he wasted all his hardwork just for fun ... really a inspirational guy :-D

It was the opposite, sadly. Participating in short contests turned out to be too stressful for me, so I did this instead. Now I have changed and I don't really care about messing up a contest anymore, so I might start getting an actual rating someday using a different handle.

I also wanted to see if the rating just goes down forever. It doesn't; at this point my rating goes up even if I don't solve anything.

So why do you use Codeforces? Almost all contests in Codeforces are short contests!!!!!!

You may have a big jump in some contest like vammadur did before you change your handle. Maybe you can beat him :)

you can still go lower by getting negative score from hacking, though I don't encourage you to do that.

So Mike please block jh05013's account!

Seeing your rating graph, I think you might even dream to become pupil again after you participate in 2 or 3 more rounds.

https://atcoder.jp/users/jh05013

https://petr-mitrichev.blogspot.com/2019/01/and-best-problem-of-2018-is.html

Waiting and still waiting...

Good time for Asia programmers!

If only more codeforces contests were like this..

Thank you all ...

Is it rated?

Seems not...

In the end of the second paragraph,The round is rated for Div. 2 participants.

Another Korean Round! I think this round would be wonderful round.

Me too! I can't wait for it!

I don't need to stay up late for the contest.It's a nice time for Chinese users.Wish everybody(especially me) good luck!

I love Korean people.

Such a perv

WOW! A very friendly time for Chinese and Korean!!! I won't worry about my sleeping!!!

Nice time!!!

Are you from China?

yep!

Why arsijo? I definitely don't want to take part in this contest!!!!!!!

It sounds like a beggar saying "I won't take anything from this fellow". Nobody cares.

So what? arsijo's rounds are commonly not welcomed.

So what? your comments are commonly not welcomed.

Good Luck for everyone who join this competition.

I've been waiting for this round almost one year. so hyped!

Wtf, where this dislike of arsijo is coming from? You haven't even seen this round yet, moreover, to my knowledge, most coordination work was done by KAN, and arsijo will just help to arrange the round as KAN may be busy at this time.

Also, by saying this sort of things you express disrespect to authors of the round at the same time. They did so much work, hoping you to enjoy the round, and now you dislike the round even before it began just because of coordinator.

All you guys saying "ohh round by arsijo again" are getting really annoying, not better than dumb "Is it rated" guys.

Why do you expect CF comments to make like any sense? People write random shit coz they are bored or just retarded.

Wow!! I hope it would be great round ever!

I'm your fan

good job！

I have the level to solve problem_A/B/C and more but my english level is so poor that I can not understand the meaning of problems QWQ

Finally I can take part in a contest without staying out late!

Korean-made problems and Korean-friendly contest time. It is perfect if the problems are very wonderful.

Time to go blue

Desire for becoming Candidate Master within 3 Div.2 Rounds!! :)

i think this round #778 very exciting. I hope my rank < 200 ^^

I failed to solve problem B in previous 2 contests. I don't want to make a hat-trick.

A good time.

I'd like to become blue this time.

kkkkk

I don't like problems with long statment :/

hi gamegame do you think you will win ioi 2020

Of course he will, he is such a god!

He still has 2 IOI attempts left, so it was nice of him to let Benq have his second win.

then do you think gamegame will win IOI 2021??

5:35 AM ON A SUNDAY MORNING on the US West Coast :(

Thinking the contest was at 7:35 PST, I freaking missed it. Sob with me.

what is the pretest 4 in problem B ?

I changed

to

and it passed pretest 4

I had the same problem. I did all I could but couldn't find what was wrong. Ruined the contest for me.

Same for me...First I struggled with pretest 2 but then pretest 4 destroyed me

criesI think you should add this to your code QwQ

you can't dig under 0 so you have to judge it if the next one is less than k.

How to solve D?

here was incorrect solution :(

Task E: https://acmp.ru/index.asp?main=task&id_task=1481

So how to solve it?

I think one possible solution is rolling hash

Use hash and check for maximum length prefix by iterator. See my submission 58613971

I myself solved it using Prefix function (KMP): 58619921

What is the pretest 4 of problem C?

How to reach to solution of C ?

WHat was pretest 2 of Problem B?

I used long double in C, and I am afraid of precision problems now.

DUDE SAME

I don't get it ;(

What does that

`forget about zero`

mean?assume that the heights could go negative

Yeah, I knew that was an edge case of the problem, but that meme picture just doesn't click to me. Shit, I am stupid =(

I thought this was pretest 4; thanks to that I was able to correct it.

+1

Waiting for the editorial guys!

Expected time complexity for problem D?

$$$\mathcal{O}(n^2)$$$.

Give me some ideals about this problem, bro.

N^2

N*N or N*N*log(N)

Why I keep getting TLE on pretest 11 of problem E?

I think it's O(|s|),Why?

Code

This part makes it quadratic. You should use hash for this part

Oh my god ,it's only a

ifBut how to use hash for this part,please explain further,thank you very much

I nearly know nothing about hash...

You should read about Rabin-Karp algorithm. Hashing is quite useful in problem related to string comparison

OK,I get it,thanks :P

Can D be solved in O(n*n) time?

Yes, using 2D partial sum to find out how many new white lines are created for each cell being chosen as the top-left position of the eraser.

I used divide and conquer and KMP in order to solve problem E . Though I was not quite sure if it would pass TL but my submission got the verdict WA. Can anyone help point out mistake in my solution :

My submission for problem E Apologies for the poorly written KMP.

4

sample e le ple

This test case should give output "sample"

Thanks I got it the divide and conquer was the wrong way

How to solve D ?

Why wouldnt suffix automaton solution for E pass below the time limit? I couldnt use an array bcs of memory, so i switched to maps, but that gave me tle, but the complexity is O(n*log(alphabet_size)), is the map factor just too big?

Why don't you use String Hash to compare two strings? It can be fast and easy to write.(Though it is slower than KMP)

And, the alphabet_size=26, I think you should use array to store the edge on the SAM. The factor of map is very big when the size of it is too small like this.

i jump straight to coding instead of thinkingof another solution, thats why i didnt use hash

But the size of it is very big. I think you can think about the Suffix Array to solve the String Problem. When the alphabet_size or the size of string is very big, SAM is very slow.

Oh, I didn't find that the alphabet_size is 62...

Is there any way to squeeze suffix automaton in the tl?

How are you using SAM? Constructing the terminal states after each new string takes too long and I can't see how to do it without

If we assume that we have memory to hold an array for the transitions between states, that means our adding of a transition takes O(1), then our complexity of constructing SAM is O(n), when we query for the largest prefix that is a suffix of the first string, we just traverse the SAM and if we come to the node which is coresponding to the last character inserted into SAM, we found our longest prefix which is a suffix of the first string. By n we denote total sum of lengths of strings in the input, i dont see why this wouldnt pass(only cause of large constant for the map) , correct me if im wrong

You can have more nodes corresponding to suffixes in addition to the one corresponding to the entire string. For instance if the string is $$$abb\dots bb$$$ every node corresponding to a substring with only $$$b$$$ is a terminal state.

Yea, sry, ur right, dont know where did i get that silly idea

Then, next question, can somehow suffix tree be implemented to fit the tle? To implement a treap for the transitions? Would treap be faster than c++ map? Or is there some c++ built in way to speed up map? And why is map factor so big?

Really good contest, in my opinion, even though I wasted a lot of time in A B and C. Almost had enougth time to debug E. RIP Rating twice in a row 1-1

What is the hacking test case for E?

Spent 1 hour trying to read and understand the preprocessing part of KMP. Then figured out that it can be solved with Hashing. Managed to only get A and B after that.

I still don't understand the preprocessing of KMP though.

Then MLE on test 12 :((

Can you please tell me where is a mistake in my solution of B? 58581229

I spent the whole contest trying to find what's wrong with it.

firstly you should get whole input, you should not use

breakwhen you are coding a multi-test case problem.Ahaha, thank you. So stupid mistake)

(deleted. Wrong comment)

Hey everyone, do you know what's wrong in my solution for E? 58612747

I'm foolish to use (single) unsigned long long for hash.

Why would that be a problem?

E: Wrong Answer On 65

Unluckily,I also used it……

Nice pretest for C :v

Same boat :(

Hack test case in E for MOD 1e9+7 is nonsense

Dang that sounds really unfair, although I always use weird values to prevent getting owned a little bit more.

.

edited

Can you help me find my mistake too .

Link to submission to B

This line:

`if(arr[i-1]>=arr[i]) c+=min(k,arr[i])+abs(arr[i]-arr[i-1]);`

The conditional is unnecesary, because you can add blocks to the bag while arr[i-1]>arr[i]-k. With that, the sum changes too, the absolute value will generate wrong answer. You should change that line to:

`c+=min(k,arr[i])+arr[i-1]-arr[i];`

Thank you so much..You are a lifesaver..

R.I.P. for my single Hash (use unsigned int) in Problem E

Wrong Answer On Test 65 TAT

Great

Hash-Killer!I will never use single Hash in Codeforces again...

Tips: Using some

unusualprime numbers to model can help you pass Elike NTT model number $$$998244353=119\times 2^{23} +1$$$ ...

My single hashing using $$$M = 10^9 + 9$$$ and $$$P = 67$$$ passed here 58620113. Ignore all the calculations in the end in

`isEqual`

function I only check the equality of the 3rd hash.Edit: uphacked :D. It would be appreciated if people could share in this thread some tips to make string hashing more probable to pass :)

just use random module, smth like 1e9+rand(), and then find the nearest prime

Why does Problem D use "cin" get timeout results?

Please add this in your

`main()`

，in front of your`cin`

What an interesting way to trick the plagiarism checker. Isn't it violation of the rules?

Maybe not.

This is a well-known skill in China to speed up

`cin`

, and cancel the influence from`stdio`

As far as I know, lots of chinese OIers use this skills in their own codes.

For honest, maybe sometimes using

`cin`

ismore convenientthan using`scanf`

, (like Probelm E), and this skill can make`iostream`

faster.So why not use this?

LOL. Take a look at the code first.

Sorry, it’s my fault.

Although this skill may help him little...

Actually I also tested without input optimization and checked if they pass just fine. I think that barely-readable code is either not O(N^2), or is extremely badly optimized.

https://codeforces.com/contest/1200/submission/58638010

My submission got TLE on test 3 but it passes the pretests. How is this possible? .-.

When will the rating be updated?

Congrats :p

Can someone explain what happens in problem C when both n,m are 1 or any one of them is 1?

Please, Can anyone help me know where my solution for problem C fails.?

My Solution

+1

float precision

where exactly?

Using

`long double`

works.Or maybe $$$\frac{(x+y-1)}{y}$$$

Thanks, that worked.

https://codeforces.com/contest/1200/submission/58612411

https://codeforces.com/contest/1200/submission/58619785

EXACT SAME CODE PASSES AFTE CONTEST??? I'm that unlucky to just get the wrong base on test 19? Are you kidding me? Can I get this restored?

Use kmp

God damn it! I feel so unhappy now (prob.C). I got WA on main test 35 because of real number rounding :(( (look at the selected text parts) In the contest I code like this: During Contest After that I fixed a little bit and got AC :(( After Contest Who has the same errors like this? Show me your hand bruh =))

For Problem E，why hash algorithm fail？

Use double hashing

Please someone tell why my solution for E is failing at case 8. Though the expected and actual output seem to be same.

https://codeforces.com/contest/1200/submission/58612328

Basically I had the same idea and my submission failed too. Can someone please help us to understand the error?

Why my submission failing for no apparent reason?

58615776 Please Help B question

When you do the sum m+= k-abs(h2-h1) you are forgetting that the number of blocks of height h1 could be less than k-abs(h2-h1), so when you do that sum, the remaining number of blocks of that pile become negative, and that's impossible. So, the sum is m+=min(h1, k-abs(h2-h1)), and with that the number of blocks will never be negative.

Thank you very much. My bad I overlooked it.

My rating becomes 2019 Nice number LOL

58606364 What is wrong with this solution for B ? It fails pretest 4 test case no. 6, but when i run that particular test case on an ide, it shows the correct answer.

If

`h[i]<h[i+1]<k`

,then`m-=b`

makes 'm' increaing ,obviously it's not true.Why won't m increase in that case ? Suppose h[i]=4, h[i+1]=6, k=8. Then we can collect all the 4 blocks from h[i] and transfer to m,right?

Sorry it doesn't mean that. Well ,

`k=160,h[i]=47,h[i+1]=107`

then u should make`b=-47`

but not`h[i+1]-h[i]-k=107-47-160=-100`

,right?yup, got it. Thanks :)

58580810 Could somebody tell me where is my mistake? It's my first time to be hacked in problem A and I'm gona to be crazy. T_T

Look into your (**left, right**) variables they took

samevalue in testcases. Two costumers cann't entersameroomOMG ,thx for u saving my sleeping.

Any ideas to solving F?

As i said in this comment i got TLE on test 3 but it doesn't make sense because the the code passed the pretests.

And the same code after contest got AC.

WTF?

And i lose rating because of this.

Why is this? djm03178 MikeMirzayanov

Because the actual running time can be different every time it's executed. It sometimes happens when your solution is almost at the edge of the time limit.

Check the time of the cases, they're not in the edge of the limit...

935ms is pretty close to 1s, I'd say.

Unrated

Someone explain D?

consider for each column and for each row, all the available left-top positions of the cfpaint which can make this column or row all white form a rectangle. We define left-bottom position of this rectangle as (x1,y1)，right-top position of this rectangle as (x2,y2),and then we need to add 1 to all the position(x,y) which satisfy x>=x1 and x<=x2 and y>=y1 and y<=y2, for this purpose, you can solve it like this: init dp[n+1][n+1] all value as 0,and when you deal with each row or column,first find the available (x1,y1)and (x2,y2),then just do like this: dp[x1][y1]++,dp[x2+1][y1]--,dp[x1][y2+1]--,dp[x2+1][y2+1]++. after solve all the rows and columns, you iterate over dp[n+1][n+1]，set dp[i][j]+=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]，after this find the maximum value in dp is just the answer.

경합이 아주 재밌었고 레이팅도 올랐고 덕분에 "아무개"란 단어도 배웠어요! 고마워요ヾ(❀╹◡╹)ﾉﾞ❀

Thanks to this contest I learned a Korean word "amugae" and gained +25 rating points, thank you very much!

I have received code coincide message for problem C,Here is the two links:58583425 58592979 I admit that these two codes are very similiar. But it is truly just because the solution for problem C is so simple and the codes between us written similarly accidently.What's more, not only the codes between us looks similiar,many codes are. I have tried to comunicate with Mike, but I didn't get any response yet maybe Mike is very busy now. I just want to show thst I am honest to participate in the contest.

For problem

F, can someone explain how is theLCMterm coming? (Specifically, how is the number of states for a particular vertex 2520 and the logic behind decomposition of the graph in various states).I'm not sure what the author means by

statehere.Can anyone explain me why my first submission got TLE and second got AC? I think the both code has same complexity. Thanks in advance. :)

1st submission: https://codeforces.com/contest/1200/submission/58837253 2nd submission: https://codeforces.com/contest/1200/submission/58837269

Why problems aren't rated yet?

Edit: They're rated now!