<almost-copy-pasted-part>

Hello! Codeforces Round #570 (Div. 3) will start at Jun/26/2019 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that **the penalty** for the wrong submission in this round (and the following Div. 3 rounds) is **10 minutes**.

Remember that only the *trusted participants of the third division* will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a *trusted participants of the third division*, you must:

- take part in at least two rated rounds (and solve at least one problem in each of them),
- do not have a point of 1900 or higher in the rating.

**Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.**

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Mikhail PikMike Piklyaev, Maksim Ne0n25 Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round.

Good luck!

I also would like to say that participants who will submit wrong solutions on purpose and hack them afterwards (example) will not be shown in the hacking leaders table.

</almost-copy-pasted-part>

**UPD**: I also would like to thank Ashishgup and kocko for help with round preparation and testing!

**UPD2**: The contest will be extended for 15 minutes because the problems are more interesting than we thought. We also advise to read all the problems because some of them may have the same difficulty and we cannot know which one will be easier for you than the other.

**UPD3**: Editorial is published!

**UPD4**:

Congratulations to the winners:

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

1 | MbahFaishol1937 | 8 | 248 |

2 | bertmin | 8 | 450 |

3 | BaiBatyr | 8 | 455 |

4 | LJF007 | 7 | 305 |

5 | proizvedenie | 7 | 322 |

Congratulations to the best hackers:

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

1 | Nazarbek_Baltabaev | 120:-90 |

2 | Radewoosh | 75:-21 |

3 | yzm10 | 36:-2 |

4 | csegura | 31 |

5 | shaker007 | 30:-11 |

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

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

A | blast | 0:01 |

B | Kirill_Kudr22 | 0:04 |

C | I_love_HellHoleStudios | 0:04 |

D | divya_rawat | 0:10 |

E | llbra9z | 0:13 |

F | FlyInTheSky | 0:42 |

G | MbahFaishol1937 | 0:27 |

H | UMP45 | 0:25 |

why I m struggling in Div.3 ? how can I improve my DP & graph solving ability?

Maybe this can help: https://codeforces.com/blog/entry/47516

You can follow my DP lists to practice Dynamic programming.

hack this submission if you can :) 56132099

Done :)

what about this one? 56133777

Hacked

not any more! 56136001 (ps: I just uniqued all numbers)

UPD: definitely not this one 56136056

I think that this last one is fine. At least I cannot hack it.

Hoping for a good contest!! Was awaiting Div3 eagerly.

"You will be given

6 or 7 (or 8)problems and 2 hours to solve them." It is so vague. Though It'll be decided later.The contest is running with no problems showing, i guess they still couldn't decide ;-)

ddos attack

Div.Vovuh xD

I hope to become purple after this round!

If you solve all problems and take first place, that might be possible

I hope to become red after this round!

you can safely stop doing these, they are useless. stop spamming the website

I find difficulties of problems from Div 3 are as same as Div 2!

Why do u think so?

It's from my experience from Div 2 and Div 3 contests I've participated.

I don

`t think so. Probably, u can`

t solve 3 problems sometimes even when u`re blue, but in div3 u canI used to think the same when I was around your rating, but once you reach somewhere around 1500, you will notice you are able to solve 4 or more problems in Div 3.

experience ?!!!! you mean solving at most 1 problem in more than 15 minutes in less than 10 contests ? are you sure you know what the meaning of experience is ?

maybe it's right when you solve only 1 problem. My experience: 3 div.2 / 4 div.3 (year ago) 4-5 div.2 / 6-7 div.3 (now)

OK, I got it. If I go to advance level I will get the difference. Thank you guys

because you're so bad at coding. if you aren't advancing, why do you keep trying and wasting your time with this cp bullcrap? move on kid....

I know what I'm doing. Didn't ask for your advice. Piece of shits everywhere

The creators of the contests have sufficient intelligence to differentiate problems of Div 2 from Div 3. Trust them.

That's because you solve only one problem during the contest regardless of whether it is Div2 or Div3. So you find both of them same.

OK. got it

Vovuh can stay on top of the contributors table just by organizing 1/2 Div. 3 rounds per month xD

Hope I will turn pupil after the round :)

I wish you good luck!

EDIT: when you get downvotes for cheering someone on xD

Thanks :)

Good luck everyone, i hope for a good contest for all of us.

1.it won't be

why ?

Div 3 after long time.

Tired of helping Vasya and Petya !

And Nastya.

Also Tanya, Alice, and Bob.

They always screw us with their so called games.

yup

when these persons are testing the round , the chance of hack comes down a lot !

It becomes zero in some questions(B) as they have to remove then xd

The winner of this contest name will start with 'g'.

## MyPrediction

Really!?

Handle or Name ?

DIV-3 contest is always missed by Vovuh. :D :D :D

Does the countdown work correctly? It says 7:05 before start!

wow new contest from vovuh

i love you man

The temperature is higher than my meme contribution

good luck everyone,hope your rating will increase

where are the problems

There they are!

Unable to see the problems.

invisibleforces !!!

also downforces!!!

Same here

EDIT : fixed

Not able to see problems. Is it only me ?

question is not opening

what is going on with interface?

why i can't ask an question????????????

you just did

Anyone else not seeing problem statements??

WTF

it is not showing !!!

But where are the problems. Contest is running without any problem set

I like your handle.

Oh time is running although there aren't any questions!

seems like, it's gonna be an unrated contest

no way ...no one has seen the problems ..they will extend the contest

what's happening codeforces..

i can't see any problem

I cannot see the problems.

no questions?

Problems??

problems aren't visible.. lol

Where are all problems? Are we a joke to you?

wait first 15 minutes

Hello, there is some issue. The problem set is not loading.

Why everyone is writing same comment of not able to see the problems ?

are there any hidden questions :(

I can't see any problems in contest main page.

can't view any problems??

Where are the problems, I can not see them

I cant enter in this round.Help plz

Why problemset is invisible?

Problems?!!!

So many submissions already and i am just receiving the problems... Will it be rated?

Sir, I share this concern.

The problems were not visible and suddenly I saw 3000 people have already solved the first question

will there be extra time for the delay?

unexpectedly ez round...wish u guys good luck.

Yet another internet speed round XD

Queryforces

problem C is easy but hard to implement...

< 10 lines in python for me

Could you please explain the solution. I mean pseudo code

You can consider the formula for how much additional charge you will need, where "out" is the number of days you don't charge: neededCharge = (out*a) + ((n — out)*b) — k + 1 Specifically, we need neededCharge to be less than or equal to 0, so we can set out based on that. Simplify to get out <= (k-n*b-1)/(a-b). So, set out = floor((k-n*b-1)/(a-b)) Then, if out is less than 0, your answer is -1. Otherwise, your answer is min(n, out).

I am having understanding the problem, could you please explain the problem. I will really appreciate it. Thanks.

can any one explain problem D ?

store array containing frequency of i in arr[i]. sort all values in reverse order, now for all elements after 1st element in array, its value is min(arr[i],arr[i-1]-1). Answer is sum of positive values in array.

Problem E is more easy for Java people

How,Can you please explain?

Thanks for the contest!

For anyone who had a hard time with any of the problems, I wrote up descriptions of my solutions, which you can find at this link. If you have any questions, feel free to post below.

Thanks, I think it'd be a bit easier to read if you posted this as a blog and if you have the implemented code, to share it.

Good idea—I’ll post this soon. Thanks!

Geothermal {May be I am wrong}...

I tried D using max-heap but at the 19th case the response was TLE .. but as you guys have used sort() method [complexity will be nlogn]. So, as Mine...

https://codeforces.com/contest/1183/submission/56128383

any suggestion where am I wrong???

I'm not sufficiently familiar with Python to debug it effectively, sorry.

Geothermal thanks for the response ...sorry, I don't want you to debug my code ... I am just asking whether max heap is a good way to solve it ..

pseudocode:

So, for me its O(nlogn) ... n for removing the elements and log(n) for maintaining the heap...??? am I correct?? ...

The blog is up at https://codeforces.com/blog/entry/67973.

Thanks for your effort. I looked into it. I found that explanation of Q.F was difficult for me to understand ( or maybe because i have used another method .) Can you tell me in short what you did ?

My method : I found out during the contest that if there is a solution which doesn't have max element (let's say m) . Then the only better option can be m/2 + m/3 + m/5.

Yes, I think we used different methods (although I know other people who used your approach too). That's a clever solution--my method was essentially a pruned complete search. I noticed that any number under 200,000 can't have too many factors (more precisely, they have at most 160 factors). This lets us considerably reduce the number of possibilities we have to search through, and from there the rest is essentially a bash.

If I'm not wrong, you take 340 problems as a candidate for first problem , and for each of them you take next 170 as second and 340 as third candidate ?

I took 340 problems as candidates for the first problem, then for each potential first problem, I chose 170 candidates for the remaining two problems. I then did some optimization so that I could pick the best pair of problems in ~170 operations rather than by considering all possible pairs of candidates.

getting tle in test case 6 problem g https://codeforces.com/contest/1183/submission/56137010

How to solve G?

Edit : This is for Problem H.

Consider dp[i][j] -> number of distinct subsequences ending at i, of length j. Then,

Where prev[i][c] is the maximal index before i, that has value c.

Is there only dp solution? I've tried whole round to think greedy one

i'd say, that this is Dp + greedy

How does it make sure that only unique subsequences are counted

How can we take care of Overflow??

Totally, I could not understand the problem C :(

it takes me more than 40 min to understand :(

You can consider the formula for how much additional charge you will need, where "out" is the number of days you don't charge: neededCharge = (out*a) + ((n — out)*b) — k + 1 Specifically, we need neededCharge to be less than or equal to 0, so we can set out based on that. Simplify to get out <= (k-n*b-1)/(a-b). So, set out = floor((k-n*b-1)/(a-b)) Then, if out is less than 0, your answer is -1. Otherwise, your answer is min(n, out).

"For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova

CAN JUST PLAYotherwise"The maximum number of turns Vova can just play that is

without charge and play.How to solve E?

dynamic programming dp [i] [j], the number of different strings of length i ending in j letter

Could you explain how do you ensure that we don't count the same string twice while building the dp. Thanks in advance.

Try to understand it yourself. Let's get another matrix used [i] [j], indicating whether there was such a state before. If it was, we simply reset dp [i] [j] and recalculate the answer for it since this time we will have more different lines of length i ending in j.

Thanks for making me figure it out myself..

Actually BFS is ok...

In test case 4 of E why cost int not 232 — 1*0 + 10*(10-9) + (C(10,2) = 45)*(10-8) + 44*(10-7).

UPD : Got it. I made a mistake.

why there was no hacking ? and when the ratings will come up ?

Read the Announcement of the round

In Division 3 rounds, hacking occurs for twelve hours after the contest. Ratings will update after the hacking phase and system tests finish.

Thank you for your explanation would you tell me how to hack somebody now ?

The Hacking phase in Div.3 comes after the contest like educational round

The rating will come up after finish the Hacking phase

What if I try to hack but fail?

Nothing happens in your penatly

great round I would say but the complexity of the tasks > D is quite high for a Div. 3 contestants

Damn I could solve E I think.. isn't it trying all the possibilities and if it took too long we would output -1

No its not you wold definitely get TLE or WA for that the solution . just consider a 100 letter string with same characters and k=99. you can use dynamic programming to solve it.

Yup it's no good to solve it like that I will try it later

Why DP. I thought it is a implementation type problem. I got pretest passed without DP.

Yes I thought of an implementation solution like yours but unfortunately I wasn't able to solve the hard version with it so I used DP to solve both of them.

It is possible. My (updated after contest) solution: http://codeforces.com/contest/1183/submission/56154439

what do you mean by possible . I'm sure you didn't simply tried all the possibilities inefficiently.

I tried all, but stop when I achieve k number of possibilities. Sure, it's not fair "all". But it's kind of brute force.

Hahaha, trying all possibilities? Did you read "substring" instead of "subsequence"?

Just as a side note, total possible ( without removing repetitions ) number of subsequences is $$$2^N$$$ where $$$N$$$ is the length of the given string.

Did you read reza comment .. yeah I get it and I know the possibilties could be large but I thought if we didn't find 100 substring after 1e8 possibility then there's no answer but as reza said 100 same letter wouldnt work with this way

Oh my bad then. But you didn't clearly mention what you were going to do? I accept I misunderstood here, but you should have said something like "Since $$$K$$$ is small, we can just find those many subsequences and then stop". This gives better idea of what you were trying to convey.

Anyhow, I must apologize for my misunderstanding. Sorry for that! I shall read more carefully from now on.

yup i got Accepted with your approach :)

can I hack my own solution???????

Yes

I remember once binaryboy1 did this with him self :|

How will be the scoring then?

you will not be provided scores if you hack your own solution

Thanks for the contest!

Why am I not a trusted participant since I have participated in more than two rated rounds and never had +1900 rating?

The user CaNDidaTE_FaSTer cheated again.

He somehow find the solution of problem H of sraman915

Submission by sraman915: 56104958

Submission by CaNDidaTE_FaSTer: 56124086

I think he should be banned from Codeforces as he did cheating multiple time. The another cheating caught by me is here

I am drawing attention of MikeMirzayanov

Who are you LE_ROI? :D :D :D If you can prove this I will give you everything in this world. Please don't wast your time to see other code. Nijher chorkai tel dao. Copy past codeforce onek valo dhorte pare. I don't know who is sraman915. Hey Sraman are you know me? LE_ROI are you man or woman? :D :D :D

The question is all about

finding the distinct subsequences of length K. after that one can easily figure out the solution. I googled it and found something relevant which I have also mentioned in my code.I don't know CaNDidaTE_FaSTer but after seeing his solution I think he has also used the same thing but he forgets to mention in his code.

Yes, you are correct. But I don't copy and past. I just use google to find out

finding the distinct subsequences of length K. Thanks you sraman915.Hey. I have also taken code from that site, although I was not sure whether I should use that code. Are we allowed to take code from other sites during contests?

Yes, googling is a must skill. It does not violate any rule of CF.

You can take any code that is not copyrighted except the code from current participants of the contest.

Okay. Thanks for clarification.

It seems he has copy and paste code from Internet source. It is clear from inconsistent indenting. Many people have done this. I don't believe he has cheated.

TIL that declaring a massive vector makes a big difference in time complexity. (vector (MAX)) https://codeforces.com/contest/1183/submission/56113733

https://codeforces.com/contest/1183/submission/56126400

https://codeforces.com/contest/1183/submission/56126075

https://codeforces.com/contest/1183/submission/56126321

I thought that declaring a vector only takes up space and not time.

TLE https://codeforces.com/contest/1183/submission/56117801 AC https://codeforces.com/contest/1183/submission/56126830 The only difference between 2 submissions is I declare the array inside main

Why I got TLE ?

Have a look at my submissions I got plenty of TLE's for the same reason on D. When you declare your array globally of size 2e5 and when there are 2e5 queries it will become O(10^10) because you are initially array of size 2e5 everytime. That's why array should be dynamic to take advantage of the fact that the sum of n over all queries is <2e5.

How to solve G?

When I tried to hack others solution with my testcase.I am getting generator crash error Since it is valid. My test case is : : test case

(for Problem D )

It is because you are generating a testcase with 200000 queries where n=200000. However, in the problem statement, it is mentioned that "It is guaranteed that the sum of n over all queries does not exceed 2*10^5 ".

Hello i am very new to codeforces will anyone tell me that after participating in div 3 and solving 2 questions why there is no effect on my rating??please tell me Thanks :)

Right now, hacking phase is going on which will continue for 12 hours. So, ratings will be changed later after the hacking phase ends.

Thanks

the rating changes will ocurr after finish hacking phase in 12 hours

can anyone explain..how to use DP in problem E?

Sure. Sub-problem : Count number of distinct subsequence in a string ? Sol — I'll use 1 based indexing. Let DP[i] be the number of distinct subsequnces ending with character s[i]. Then if character s[i] did not occured before then we can chain it to all distinct subsequence occured before this position i.e. we can freely choose second last position in our subsequence DP[i] = sum of all DP[j] for j < i. If s[i] occured before then we don't need to count second last position before last occurence of s[i] because they are already calculated DP[i] = sum of DP[j] for prev[i] <= j < i. where prev[i] = last occurence of s[i]. Base case is empty subsequence. DP[0] = 1.

Original-Problem — Just add length state in DP. DP[i][j] = Number of distinct subsequence having last character s[i] and is of length j . Base case DP[0][0] = 1.

This solution is O(n^3) but can be optimised to O(n^2) by calculating prefix sum DP for each length layer.

While finding best cost in problem : Start taking subsequence with maximum length.

very nice round . congrats

Can somebody please explain the graphical approach to problem E?

queriesround.can somebody explain how you think problem B solution thanks in advance

Take the item with the least price, if you increase this price by k, you will get the maximum price this item can be given, Now the range of prices for this item will be, assume price as 'a', [a,a+k], Now look at the item with the maximum price, you can change it's value to anything in the range, (let price be 'b')[b-k,b+k], if you take intersection of these ranges, you will get the range in which all prices of other items can be brought to,i.e, each item in the array can be brought to some price in this intersection, the maximum of this intersection will be the answer.

In B we have a sure move to maximize the common price, if that is not possible there can't be a common price.

After sorting the prices, if we increase the smallest price by k(maximum possible increase), and if the product with largest price is less than a[0] + 2*k, then there exist an increment or decrement of a value less than k to reach that maximum possible price. But if the product with largest price is greater than a[0] + 2*k then there is no such price that the smallest and largest initial price product can have in common.

thank you

Can someone please review my solution for B: https://codeforces.com/contest/1183/submission/56089281

I think I got lucky, since I don't even know what I was intending to do. My logic made sense in the start, and I kept changing the conditional to pass the example input.

Perhaps it will not pass sytem tests.

I think your solution is correct. After sorting the array, to print (a[0]+k) as answer, we need to just check if (a[n-1]-k)<=(a[0]+k) or (a[n-1]-a[0])<=2*k. Instead of checking only for a[n-1] (or max element), you are checking for all elements which is not necessary. So it should pass system tests.

Thank you for your reply. Yes I noticed this too. I wasted time being confused with myself. I fully understand it now.

Problem statement of C was not good, it took me around 30-40 minutes to understand the problem statement.

In the third problem, when I submit the solution with pypy I am getting TLE(time limit exceeded) in test 27 but when I use python 3 my solution is getting accepted. What is the difference between them and why did coordinators asked to use pypy??

edited: Solution with python 56132978 Same solution with pypy 56130341

I did some research and found out that the problem is

+=when I tried solving with replaced+=in pypy my solution was accepted.Good round and good tasks. Thanks, Vovuh!

Will hack score?

not in this one

.

How can I figure out what's wrong with my code when I get a WA on a mile long test case?

Create a program that generates a (small) testcase, generate one as long as your output equals to the output of a bruteforce/copied model solution.

The solution itself is more or less bruteforce plus I tested the code for a lot of small cases by hand so I'm really surprised that I get WA

The best div 3 I ever seen. But different in complexity between D and E was too hight.

Hey codeforces ,

Please check my blog where I have revealed a big fraud that happened in today's contest !

What these two users did is just unbelievable, I hope MikeMirzayanov will do something about the subject.

problem G getting tle on test case 6 https://codeforces.com/contest/1183/submission/56137010

https://codeforces.com/blog/entry/20553

My solution I'm getting trouble with problem B. Could anyone tell me what's wrong with my approach?? please...

When will the problem analysis be published?

any help pls!,why this code fail in test 3 problem B? https://codeforces.com/contest/1183/submission/56142029

how to solve E?? plz someone explain it in simple words

Use breadth first search. Nodes are strings. Edges is removing one character from it. Use map or set to remove duplicates.

For E u can simply bruteforce...Generate unique strings by deleting 0,1,2,3... characters from given string until size of 'S' becomes K... To generate all string u can use a queue of string and push the given string into it now take the front of queue, generate and push all unique string by deleting a character from it. Repeat this until queue becomes empty... You can refer to my submission

Are all the solutions rejudged? I had solved 3 problems but now it is showing none. What is the issue?

One of the worst contests ever. Terrible test cases, and for some reason, all questions had the same weight which doesn't make any sense.

Does our rank go up if we do successful hacks?

No, just in div.2 or div.1 you can hack and come up your rating

Thanks..and btw when will the ratings be updated?

as soon as in these moments

Editorials?

Interesting problems.

systems message:"Внимание! Ваше решение 56108275 по задаче 1183E значительным образом совпадает с решениями других участников и находится в группе одинаковых решений lukamosiashvili/56108275, Whatever.../56123536. Такое совпадение является явным нарушением правил. Отметим, что непреднамеренное утечка тоже является нарушением. Например, не следует пользоваться ideone.com с настройками по умолчанию (публичным доступом к вашему коду). Если вы имеете неоспоримые доказательства, что совпадение произошло по причине использования общего источника, опубликованного до соревнования, то напишите комментарий к посту о раунде со всеми деталями. Подробнее можно прочитать по ссылке http://codeforces.com/blog/entry/8790. Такое нарушение правил может являться основанием для блокировки вашего аккаунта или других штрафных санкций. В случае повторения нарушений, ваш аккаунт может быть заблокирован." I can not wonder how he copyed my code, because I not gived him my code.

Where Is The Editorial?

any editorial/tutorial please? :)

https://codeforces.com/blog/entry/67973

unofficial and please stop making these comments before reading other comments in here, you're creating useless messages which waste people's time when you could have just scrolled up a bit and found what you were looking for.

The test case in problem c on which my code was hacked is showing same solution on one of the correct submissions .Are there any other reasons of a code getting hacked ?

It might be giving TLE.

Yes it was that only thank you.

Where can I get editorial of this contest?? Plz help

It is not uploaded yet!

Can someone please explain how to solve the last problem(H)?

Wow, this is my first time on the list!! Happy:)

This may sound dumb but I still dont understand Problem C- Computer Game. What is different between output 0 and -1?

NOTE: In the first example query Vova can just play 4 turns and spend 12 units of charge and then one turn play and charge and spend 2 more units. So the remaining charge of the battery will be 1.

doubt: TEST CASE: 15 5 3 2 If Vova can play 4 without charge and then 1 turn with charging then why is output 4?

Help would be really appreciated

It’s all based on the completion of this game. In worst case you may output 0, otherwise output -1 when Vova cannot complete anyway. Vova can complete only if after each of n turns the charge of the laptop battery is

strictly greater than 0. If it is equal to zero, it can only output -1, but it is not good.The answer that the setter is looking for is the maximum number of turns Vova can play

without charging, so the last turn (the play and charge turn) does not count towards the final answer. That makes the answer 4 instead of 5.I am a begginer and most of my codes face TLE.Please suggest?

keep in mind the constraints and optimize accordingly

Thanks

If you are Python programmer, consider using C++ instead of Python when you submit your code

what is wrong in my code;

## include

using namespace std;

int main() { int a,n,b,d,c; cin>>a; d=a; while (d != 0) { b = d % 10; c = c + b; d = d / 10; } if((c%4) == 0) {cout<<a; } else {n=c%4; a= a+n; cout<<a;}}

You should write a loop to find a bigger answer than "a" in the else statement.

ohh i found my mistake. thanks