Hi!

I'm glad to invite you to take part in Codeforces Round #562 (Div. 1) and Codeforces Round #562 (Div. 2), they will be held in May/26/2019 18:35 (Moscow time). The round will be rated for both divisions (^人^).

Participants in each division will be offered five problems and two hours to solve them.

The problems were written and prepared by me. Thanks to KAN for his help with the round, to sunset, TLE, Sooke, isaf27, Lewin, Aleks5d and wrg0ababd for testing and task discussing! Also, thanks to MikeMirzayanov for amazing systems Codeforces and Polygon!

Congratulations the winners!

Div1:

1) Vn_nV

3) Errichto

4) maroonrk

5) Um_nik

Div2:

1) soros666

2) lelolas

3) ndmitrovic

4) prick

5) qk0qhh

1

Glad for another Div1!

How many problems are shared between Div1 and Div2?

Why do you ask?

why he should have reason?

Sometimes it helps to understand the difficulty of the problems.Nothing else.

Usually,the problems "C""D""E" in div2 are the same as the problems "A""B""C" in div1,respectively. As a result,there are three problems shared between div1 and div2.

I wish problem statements are short like this announcement!

I hope so too.

Why are the links for both divisions duplicated in the attachments section of the annoucement ?

same to me :(

so relatable :)))

300iq's problems be like:Hahaha

Your comments be like:

can you explain this meme, I know its too lame to ask but I wasnt able to get it. Is it about W+A wrong answers and W+orrying about corner cases?

Yes

so real

Long time no see!!!

Lets have a great contest Guys.Enjoy everyone and best of luck for it300iq is return back with awesome contest :)

I hpe the problem statements are as short as the announcement :)

Which is Harder Red in Codeforces or Grandmaster in chess?

See this Quora answer by I_love_Tanya_Romanova

Ok, thanks.

Can't believe being red is easier.

How many problems will be in contest?

Just wait for another 30 mins. And you will have the answer to your question.

5 problems

Participants in each division will be offered five problems and two hours to solve them.Dude, please read the announcement.

I like weekend competitions, thank you 300iq

Anyone else facing problem in hacking? I get 403 when I try to open code even though I locked.

()

hahaha :)

How to solve C? I could easily write O(nm) DP solution, but how to optimize it?

I used binary search from 0 to m for O(nlog(m))

I tried to go for this approach too, but couldn't figure out how to simulate given an answer.

have some int prev = array[0]

i = the max number of moves a number can increase.

for every int a, if a > prev, check if it is possible to increase a to prev in i moves. If not, prev = a.

if a < prev and you cant even get to prev by increasing a i times, return false,

how to check for some M if its possible?

Go from left to right through all the numbers. Attempt to turn the input array into a non-decreasing array. Say when you're at a given number, the biggest value yet has been X. The current number has value Y. You'll be either able to transform that number into X, or increasing the value of that number will be worthless; so if (Y+M)%M > X, the maximum of the array remains unchanged; else, if Y is also < X, then that M isn't valid.

got it, thanks

Yeah me too

Use something like a binary search...

Say we can use k operations to make it non-decreasing. We can obviously do it in k+1. So search for value where it will be impossible to do in lesser steps.

See this Solution

Thanks

what about a binary search for the answer?

The way I did it was using binary search because the answer is in [0, M]. Checking if a value is a valid solution means doing a greedy: attempt to turn the input array into a non-decreasing array with a set of operations, lesser than value X. If value X is valid, then you might find another answer lesser than X; otherwise, the answer is surely bigger than X.

That greedy verification implies going from left to right through all the numbers, and at a given number, you try to approach the maximum of the array as much as possible; that means either not doing anything with the number, or otherwise, you can always set it to that maximum of the array.

Well, I hope this logic works, still waiting for hacks

That moment when I realized problem B can be done by sole bruteforce...

I need better observation tho :D

Which bruteforce?

Every substring of length 9 contains a triple such that $$$x_s = x_{s + k} = x_{s + 2k}$$$. This allows for a brute force solution to pass.

How did you get that?

I couldn't figure out a way to prove it during the contest. So I just wrote a brute force code which checks for every length N string, whether it contains a triple or not. It only took about 10 minutes in total.

It felt like because there are only two characters, avoiding those triples seems pretty hard. If you want to avoid triples, the number of restrictions on the string grows faster than the length of the string. So I wrote a script to verify all cases. Maybe there is a nicer way to prove it, though.

I just assumed it cannot be longer than 20, with a huge reserve, since if fits in TL easily anyway.

I don't know if there's a particularly nice proof for this case, but the general version of this problem has been studied and some values are well-known: https://en.wikipedia.org/wiki/Van_der_Waerden%27s_theorem

Yeah, the 9 on top left of this table is actually the same 9.

Ramsey theory did seem like a thing to think about, the problem is that Ramsey theory tends to give absurdly huge upper bounds.

deleted. :\

I did that in the end,but how to prove it fits in TL?

I'm not sure about proving, but by generating all possible cases, the longest "shortest pair $$$(l, r)$$$ with fixed $$$l$$$" would never exceed $$$10$$$.

Good tasks, thanks)

How to solve C? Tried some mo's algorithm, then realized that I forgot it has to be in order.

For each i and bit position b compute the smallest index

`minReachable(i)(b) >= i`

such that`a(minReachable(i)(b))`

has bit b set and`minReachable(i)(b)`

is reachable from i.Processing the query: reachable if there exists bit b set in a(y) such that

`minReachable(x)(b) <= y`

.54686628

Congratulations to rahuldugar for becoming red.

I hope so.

Thanks:D

Was anyone able to hack anyone?

If so, what was the hack

I was able to hack two with this — 7 7 1 2 6

A, C and E are cool, B quite standard, D tedious but still not so bad (because it requires some ideas and observations). So the round was nice but WTF is up with those Shi/Fou instead of YES/NO? I had to look back into the statement every time I run my code. This should happen only if problems are translated from a local contest to CF mirror. Don't do it in the future.

I feel the same every time I see TAK/NIE in polish tasks.

At least "NIE" has some resemblance to "NO" (same first letter) so it isn't that bad. Same if it's in some other random language like Nein/Nyet.

Ofc. using TAK/NIE would still be stupid in a CF round that doesn't come from a local contest.

That comment made me looking up all CF contests your did and surprisingly I haven't found a single TAK/NIE

Maybe I don't take problems from local contests? :D

No, I just've thought you might've changed your opinion in the past (I personally don't see anything bad in TAK/Nie and Fou/Shi) and it would've been amusing to look that up now :)

It's because 300iq is learning Chinese recently.

C is cool and B is standard? Didn't you swap the problems?

I like dynamic programming, but indeed C was standard (still cool for me).

I got the idea for B in 1 minute that long strings have such triple, after failing to construct a big string that doesn't. Something like this appeared in many problems.

I got it fast too, but it was pretty cool in my opinion. Don't remember problems using that idea.

Here is a problem with similar idea. Today's problem is a case of the Van der Waerden's theorem

const string yes =..., no =...;

Oh, i thought that it won't be a problem..

I'm sorry if it spoiled the fun of the contest for you :(

It doesn't ruin on the contest, but it's something very easy to avoid for other setters, and I hope my comment will prevent any future occurrence of something like this.

Btw, why is D tedious? The intended solution has a very short implementation in ~100 short lines.

Ok, I change my mind. My implementation is much longer because I did more (unnecessary) things.

Hi! Can someone please tell me why greedy approach does not work for div2 C? (C. Increasing by Modulo). This is the approach I am talking about: for all arr[i] where i>1,<=n if(arr[i]<arr[i-1]) either increase arr[i] or decrease arr[i-1](increase to m, then to arr[i-2]). store number of operations needed for each arr[i], and answer is the maximum among stored values. Thanks

Sorry I missed this part, either increase arr[i] or decrease arr[i-1]

A contest like these teaches a lot although rating decreases like a waterfall. Still, It is fun.

how to solve div. 2 E ?

Please who can explain the solution to div2 B

Each valid solution should contain a number that occurs in at least half of all the given pairs. There can't be more than 2 numbers with this property. Attempt to use each one and then you can check if that is possible going in any order through the array; the first time you find a mismatch with another pair, try to take one value from it.

What's the runtime of the algorithm

It's O(2*N), but we can ignore that constant

choose a[0] and check that the remaining pairs whom values aren't equal to a[0] share a commun number, if not check for b[0].

Why was there so many wrong submissions for d?! Is there any corner case?

My solution is for every pair of leaves check if you can change question marks accordingly. But actually it's the other way around, first change ?s then every pair should satisfy the condition. I got WA and it's not a proper solution(found a testcase afterwards) Maybe also other people tried this?

Hmm! Is this E: https://community.topcoder.com/stat?c=problem_statement&pm=14159&rd=16690.

The statement looked some simple that I immediately started googling some keywords but couldn't find it :/

Yup, and with the same reason we didn't find it before the contest! ;(

I googled and found this. Started by searching "two permutation xor" something, I found this at some reference in a recent paper. However I'm too sleepy to read this...

OnionPringles also told me that same problem was in IMO 2005 Shortlist.

https://community.topcoder.com/tc?module=ProblemDetail&rd=16690&pm=14159 This page says that you have tested that problem.. Am I missing something?

XD

That's perfectly possible. I have a very bad memory for problems and my friends sometimes laugh at me for that. I wouldn't ever be surprised if that was my problem, to be honest.

I am so sorry! I thought that my problem is original :(

Will this round be unrated?

Nope

No, problems that are not new for some participants is not a reason for unrated.

But I think phoenix__jpn should be unrated. He just submitted problem E in 15 minutes and get rank 88. In his code you can even see 'SRM686'.

As per rules, what he did is within rules

How to solve C ??

https://codeforces.com/blog/entry/67189?#comment-513710

Litreally your username ,binary search for ans from 0-m

That's A, not C.

Oh sorry , i thought Div2 C ... my bad

There is no scoring distribution in the blog.

Problem E: & and &.

Maybe sunset and TLE are not familiar with well-known problems in China.

How to solve div 2 B?

Not in Division 2, but I think this works. We do casework. Obviously, one of the two numbers in the first pair must be x or y. WLOG, let the first pair contain x, and split into two cases based on which number is x.

For each possible x, iterate through the remaining pairs. One of the two numbers in the first pair that does not contain x must be y. Iterate through both of these possible values for y to check whether they work.

As we have four cases and can check each case in O(N) time, this will easily work within the time limit.

Check which pairs of numbers contain a[0] and then check if there is some number contained in all the other pairs (you can use map for that). Then do the same for b[0]. My solution

My approach :

take an array temp and push 1st pair

push another pair which does not have any elements same as 1st pair

if there is no other pair then 1st pair is our answer else

now pair(x,y) must be one of the pairs of this 4 elements

take every pair and check

if we find at least one pair then return YES else NO

solution : https://codeforces.com/contest/1169/submission/54683336

weak test case in problem B(div 2)

this is my ac code https://codeforces.com/contest/1169/submission/54686525

but for the following test case i am getting wrong answer

6 8 1 4 1 4 1 4 2 3 2 3 1 5 3 5 4 5

the answer should be "NO" but my code output is "YES"

although this is ac code

Hah, there are only four failed solutions in the entire Div1. A bit too strong pretests maybe?

Pretests can't be too strong :)

You are not right))

Does it follow that the systests are weak then?

There's no such thing as pretests that are too strong! (There are sometimes pretests that take too long to run though)

Am I the only one who

~~solved~~overcomplicated D1B with four bitsets?..Why did my submission 54684486 fail at test 4?

A relatively difficult Div. 2 than usual with $$$<1800$$$ official submissions for B and $$$<600$$$ official submissions for C. But questions were interesting!

It's normal because people with rating from 1900 to 2099 participated in div 1

MikeMirzayanov, I submitted solution for Div1 B, then again after around 20 minutes I submitted solution for Div1 B with some modifications, but my earlier solution is skipped, which must be considered as per rules. What was the reason?

According to the rules your last submitted solution will be considered even if your previous gave AC and the last solution gave WA.

Only the last correct submission is considered for testing. The rest are skipped.

How Solve B.pairs problem??

If you consider any pair pi, then we can see that one of the x or y (or both) is from the chosen pair. So just bruteforce for other answer.

Concise problem statement, quick systems test, quick rating update, quick editorial. Good contest!

Has anyone tried and succeeded in DIV 2-(C) using DP ??