Hello, Codeforces!

We are proud to finally invite you to participate in Codeforces Round #815 (Div. 2), which will start on Aug/18/2022 16:35 (Moscow time). You will be given **5** problems, one of which contains a subtask and **2** hours to solve them. We greatly encourage you to read all the problems.

Round is completely set by SIS (Summer Informatics School) students. During the camp our students did their best to prepare interesting and creative problems. You can check previous rounds prepared by SIS students: Codeforces Round #612, Codeforces Round #530, Codeforces Round #694.

People who participated in the creation of the round:

- Problems are authored and prepared by: Kirill kirill.kligunov Kligunov, Gleb glebustim Ustimenko, Alexey daubi Vasiliev, Stanislav Death_on_2_Legs Alekseev, Vladimir plagues Gerasikov, Artem artem3605 Abaturov, Artem a.stepanov281005 Stepanov, Evgenii pakhomovee Pakhomov, Viktor robivirt Krivoschekov under the guidance of Mikhail meshanya Pyaderkin, Nikolay budalnik Budin, Philipp philmol Molodcov, Vladimir TeaTime Novikov, Fedor fastmath Ushakov.

- And of course we want to thank our army of testers: alexxela12345, wabadabakalakaboo, fishy15, Kapt, rafaelka, alexchist, bashkort, Obeziana_Banana_Clown, Viktoriuss, PUFL, hoshiii, Vladosiya, anporf, elizazh.

- Coordinator: Artyom123

Also, we would like to thank:

- Artyom123 for the brilliant coordination.
- fastmath for improving one of the tasks!
- meshanya for improving the structure of the contest!
- MikeMirzayanov for great platforms, Codeforces and Polygon!

Scoring distribution: $$$500-1000-1250-(1500-1000)-2750$$$.

Good luck & have fun!

**UPD1**: **Editorial**

**UPD2**: **Winners**!

**Div 2:**

**Div 1:**

Gl Hf

why in system testing our answer is get TLE or wrong? because of it's added new test cases?

During the contest time, your code successfully run agnist some test case. After the contest, your code again run agnist rest of the data set. But it took extra time than time limit, that’s why you got TLE.

Waiting for it!

Not as a tester, I know that the problem is good since the last contest by SIS students was great.

So is your spacecraft on the orbit?

so next time I see your comment about problems are good without testing, I don't participate in that round...

xd

[Deleted]

Some people always lack a sense of humor.

argee with you haha

As an author, I am author.

As a SlavicG fan, I will hope that this will not be another speedforce round.

It seems to say everything, and it seems to say nothing

Greet from China!

It's very good for Chinese because it's 9:35 p.m in China at this time, Not 10:35 p.m. !

right

absolutely right，up vote this round!

as a tester, I tasted this round.

How does it taste?

I bet it's sweet and spicy ;)

you’ll find out:)

like a shit

Why? I tasted it too, but it was so spicy and good

too small points for d2

hm, if u solved D2, you solved D1 too, so you get 2500 points, its pretty much

nice profile pic bro

are you sure you are a tester and not a

sommelier?Artyom123 5 problem round. Have to participate!

hope to specialist in this round

hope to pupil

Hope to pupil in this round

Oof, 1199. You'll get to it next time, keep it up!

Also, there will be recalculation presumably. So, probably you will get +1 after it :D

I think problem C has a subtask.

How come?

As a participant, I will participate.

orz

I hope to use this round to go back to Master.

Amen

You will do it ! :)

Best wish to you :)

Oh I missed this round and used the next round to go back :)

Great!This Unusual time allows me not to sleep so late :)))

Hope to candidate master in this round

Good luck to every one!it took you 3 edits to type 5 words

When there are supposed to be four words.

Hope to pupil in this round

Congrats bro on becoming pupil!!

Thanks

Coders Time.

As an entrant, I think I should now go and write the question

Finally there is a round of normal time for UTC+8! But,there is only 2h but not 2h+15min.May I think it's a little bit easier than round #814(Div.2)? I am just guessing,so it's may easily wrong（

Also,hope to Expert(even though there's 167 between my rating and the base rating of an expert(1600) in this round.

hope to expert ++;

I can't get $$$\color{blue}{\tt{Expert}}$$$, because I'm slow on C.

I nearly reached expert yesterday.Finally my rating is 1594

Hope to expert in this round

Wish you the most of luck :)

I didn't have enough luck to read the starting time... woke up an hour too late.

Why the announcement does not mention that the time is unusual, and why is it not displayed as client local time?

Hope that the round provided by SIS students is really friendly. Everybody +154!

I just need 17

Note the unusual time[Not relevant]

Son, there are other CP websites other than this amazing platform so if you are so mad just don't come here again it is that simple.

Just a simple question: is the link of "Codeforces Round #815 (Div. 2)" in "We are proud to finally invite you to participate in Codeforces Round #815 (Div. 2), which will start on Thursday, August 18, 2022 at 13:35." from the post above correct? It says "https://codeforces.com/blog/entry/103966" here.

yeah, that's a clear copy-paste error... that they still haven't corrected... (said after mistakenly clicking on it n times)...

edit: and now it's been fixed to link to this announcement post...?

Yeah. Please fix it TeaTime. (Now it's https://codeforces.com/blog/entry/106074)

Edit: Now fixed :)

Sorry, fixed it in russian version but forgot to fix in english. Now it should work!

5 problems and 14 authors :/

Hope to master this round!

Congrats!

thanks!

Almost woke up late, didn't realize the one hour early unusual timing, almost missed the contest.

Me too. I hate the changes in the time of the contest. At least they should write "Please Note the unusual time"

Was waiting for the contest to have some fun, turns out that can't even solve problem A.

And now feel very stupidly for forgetting 5th grade math.

Me after 1 hour after not even able to solve A:

A little joke : I wrote

`p % q`

when`q = 0`

when I solve A.D2*

can u plz give some hints for d1 i was totally blank for it during contest no Clues and how to think for this kind of problem??

I thought because all a[i] < 200 it won’t matter a lot in the xor operation because the 8th bit and higher will not be affected (2^8 xor a[i] ≈ 2^8), so i divided the array in blocks of size 2^8(256), then cannot exist a subsequence in more than one block (indices i < j) then a[i] xor j < a[j] xor i, and finally eliminate a[] because its small and j < i its false, so you only need to run a standard LIS algorithm inside every block and return the largest subsequence among them.

missed the contest because of unusual start time, thanks.

Please highlight in bold about unusual start time. Missed the round ＞︿＜

You lucky bastard!....saved from suffering..xD

Problem D, what about the array B meaning?

It looks like array B is a index of array A, but I find all page with ctrl+F, not found the word

"index"in problem statement(found in problem note, but not useful).So, the problem writter, do you know what

"subsequence"mean? Read about your sentence:"is a subsequence of length m of the array a.", the reviewer of this problem really think that express the meaning correctly?I asked a similar question and it turns out that

b is actually a index of array A.Only after reading this thread, I understood the question properly. But, is it allowed to discuss about the problem statement during the contest ? Just wondering. :?

I know it so I just repeated the problem writters' words. Seems lots of people got stuck on it.

I asked the same thing in dashboard help window and author replied "Read statement again". Like seriously???

sameeee. I wasted around 1 hour coding the solution and later realised it's index array.

I think the problem A is harder than problem B&C...QWQ

+1

speedforces, penaltyforces, guessforces.

Not really, but I actually did fail on D1 for 4 times. For misunderstanding!

I just think the gap between D1 and D2 is a bit big.

B and C are much easier than A!!!

for me c>A>B i don't know how u feel C easier than A

I just spent 2 min thinking about C. But I spent 6 min to think of the answer of A!

Maybe just for me... Stuck on A

The arrangement of difficulty is really puzzling.

Not to blame the problems themselves, only the arrangement.

I can't solve

A!! ◑﹏◐Same !! only got the base case if one of the numerartor is 0 print 1 and if both numerator 0 then 0 lol:<

Yes that's right !!{{(>_<)}}

wasted all my time on D1 by assuming that b array contains elements of array a such that elements belongs to [0, n). After seeing tc 1 realised that it's a index array. Was it mentioned in the problem?

What's the pretest 3 of D fix? Pretty convinced my 2D DP solution is correct (trying to match bits one by one and storing maximum for each pairing of index 'bit prefix' and 200 last values). Thanks.

I can't see your solution, but seems you overcomplicated. Just do these loops:

$$$a \oplus b \in \{a - b, a + b\}$$$ hence $$$a_j \oplus i < a_i \oplus j \implies i - 200 < j + 200 \implies j > i - 400$$$. Probably, there is some $$$\pm 1$$$ mistake.

what subsequence mean???

Div2 D Ok, we can use dp to find the longest sequence, but how do we find all such pairs of numbers that meet xor restriction in a good time? Or there is another approach?

Use 01-Trie to optimize the transition.

What are transitions? and how we can optimize them?

I couldn't solve $$$D2$$$, but you definetely can't find all transitions (pairs, that satisfy inequality). Simple test gives, that there are $$$O(n^2)$$$ transitions.

using 01-trie is a good choice

I always fall behind on problems like A because people submit random guesses. Honest thanks for the weak pretests, they are good from time to time for punishing this strategy.

In

BI don't know if it's just me but it took me a while to notice that $$$a_{l}...a_{r}$$$ were missing in the first $$$2$$$ expressions. Stating it in words would have been nice.

e.g.The max/min without the subsegment $$$a_{l},...,a_{r}$$$.+1

What was your understanding of the meaning of the formulars instead?

I mean, at first I did not understand them at all for more or less same reason. But there is also no other meaning possible, so I understood after second or third reading.

I don't understand Problem D.

In the example 1,the last factor is equal to n.

But the Note says "In the first test case, we can pick the whole array as a beautiful subsequence".

Why?

Please forgive my poor English.

In the first test case, you can pick the whole

indexarray [0, 1] as a beautiful subsequence, not the array itself.I see. Thank you.

Thanks, I was not able to understand the problem until I read your comment.

The words

`is a subsequence of length m of the array a.`

were confusing me so much that I didn't even think that it could be an index array!The word "subsequence" in D is quite misleading...

Why does the subsequence of an array is its index array???

What is the intended complexity of $$$D1$$$? I tried an algorithm of $$$O(N*log(N)*max(a[i]))$$$ using trie but it was not enough to pass the time limit.

I think it is O($$$n \times 200 \times log(200))$$$).

I used O(256n)

For each

itry only suchjthati—j<= 600 (this constant is even less).Maybe $$$O(n\cdot 256)$$$ ？

By seperating $$$a$$$ into blocks with length of 256, and do $$$O(n^2)$$$ dp.

Because $$$a_i\le200$$$,

`index>>8`

(divided by 256) doesn't change by $$$\oplus=a_i$$$, so we can't choose any indices from different blocks.Same.

Thanks everyone. Your insights are appreciated.

What is the hack for A? Is it related to precision issues?

There is no "the hack". I hacked four times, each time in a different way. There was no typical mistake, each wrong solution was just random wrong logic.

My hacks:

Precision is definitely not an issue unless you actually calculate in floats/doubles, in which case you 100% can be hacked.

How to solve D1, D2?

trie, think of $$$(i, A[i])$$$ as one thing, at bit $$$b$$$ you will have $$$(i_b, A[i]_b)$$$ which you can think of as a number in base 4, these four numbers form a partially ordered set where each number has exactly one number less than it (so check that in dfs) and two numbers equal to it so recurse on them, to reduce the complexity from $$$\mathcal{O}(n \times MAXA)$$$ to $$$\mathcal{O}(n log(n) + n log(MAXA)))$$$ notice that you can group 0 with 3 and 1 with 2.

D1 直接暴力

it took me 1 hour to understand that the sequence b in problem D is the index of a, and i solved it 3 minutes after the end of the contest. confusing description ruined my contest! worst contest I've ever attended

So what is the solution for the hard version?)

use a 01Trie to optimize the transition

I mean d1, I can't solve d2 either

DP, using 01-trie to optimize it

Try to use a 01-trie to maintain pairs.

Imagine 30 high rated programmers preparing a round and everyone agree with a wrong definition of subsequence :/

A fuckload of TLs for C INCOMING!!!

Okay, solutions that do not use cumulative sums seem to pass. Probably, TL should have been more strict.

Despite the confusing description, D2 is the best problem I've seen in CF div.2 rounds. I think using 01-trie to optimize the transition is quite tricky for me :)

Had an idea for D1, but was not able to debug it in time D:

Finally positive delta, so i am not complaining. Nice set overall, regardless B and C being easier than A.

Get really confused.

In problem D, the statement says that

`b is a subsequence of length m of the array a`

. How can $$$b$$$ be a subsequence of $$$a$$$? In the first case of the sample, how do $$$[0,1]$$$ turn to be subsequence of $$$[1,2]$$$?I spend more than an hour on the version of $$$b_i$$$ is an element of sequence $$$a$$$, not until finding my long code not outputing the correct answer to the sample test.

There's even no update or clarification!It's maybe true that this is explained in the sample. However I do think this kind of description is annoying, as I, urgently, was

in a hurrytrying to solve the problem and not aware of the misunderstanding.I should have got an increase in my rating. Anyway... I'm realy down in the dumps. :(

I think probably not only me were confused with the description. Why none of the numerous writers and testers pointed this out? More than 30 names are mentioned, that's a large number even compared to other contests.

I'm pissed off a bit because there is neither descrition updates nor clarifications during the two-hour contest.

In the previous contests, I find the clarifications really detailed, sometimes

evennagging. However I got nothing this time, when I really nead them. I think a simple short clarification can get me back to track.Problems in contests are not like normal training problems, a slight misunderstand can have significant influence on some (maybe one or two, but probably a few) participants.Sorry for the bad mood brought to the comments. I promise I will make more contribition to the codefoces society to make this up.

My solution to the misunderstood version of D1 has come out. The link is here. :)

NO WAYYYY T-T JUST GOT FST ON B CAUSE OF JAVA SORTING I'm so sad. ;(

Many fst in problem A...

The pretest of A is so weak!

If you don't use long long,you will also pass the pretest!

That's true.

Yes. I'm waiting for FST.

Int solution (WA) 168831736 LL solution (AC) 168832004

seems ok

what?my first code without long long even can't pass the example:(

took 10 minutes to figure out what problem D means, tried and failed to solve it in the rest hour, and realized that I misunderstood it after the contest:)))))

I'm quite sure there must be a severe mistake in the D1 statement. It describes $$$b$$$ as a subsequence of $$$a$$$. By definition of subsequence, the elements in $$$b$$$ must be in $$$a$$$, and the relative order of the elements in $$$b$$$ are the same as the relative order of the elements in $$$a$$$.

However, right away from sample-input #1, we have a contradiction. The example shows $$$1 \oplus 1 < 2 \oplus 0$$$, which means the $$$b$$$ values are $$$1$$$ and $$$0$$$.

But 0 isn't in the array!How can a subsequence of an array with no zero contain a zero???I was also confused by test-case #2, where they selected indices 1, 2, and 4. Okay, these are in the array this time, but not in that order! The relative order in array $$$a$$$ is 2, 4, 1. So [1, 2, 4] is not a subsequence of $$$a$$$. I thought they might have meant $$$[2, 4, 1]$$$, but they also wrote that $$$b$$$ is strictly increasing. How does this make sense?

I had over

an entire hourafter solving C, and could not understand this. Asking a question yielded the generic response of "Read the problem statement", but no matter how much I read it, I couldn't make sense of these.It was only after the contest, from another comment, that mentioned that $$$b$$$ is actually simply an increasing set of indices of $$$a$$$, completely independent of the values of $$$a$$$. This is

nota subsequence. Nowhere in the problem does it mention that $$$b$$$ was a set of indices.This is an enormous mistake that prevented me (I'm sure many others), from being able to even understand the problem. Not only was there a severe mistake in the original statement, but what's even worse is that this was never corrected throughout the contest, and even the inquiries about this issue were responded with a generic "Read the problem statement". If you're getting questions about a statement, maybe you should like, actually read the statement yourself and figure out why people aren't understanding it, and then correct the problem statement and humbly clarify the issue, as opposed to giving a generic "Read the problem statement" response, as if the questioners are too stupid to understand that a "subsequence" actually refers to a set of indices!!!

But the meaning of subsequence in this problem is given in the problem statement?

SpoilerJust because the word "subsequence" usually mean some element of array in same order doesn't mean it will be the same in this problem. But yeah i agree it can be confusing. Maybe it will be better if without the word "subsequence", just array B.

My understanding was that it defined $$$b$$$ as a subsequence of strictly increasing elements of $$$a$$$ such that they are all in the range $$$[0, n - 1]$$$. This is entirely consistent with the statement you highlighted. In other words, I interpreted it as a restriction on what constitutes a valid subsequence for this problem as opposed to redefining subsequence.

The definition of beauty referred to $$$a_{b_p}$$$ and $$$a_{b_{p + 1}}$$$, so restricting $$$b$$$ as being a subsequence with values in range $$$[0, n - 1]$$$ was perfectly justified. There was nothing in the problem statement that hinted that my interpretation was flawed. My interpretation was a perfectly valid problem that I would probably have written in the exact same way as this given problem statement, but it was not actually the interpretation that was intended.

What would have been correct is if, instead of "a subsequence of length $$$m$$$ of the array $$$a$$$", they wrote "a subsequence of length $$$m$$$ of the

indices inarray $$$a$$$.I see, i get your interpretation is that array B is :

`[0, n - 1]`

.But actually the sentence i highlighted mean array B, with property increasing and value between

`[0, n - 1]`

is the definition of subsequence, nothing else.Anyway now we know the problem, lets upsolve it! :D

I wasted more than half an hour on D1 because of the problem statement. Still don't get how a subsequence of 'a' implies a collection of indexes rather than the elements themselves.

Exactly! How can a subsequence of an array be a collection of indices? TeaTime

Why the output in E is always either 1 or 2 if number of distinct elements in the input is greater than k? Any way to prove that?

Off the top of my head.

You can increase length of the first square in top-left (red square) until increasing it one more time reduces the number of distinct values below $$$k$$$ (green square). Then as the second square, you can take the blue one and increase its length until you reach the requirement. As the blue square reduces the number of distinct values by at most $$$2$$$, you might be off by one. But you can choose to write a completely new value or an existing value in the square depending on the situation you're in, so you can meet the requirement.

You want to choose 2 squares such that by removing these squares, you remove all but $$$k$$$ or $$$k - 1$$$ colors from the grid.

Consider for each $$$\ell$$$ the square that has the top left corner at the top left corner of the grid. Each of these squares removes at least as many colors as the previous one. The first square removes 0 or 1 colors and the last square removes all colors. If one of these squares removes exactly the correct amount of colors, we are done.

Otherwise, there must be a point where the $$$\ell$$$-th square removes too few colors and the $$$\ell + 1$$$-st square removes too many colors. Now you can make all of those shapes with 2 squares:

At each step you remove at most 2 more colors and transition from the $$$\ell$$$-th square to the $$$\ell + 1$$$-st square, so at some point exactly $$$k$$$ or $$$k - 1$$$ colors are left after removing.

looks like if you use division on A it will FST

Screencast with commentary

weak pretest for problem A.

Solve A in 10min — As problem A, not good enough.

Get FST — Good job.

About D's statement:

Obviously, neither "b is a subsequence of [0, 1,... n — 1]" nor "b is a subsequence of indexes of a" is way more precise than "b is a subsequence of length m of the array a". So why does someone writes things like

"b is a subsequence of a"in the statement and don't make any public clarification?You pointed it out and yet they didn't bother updating the statement? Wow.

Confusing sample descriptions+weak system tests, gonna have a lot of fun losing 100+ points

D was so confusing spent 1 hr just reading it.

I don't think the description of problem D is reasonable. It writes that array $$$b=[b_0,b_1,b_2,...,b_{m-1}]$$$ is a subsequence of the array a. However, according to the exapmle, we can find that

the elements in array b are indicesbut not elements in array a, which meansarray b isn't a subsequence of array a. To be honest, this bothered me a lot during the contest.(╥_╥)Sad view don't open it

SpoilerTeaTime could you update link to contest? Now it refers to 804 contest blog

Now it refers to current blog but still not to contest

168821144

Problem B, why this submission is TLE. Java

For large inputs in Java, you'll need fast IO. https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/

`Arrays.sort`

is $$$O(n^2)$$$ in certain cases.this is my first time commenting in CF discussion section this is my code for div 2 C Corners... but I got a fail on pretest 2. I tried debugging and solving but wasn't able to do it.

below i have also explained my code... if you can have a look. And tell me what's wrong with it. thanks

. . . . .

from collections import defaultdict

def solve(): t = int(input())

solve()

Put the code inside a Spoiler

You should also check if there if two zeros are diagonally adjacent.

yess just find out my mistake thank you... tysm

B has more accepted solutions than A::) ...Weak Test cases but still, IMO it was a good question.

The editorial link is broken, says i'm not allowed to see the editorial

Amazing. We have successfully made two LGM's massively overcomplicate a Div. 2B. Um_nik: 168820726 jiangly: 168847264

At the same time, I think they know much better why their solution works than a large number of solvers.

jiangly's solution evidently didn't work

Can someone explain why my solution that just check for each i(0 ... 200) the last 3 indexes they were met in the array gives AC? I think the tests are just weak but maybe it can be proven in some way. 168854584

Indices will grow larger than the elements themselves, and after every 256 elements, 8-bit will flip, and all previous elements are invalidated, because the most significant bits of new indices will be larger than any previous indices. Since a_i <= 200, they won't be affected by xor. So probably weak tests.

Editorial is not opening!!!!!!!!!!

ABC=500,500,500

Problem A: why does this code 168868045 gives me wrong answer in 13 with

GNU C++20 (64)while the exact same code gives me accepted with

GNU C++14168869739not my fault i guess !!

Because you are calculating with floating-point numbers, and they're different in 32-bit and 64-bit systems.

how could i know ?The better lesson to take away from it is to never trust floats. Don't use floats unless you absolutely need to. And even then be very careful with them.

It's pretty rare on CF to need to use floats, especially on easy problems. There's no need to use floats in this problem, for example the fractions are equal if and only if $$$ad = bc$$$.

Ratings updated preliminarily. We will remove cheaters and update the ratings again soon!

In problem D1 there is no test, where the answer is 1.

For the first time, I was able to solve 4 problems in a div 2 contest :)

In Problem C, based on the constraints, I first came up with a Greedy Set-based NlogN solution, and without looking for any observations, decided to start implementing it, only to narrowly get TLE on TC 8 (even after multiple failed attempts at optimization).

I think the unusual Time Constraint of 1 second was a deliberate thing to prevent these kinds of solutions from passing.

While I agree that the intended solution is a lot more simpler and elegant, because of only a slightly higher time complexity, and because it required a lot more effort, the authors should have also allowed the greedy NLogN solutions to pass.

My Submission

but c can be solved by a o(n*m) solution...

My feedback (only ABC problems):

Good first three problems, especially B. I liked A too, but I don't understand why it got so few solves. C felt little easier that normal Div.2 C problem.

GreedyForces (?) It was a nice round, thanks!

Nice Music

I like this round, problem D was really interesting! Although the description was a bit confusing.

You missed the part

note the unusual timeHello, the system says that I cheat on C but I don't what should I do? somebody help plz

Attention!

Your solution 168861333 for the problem 1720A significantly coincides with solutions saubhagyaprakash/168825261, ajis207/168825753, Raaghav909/168833485, gla_191550059/168835636, akm1002/168836385, 6615-Bhumeera/168858644, MARSHALMATHERS/168861333. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://codeforces.com/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked.

This has happened because problem A of DIV2 rounds is trivial most of the times and the code is of 4-5 lines so it is just a coincidence that someone wrote a similar thing which I did even if you would go through a number of other submissions you would find that the logic is nearly same and since it is a small code it gets matching for a number of people.

I agree. I've recieved similar mail, someone's code is very similar to mine. (168808729, 168826905)

Looking at the skipped submissions of 1720A, the codes are all quite similar. It seems necessary to re-check the skipped submissions.

i got mails regarding coinciding codes in two accounts but actually both the accounts are mine ebshu21 and rony19 both are my accounts and i submitted the solutions for the contest problems during the contest from both my accounts but now that contest is not rated for me i my rating got reduced. please help me out. i can give all sorts of proof