### 300iq's blog

By 300iq, 8 months ago, translation, ,

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

4) prick

5) qk0qhh

Editorial

• +340

 » 8 months ago, # | ← Rev. 2 →   -47 1
•  » » 8 months ago, # ^ |   -22 Glad for another Div1!
 » 8 months ago, # |   +10 How many problems are shared between Div1 and Div2?
•  » » 8 months ago, # ^ |   +12 Why do you ask?
•  » » » 8 months ago, # ^ |   +76 why he should have reason?
•  » » » 8 months ago, # ^ | ← Rev. 2 →   +17 Sometimes it helps to understand the difficulty of the problems.Nothing else.
•  » » 8 months ago, # ^ |   0 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.
 » 8 months ago, # |   +65 I wish problem statements are short like this announcement!
•  » » 8 months ago, # ^ | ← Rev. 2 →   -8 I hope so too.
 » 8 months ago, # |   +19 Why are the links for both divisions duplicated in the attachments section of the annoucement ?
 » 8 months ago, # |   +227
•  » » 8 months ago, # ^ |   +7 same to me :(
•  » » 8 months ago, # ^ |   0 so relatable :)))
 » 8 months ago, # |   +336 300iq's problems be like:
•  » » 8 months ago, # ^ |   -10 Hahaha
•  » » 8 months ago, # ^ |   +54 Your comments be like:
•  » » 8 months ago, # ^ |   +104
•  » » » 8 months ago, # ^ |   0 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?
•  » » » » 8 months ago, # ^ |   +1 Yes
•  » » 8 months ago, # ^ |   +4 so real
•  » » 7 months ago, # ^ |   0 so realistic....
 » 8 months ago, # |   +10 Long time no see!!!
 » 8 months ago, # |   +4 Lets have a great contest Guys . Enjoy everyone and best of luck for it
 » 8 months ago, # |   +4 300iq is return back with awesome contest :)
 » 8 months ago, # |   0 I hpe the problem statements are as short as the announcement :)
 » 8 months ago, # |   -7 Which is Harder Red in Codeforces or Grandmaster in chess?
•  » » 8 months ago, # ^ |   +20 See this Quora answer by I_love_Tanya_Romanova
•  » » » 8 months ago, # ^ |   -6 Ok, thanks.
•  » » » 8 months ago, # ^ |   -21 Can't believe being red is easier.
 » 8 months ago, # |   0 How many problems will be in contest?
•  » » 8 months ago, # ^ |   +1 Just wait for another 30 mins. And you will have the answer to your question.
•  » » 8 months ago, # ^ |   0 5 problems
•  » » 8 months ago, # ^ |   +10 Participants in each division will be offered five problems and two hours to solve them.Dude, please read the announcement.
 » 8 months ago, # |   +15 I like weekend competitions, thank you 300iq
 » 8 months ago, # |   -11 Anyone else facing problem in hacking? I get 403 when I try to open code even though I locked.
 » 8 months ago, # |   -36 ()
•  » » 8 months ago, # ^ |   -13 hahaha :)
 » 8 months ago, # |   0 How to solve C? I could easily write O(nm) DP solution, but how to optimize it?
•  » » 8 months ago, # ^ |   +6 I used binary search from 0 to m for O(nlog(m))
•  » » » 8 months ago, # ^ |   0 I tried to go for this approach too, but couldn't figure out how to simulate given an answer.
•  » » » » 8 months ago, # ^ |   +6 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,
•  » » » 8 months ago, # ^ |   +1 how to check for some M if its possible?
•  » » » » 8 months ago, # ^ |   0 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.
•  » » » » » 8 months ago, # ^ |   0 got it, thanks
•  » » 8 months ago, # ^ |   0 Yeah me too
•  » » 8 months ago, # ^ |   +6 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
•  » » » 8 months ago, # ^ |   0 Thanks
•  » » 8 months ago, # ^ |   0 what about a binary search for the answer?
•  » » 8 months ago, # ^ |   +3 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
 » 8 months ago, # |   +8 That moment when I realized problem B can be done by sole bruteforce...I need better observation tho :D
•  » » 8 months ago, # ^ |   0 Which bruteforce?
•  » » » 8 months ago, # ^ |   +42 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.
•  » » » » 8 months ago, # ^ |   +3 How did you get that?
•  » » » » » 8 months ago, # ^ |   +18 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.
•  » » » » » 8 months ago, # ^ |   +8 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.
•  » » » » » » 8 months ago, # ^ |   0 I just assumed it cannot be longer than 20, with a huge reserve, since if fits in TL easily anyway.
•  » » » » » » 8 months ago, # ^ |   +11 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
•  » » » » » » » 8 months ago, # ^ |   +4 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.
•  » » » » » » 8 months ago, # ^ | ← Rev. 2 →   0 deleted. :\
•  » » 8 months ago, # ^ |   +11 I did that in the end,but how to prove it fits in TL?
•  » » » 8 months ago, # ^ |   +14 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$.
 » 8 months ago, # |   +6 Good tasks, thanks)
 » 8 months ago, # |   0 How to solve C? Tried some mo's algorithm, then realized that I forgot it has to be in order.
•  » » 8 months ago, # ^ | ← Rev. 4 →   0 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
 » 8 months ago, # | ← Rev. 3 →   +35 Congratulations to rahuldugar for becoming red.I hope so.
•  » » 8 months ago, # ^ |   +19 Thanks:D
 » 8 months ago, # |   0 Was anyone able to hack anyone? If so, what was the hack
•  » » 8 months ago, # ^ |   0 I was able to hack two with this — 7 7 1 2 6
 » 8 months ago, # | ← Rev. 2 →   +116 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.
•  » » 8 months ago, # ^ |   +115 I feel the same every time I see TAK/NIE in polish tasks.
•  » » » 8 months ago, # ^ | ← Rev. 3 →   -17 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.
•  » » » » 8 months ago, # ^ |   0 That comment made me looking up all CF contests your did and surprisingly I haven't found a single TAK/NIE
•  » » » » » 8 months ago, # ^ |   +9 Maybe I don't take problems from local contests? :D
•  » » » » » » 8 months ago, # ^ | ← Rev. 2 →   0 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 :)
•  » » 8 months ago, # ^ |   +80 It's because 300iq is learning Chinese recently.
•  » » 8 months ago, # ^ |   +73 C is cool and B is standard? Didn't you swap the problems?
•  » » » 8 months ago, # ^ |   +3 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.
•  » » » » 8 months ago, # ^ |   +2 I got it fast too, but it was pretty cool in my opinion. Don't remember problems using that idea.
•  » » » » » 8 months ago, # ^ |   +8 Here is a problem with similar idea. Today's problem is a case of the Van der Waerden's theorem
•  » » 8 months ago, # ^ |   0 const string yes =..., no =...;
•  » » » 8 months ago, # ^ |   +3 I had to look back into the statement every time I run my code.
•  » » 8 months ago, # ^ |   -14 Oh, i thought that it won't be a problem..I'm sorry if it spoiled the fun of the contest for you :(
•  » » » 8 months ago, # ^ |   0 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.
•  » » 8 months ago, # ^ |   0 Btw, why is D tedious? The intended solution has a very short implementation in ~100 short lines.
•  » » » 8 months ago, # ^ |   0 Ok, I change my mind. My implementation is much longer because I did more (unnecessary) things.
 » 8 months ago, # | ← Rev. 2 →   0 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]
•  » » 8 months ago, # ^ |   0 Sorry I missed this part, either increase arr[i] or decrease arr[i-1]
 » 8 months ago, # |   0 A contest like these teaches a lot although rating decreases like a waterfall. Still, It is fun.
 » 8 months ago, # |   0 how to solve div. 2 E ?
 » 8 months ago, # |   +3 Please who can explain the solution to div2 B
•  » » 8 months ago, # ^ |   0 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.
•  » » » 8 months ago, # ^ |   0 What's the runtime of the algorithm
•  » » » » 8 months ago, # ^ |   0 It's O(2*N), but we can ignore that constant
•  » » 8 months ago, # ^ | ← Rev. 3 →   +1 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].
 » 8 months ago, # |   +10 Why was there so many wrong submissions for d?! Is there any corner case?
•  » » 8 months ago, # ^ |   0 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?
 » 8 months ago, # |   +85
•  » » 8 months ago, # ^ |   0 The statement looked some simple that I immediately started googling some keywords but couldn't find it :/
•  » » » 8 months ago, # ^ |   +12 Yup, and with the same reason we didn't find it before the contest! ;(
•  » » » 8 months ago, # ^ |   +8 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.
•  » » » 8 months ago, # ^ |   +85 https://community.topcoder.com/tc?module=ProblemDetail&rd=16690&pm=14159 This page says that you have tested that problem.. Am I missing something?
•  » » » » 8 months ago, # ^ |   +69 XDThat'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.
•  » » 8 months ago, # ^ |   +44 I am so sorry! I thought that my problem is original :(
•  » » » 8 months ago, # ^ |   -27 Will this round be unrated?
•  » » » » 8 months ago, # ^ |   +12 Nope
•  » » » » 8 months ago, # ^ |   +38 No, problems that are not new for some participants is not a reason for unrated.
•  » » » » » 8 months ago, # ^ |   0 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'.
•  » » » » » » 8 months ago, # ^ |   +5 As per rules, what he did is within rules
 » 8 months ago, # |   +1 How to solve C ??
•  » » 8 months ago, # ^ |   0
•  » » 8 months ago, # ^ |   -7 Litreally your username ,binary search for ans from 0-m
•  » » » 8 months ago, # ^ |   +2 That's A, not C.
•  » » » » 8 months ago, # ^ |   0 Oh sorry , i thought Div2 C ... my bad
 » 8 months ago, # |   -10 There is no scoring distribution in the blog.
 » 8 months ago, # |   +53 Problem E: & and &.Maybe sunset and TLE are not familiar with well-known problems in China.
 » 8 months ago, # |   0 How to solve div 2 B?
•  » » 8 months ago, # ^ |   +1 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.
•  » » 8 months ago, # ^ |   0 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
•  » » 8 months ago, # ^ |   0 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
 » 8 months ago, # |   0 weak test case in problem B(div 2)this is my ac code https://codeforces.com/contest/1169/submission/54686525but for the following test case i am getting wrong answer6 8 1 4 1 4 1 4 2 3 2 3 1 5 3 5 4 5the answer should be "NO" but my code output is "YES"although this is ac code
 » 8 months ago, # |   -22 Hah, there are only four failed solutions in the entire Div1. A bit too strong pretests maybe?
•  » » 8 months ago, # ^ |   +31 Pretests can't be too strong :)
•  » » » 8 months ago, # ^ |   -13 You are not right))
•  » » » 8 months ago, # ^ |   +14 Does it follow that the systests are weak then?
•  » » » » 8 months ago, # ^ |   +22
•  » » 8 months ago, # ^ |   0 There's no such thing as pretests that are too strong! (There are sometimes pretests that take too long to run though)
 » 8 months ago, # | ← Rev. 2 →   0 Am I the only one who solved overcomplicated D1B with four bitsets?..
 » 8 months ago, # |   0 Why did my submission 54684486 fail at test 4?
 » 8 months ago, # |   +3 A relatively difficult Div. 2 than usual with $<1800$ official submissions for B and $<600$ official submissions for C. But questions were interesting!
•  » » 8 months ago, # ^ |   +24 It's normal because people with rating from 1900 to 2099 participated in div 1
 » 8 months ago, # |   -21 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?
•  » » 8 months ago, # ^ |   +21 According to the rules your last submitted solution will be considered even if your previous gave AC and the last solution gave WA.
•  » » 8 months ago, # ^ |   +20 Only the last correct submission is considered for testing. The rest are skipped.
 » 8 months ago, # |   0 How Solve B.pairs problem??
•  » » 8 months ago, # ^ | ← Rev. 3 →   0 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.
 » 8 months ago, # |   +15 Concise problem statement, quick systems test, quick rating update, quick editorial. Good contest!
 » 8 months ago, # |   0 Has anyone tried and succeeded in DIV 2-(C) using DP ??