Henlo Codeforces! ^_^

I invite you to participate in Codeforces Round #663 (Div.2) taking place on Aug/09/2020 17:35 (Moscow time). The round is rated for users rated less than 2100, while other users can participate non-competitively.

The round features five problems, and you have 2 hours to solve them. There may, or may not, be an interactive problem; regardless, you should know how to deal with them.

I would, now, like to thank–

- antontrygubO_o for coordination
~~and manipulation~~. - AwakeAnay, AsleepAdhyyan, and RestingRajarshi for always listening to my problem ideas.
- BRCode for making 3b1b-style video editorials of the problems!
- Aggu_01000101, Devil, Dragnoid99, far_from_NOOB, IaMaNanBord, Osama_Alkhodairy, prabowo, taran_1407, Tarrus, Tathagat_shah, TheOneYouWant, Utkarsh.25dec, Vivek1998299, _Aaryan_, aryanc403, dorijanlendvaj, growup974, hugopm, knightron00, kshitij_sodani, ltc.groverkss, nishkarsh, Roham, shash42, socho, talibmohd, and thenymphsofdelphi for testing!
- MikeMirzayanov for Codeforces and Polygon platforms– Polygon is truly remarkable!

Please do not mind the long list of testers (I had to write code to tag everyone here) since the problem set changed *significantly* after the first round of testing.

~~We will announce the scoring distribution shortly.~~ The scoring distribution is **500–750–1250–2000–2750**.

Good luck, and stay safe!

**UPD**: Editorial

Here are video editorials by BRCode:

**UPD2:** Finally, congratulations to the winners!

**Div. 1:**

**Div. 2:**

As a tester I think people will like this round because of interesting problems,diverse topics and short statements

Also (as a tester) wants contribution :)

So that was a f***ing lie (about "as a tester")

I meant kshitij_sodani, not me. I guess people got confused and downvoted me.

Understand, have a great day!

Sir on CodeForces never make the mistake of arguing with a person who has higher rating. I've been burnt before.

Ratism...

I literally just told you not to do this smh

I didn't argue with you smh

I've heard myths like

If you are div 1 , than the number of div 2 guys you've roasted is (your contribution)*(1000000000 +7) , is that trueIt's actually 998244353

I guess its bad news for stEV then

Time to lose contrib :)

thanks, I see a lot of orange here in the group.BTW what's polygon, I read it in every announcement

`MikeMirzayanov for Codeforces and Polygon platforms– Polygon is truly remarkable!`

Polygon in basically the platform for creation of programming contest problems. It also supports problem statement writing, test data preparing, model solutions, judging and automatic validation.

Hope there are strong test cases this time. :P

how can i increase my rating

Just after reading SleepyShashwat I am feeling sleepy

As a tester... Damn there's so many of us!

OMG!!! another "as a tester" comments "/

But we can't disagree many of them gives us some useful information about the round.

351F44 , I understand the first part of your username

buttwhy do you like1373Which ponies are we helping this time?

I wish none of them :(

Sorry to disappoint you, but I've tried my best to keep the statements short and purely formal.

Thanks a lot for short and formal statements :)

That's disgusting

Definitely not the ones named Augustus.

Omg Indian round! So excited

Ah shit here we go again. Oh, wait...

You think this line will work everytime :D

Am I the only one, seeing the similarity between the names ofSleepyShashwat,RestingRajarshi, AsleepAdhyyan , AwakeAnay.. UPD:one of them is odd one outand...?

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

I am not sure about other three, but[user:SleepyShashwat] is an IOI Silver medalist from India.

it will be Mathforses because you are coordinator no writing) look like stupid and interesting)

*insert cringe proud indian comment here *

0

I hope, we don't have to help Ponies, in this contest, unlike Previous Contest! :|

Hope the problem statements are made while you are not sleepy.

Well he was, but I made sure they are alright ;)

Memes/images should be posted in spoiler!

Indians on CF"

As a tester..."

How to feign consumer satisfaction to investorsAnton roundsDisclaimer: The memes aren't specifically for this round, that's for you to decide :) I liked it a lot as a tester.

So we'll have video editorials too this time?

Yes and afaik in 3b1b style.

Looking forward to it!

:)

This will be the first official video editorials for me in CF. Looking forward to it.

orz

As a participant, all we want is short and clear statement. Hope we won't get disappointed :)

Not.Enough.Memes.

Is it just me or the meme image disappeared after 12 hours?

Props for the 3b1b style video editorials! Sounds really cool, will definitely watch.

As a pony , I hope I'll not find any problem about ponies :(

Lol

Don't downvote sir

SleepyShashwat,AwakeAnay,AsleepAdhyyan, andRestingRajarshi.Coincidence!? I think not.

;)How so insightful sir

Not a coincidence indeed, check this

LOL, didn't know about this.

Wow Lelouch.Lamperouge you are a brilliant archaeologist!

Thanks NewAccelWorld XD

LMAO

`BRCode for making 3b1b-style video editorials of the problems!`

YouTubers who make video editorials after the contest...![ ](

I'm wondering why almost half of the recent contests, including this one, contain $$$5$$$ problems, but not $$$6$$$.

As a tester you will know why 5 is enough :)

I won't be wondering any more if I can have a chance to be a testerBecause , by excluding 1 problem from 5 contests ,they can create a new one.

Is this the quartet of last year's IOI from India?

Curious to know, how many problems/ideas got rejected in this round.

"Henlo" ?

Here

Hopefully the ponies are grazing grass instead of playing chess coloring games with each other.

I hope we are not going to have weak pretests like the previous one

Happy to see an Indian round Again. :D

Not as a tester I hope you good luck!

Wait did I read it right that there are vedio editorials ? Cool.

Hope that this round has short statements and strong pretests. I am still trying to get back from the trauma of previous round.

An Indian round with so many testers (and no more ponies and their stories) !!So excited.

How many testers do you need?

-YES!

How many pony stories do you need?

-NO!

I hope this round will not test our English comprehension skills.

lol, last one did! XD

Yes the problems were very confusing.

I second that.

Why is every div2 round having 5 problems now? Is making 6 problems too hard or are you sleepy while writing problems as well?

I prefer 5 problem rounds. They have better problems.

(I had to write code to tag everyone here):How does one write code to tag people?O.oOh, I meant to sort the handles, and then wrap them around [user: ] o_o.

I just realize that the names are sorted.

Did you use an

`if`

to add theandbefore the last handle? :PHope the statements are not sleepy.

As a tester i want to say that the contest is shit!!!! Thankfully i am not participating in this officially!! sighs: All the specialists brace yourself!!

Thats not really surprising if you look at the tag of the blog.

Deleted:(

Do you mean advanced algorithms as you mention specialists are going to have a hard time? or are you referring to math tricky questions? or ADHOCs? 0_0

Its just because i am a specialist

Typo in spelling of Hello Codeforces Please change Henlo --> Hello

Actually not, see this.

Just have learned that few comments above.

With this amount of testers

Hope for stronk pretest and programming test, not English test.

Thx.

(and 3b1b editorial seems nice!)

Although your Indian English is kinda weird, but the 3B1B-style video is so fantastic!

Why am I getting a feeling that this is going to be a MathForces round? I hope it is not though! :P

Also antontrygubO_o as a coordinator (Yay! :D)

I think your 2 statements contradict each other

Anton as co-ordinatorandContest full of Adhoc problemsDo these two statements contract as well ?

Oh fuck! :/

Prove 1 : link1 link2

prove 2 : sorry Not available (may be your id created last of 2018 )

Henlo Codeforces! ^_^ I think here must be "Hello" ^_^

No, they didn't misspell Henlo is a cute puppy language style for saying Hello.

Another contest!! As a regular contestant, I need a break :'(

As a contestant, I want rounds with aryanc403 as the author

Round preparation as an author very hard. :(

I really starts enjoying memes here...

Thanks , Codeforces!!!

author, how could you misspell the word ,,Hello''? i want to cry((

Henlo is an internet term used for greeting others. It is not misspelt :')

ok but my eyes can't understand it((

They didn't misspell it. It is a cute puppy language style for saying Hello.

Did any tester test anything with Python? Did someone spend the 10 minutes checking if the standrad solution in Python doesn't get TLE or too much memory?

Advise as a community member, You should never worry about TL issues in an Anton coordinated round.

^_^

Hope the statements are clear. I don't want to walk around the maze :)))

soo, if i utterly fail to do the questions then what will happen? (my rank is 0 , will to in minus or increase if yes then how?!

If you don't have a submission then rating will be unchanged.

If you make at least one submission but solve 0 then rating may increase for new users.

Check Here for details.

Thanks man, for helping me out

Thanks , Codeforces!!!

As a tester I think people will like this round because of interesting problems,diverse topics and short statements. Thanks, Codeforces!!!

Yeah.there will also be thought-provoking questions

SleepyShashwat please don't sleep during the going contest

Relax, there's AwakeAnay

[Deleted]

Looking forward to a good round after a not-so-good round.

Happy to see Indian School Students doing great on Codeforces and other CP Platforms! I wish, I also knew about CP while I was in School. Indian Students need to learn that "Apart from IIT JEE, there is also a world called CP". All the best SleepyShashwat for your future endeavours!

Awwwwwwwww, Were you not able to clear JEE, you poor soul

Poor Soul thinking that only a JEE Failure would write that statement. I think you are in the First Year of an IIT or you are not an IITian. Only some First Yearites(Fachas) at IITs have this attitude that they have cleared JEE and won the world OR this attitude is shown by

Butt Hurtswho couldn't clear JEE Advanced!What if i say i am in third year in an IIT ? What shitty explanation will you give then ?

In my college "fachas" or first years, whom you are saying shit for no reason, are better than you in CP.

I have seen people mention IITJEE many times before . So , does this university conduct some kind of computer science competition like I.O.I. , because I have seen it quite a few times like on this blog , Indian contest blog , cheater blogs and some ICPC blogs .

Its a rare thing for universities getting mentioned so it kind of made me curious

IITJEE is engineering entrance exam of physics, chemistry and maths which is considered to be one of the most difficult entrance exams in the world.

Top rankers in this exam pursue computer science in IITs not because they have interest in IOI or ICPC only because their parents saw headlines in newspapers telling some CSE grad from IIT secured this much package at google or is now CEO of this company blah blah which is big deal for middle class indian society as most other jobs in india are very low-paid.

Also indian pupils are dumbass as there was no need of mentioning IITJEE in this blog in the first place

LOL you are from IIT and still a pupil after one year. You must belong to one of the "special" communities.

The only reason i am offending you is you tried to offend those students who busted their ass in getting a f***** IIT after like 2 years of rigorous studying ( maybe 4 years for some ) and you are into CP for like one year and still nowhere with CP ( to be honest ).

I am also in the third year. And to be honest, you can check my submissions, I only gave contests till December last year. Many first years are better than me in my college also. They are Masters and it happens in all IITs I guess. I know I am nowhere in CP and it doesn't even matter to me. And what I have tried to say is there is a world apart from JEE also- for those who couldn't clear that! We also do CP only to get Jobs in MNCs and they also! I also spent 2 years in rigorous studies and I know that situation. And for your kind info, you are wrong even at judging my "Special and Reserved Community" LOL!!! It is just that some need more time doing CP some don't need that. Some do CP continuously and daily while some don't practice that much and I belong to the second one. I don't practice that much because everyone has different priorities. CP is a backup for some to enter the software/IT sector. They may want to do something else like Management, Civil Services, etc. And there are many such IDs on Codeforces- belonging to IITians, a general category and Pupil/Specialist. So, keeping all factors in mind stop judging people! And for your kind information, study for Internships rather than trying to offend me! And I didn't call first years

SHIT. It was you who misinterpreted it! I just said they have that kind of feeling in mind in first years. But second-year onwards they know the situation :P.Ok Mister Pupil

or he might have cleared JEE

I cleared JEE but wish I'd rather got to know about CP back in school. I have been good at programming since I was in high school but thanks to the JEE culture in India I never got to know about cp.

Whats worse, I got to know about cp only in my third year and I have only 1 year in my college life left now. Honestly if i could go back in time, I would tell my earlier self to do CP rather than jee.

What is IIT JEE ? Is it something on the lines of web development or something like that

it is the exam conducted to select students for studying in the most prestigious colleges of india (IIT). and no, u need to learn physics, chemistry and maths to crack the exam and secure the highest ranks possible to take up computer science(which is one of the many streams taught in an IIT).

So are students not aware about cp or they choose not to pursue it

I feel very sorry to say that but the education system in India is totally weird. I hear the word "CP" just some months before(after going to college). When we were in standard till 10. We have absolutely zero knowledge about programming(and we taught in school is totally theoretically especially in CBSE Board(I am from CBSE). In countries like Russia, people start programming in a very early age. They have much more knowledge than us. (Prooving my above statement, Currently there are only 7 red coders from India despite having the largest number of active members in Codeforces(almost double than any country).I am from India, and I really feel for it!!!

you mean that we have not started cp early, so we are not talented as other country's people?

Yes, this is the only reason I can think of!

Don't feel such. "CP" is not everything. CP just make your approach analytical and logical. Just like a brain exercise. But JEE is where you can do it with extra knowledge. CP makes you better at problem-solving but JEE is really good make strong your fundamentals. Especially I love physics. I love CP too. But I think Physics is always good to explore :)

Hope that statements are simpler this time

I hope I will not sleep during the contest!!!

Thank you.

Score Distribution?

where is editorial for this round?

What do you mean? The round hasn't even started yet...

here

UPD: lol. 7 people got rickrolled :))

sorry I mean for previous round actually.

codeforces helping a lot to many students

Auto comment: topic has been updated by SleepyShashwat (previous revision, new revision, compare).I hope the problems will be interesting.

very excited for round.

Very excited for the indian round :)

woweeeeeeeeee! 3Blue1Brown style editorials.

Half of the coders are giving Goldman Sachs aptitude test now lol

Is it necessary to post it here ?

Just felt like posting man. Everyone posts irrelevant memes, so why not this. Anyways, I apologise I said something wrong.

That's true about irrelevant meme. But what I am saying here is we should try to avoid posting irrelevant stuff here. Is someone is committing some mistake, it doesn't mean that we should also right ?

I think you misunderstood. I said, many are busy giving the test so, may not appear in this round. Thats what I meant :}

What's the lol for ? I genuinely can't find a reason to laugh at that ...

This feels quite opposite of previous round...

I can't understand what 'even length square sub-matrix' means in problem D.

Does it mean a sub-matrix with even width and even height?

Thanks

@SleepyShashwat

A binary matrix is called good if

every even length square sub-matrixhas an odd number of ones.It is described in the sample explanation below the testcases

Problem B was too easy , should have been a little harder...

After solving A and B what should be the best thing to do?

Rest, I guess.

Looking at the scoreboard hahaha

leaving

Solve C.

such an unbalanced round.

Solve Problem C. XD

Me after solving A and B :-)

Permutation lover SleepyShashwat

From today, I started loving

permutationsbecause no one knows how you canplay with permutationsexcept themasterSleepyShashwat. Truly agood and well implementationbased round. Only DS can help :)That's right! Only DS007 can help make future contests better!

The problem statements were really nice :) But the difficulty could have been a bit higher for C.

I havent studied graph theory till now sad.

there is nothing to do with graph theory for c

C is perfect. Intuitional.

Determine if the contest is

good?If Tx is the number of people solved task x, then the contest is good if Tj < Ti for any j > i

For now, 13045 — 12108 — 5115 — 1169 — 61.

My JEE notes help me in solving question C

JEE?

In india this exam is to get into engineering colleges.

Now this is what I call a Contest. loved it. Kudos to the author.

Nice problem set! A good round after a long time :)

Waiting for the end of the contest to start discussing the task E

`PATH: if diameter of graph >= (n+1)/2 ^)`

`PAIRING: if otherwise, but how to construct?`

Do dfs. In dfs tree if there is a path from root to any leaf with length >= (n+1)/2 we have solution PATH. Otherwise we pair nodes at same depth/level in dfs tree(because in worst case we won't pair only one node at some depth and from first check depth of the tree < (n+1)/2 so we will lose at most n/2 nodes during pairing which is valid).

Root at any node. Find a dfs Tree.

If the height is >=N/2 you have a path. Otherwise pair nodes on the same height.

Nice contest, too bad I wasn't concentrated enough :(

SleepyShashwat orz

2 minutes of silence for these people.Do you mean problem C? D didn't have issues with mods

Changed.

or

Thanks to

ErrichtoIn case someone wants the link, https://www.youtube.com/watch?v=-OPohCQqi_E

I got -150 in C because of this issue :( .

Solution of C:

https://oeis.org/A059204

I was so close T-T

:( I recognized how to solve it that permutation must have at least one dip but was not able to generalize the series. Thanks for OEIS link.

Pretest 6 For Problem C ????

negative number modulo

print answer modulo

`(ans%mod+mod)%mod`

;)My solution got negative answer for n=100

You getting WA because sometimes (n!)%mod < (2^(n-1))%mod. You need to add do (ans+mod)%mod

i m sad :(

Such a nice D!

What's the pretest 3 for problem D

I think some n=3 and m=300000.

Hmm, but I am not getting what I am doing wrong

I liked the problemset.

How to solve D? (I had understood that for n>=4 and m>=4 the answer is -1, but I don't understand what to do next).

Since $$$n \leq 4$$$ you can do dp[i][mask] in O($$$m * (2^{n})^2$$$)

"mask" means the type of the square?

oh, I should have thought about dp :( nice problem but.

n<=m so you don't need the min and max functions.

Thanks, I guess I need to read problem statements more carefully.

Oof, wasted 10 mins altering it to work in the case where m < 4 and n >= 4 without seeing this.

everybody got that part but man how should we place greedily anyone ??

I don't think that it's possible to do it greedily.

that's why I wasted a lot of time next time I will make sure when dp is possible just apply it.

how to solve C please help??///

n!-2^(n-1) is the answer.

why?

number of permutations is n!. And you have to count how many permutation of the form (2,1,3) do you have because that gives you a cycle between 1,2,3. (and 3,1,2 too). The permutations which are not from this type is 1,2,..n (increases) and after n decreases. And that number is 2^(n-1).

(with 2,1,3 i mean some v[i-1] > v[i] < v[i+1] not just 2,1,3)

Didn't the question asked to find the total permutations of length given n? For n=4, is [4, 2, 3, 1] having length cycle of length 4?

As per the definition given, vi and vi+1 share an edge for all i (1≤i<k), and v1 and vk share an edge. v1 to vk edge is only possible either of 2 cases 1. n-1 at position and n is at last position 2. n is at first position and n-1 is at last position then only we can form a cycle of length n right? Correct me if I am wrong somewhere.

I agree but i can`t see your point. 4,2,3,1 has a cycle of length 3 so i don't care if has a cycle of length 4.

Sorry I misinterpreted the question.

From the statement, "Given n, find the number of cyclic permutations of length n. Since the number may be very large, output it modulo 109+7.". I thought, we need to find permutations whose cycle length is n.

Total permutations = n! Permutations without cycles = 2^(n-1) I'll explain how I got 2^(n-1): For any permutation, if there is no cycle in it then it should follow this logic: 1)For any i,(1<=i<n) numbers i+1,i+2,i+3,... n should lie on the same side, if not then the permutation contains cycle. Then start calculating the ways by following this logic. Eg: for n = 4 You can put 1 in either of the ends.(because all other numbers should be on same side of 1) Then 2 possibilities: 1--- ---1 (you have to fill blankns with 2,3,4) Now, 3&4 should be on same side of 2, so, our possibilities are now 12-- 1--2 2--1 --21 .Recursively this gives 2^n-1 ways.

Use simple permutations and combinations and the principle of inclusion and exclusion :)

A very nice contest!! Problem statements were short and to the point.

oeis solution of C but I found it at the last minute after my original solution kept failing for large numbers -_-

People with WA/RTE/TLE on A. Care to explain your soln?

Congrats Beta_R for getting hacked on A twice.

maybe Levon2004 can shed some light on this

iches uzum aber?

1 77

1 6 4 RRRR RRRR RRRR RRRR RRRR RRRC

1 57

AnandOza

I have a feeling that it was done on purpose to gain hacking points.

Yeah, they have an if statement to get hacked lmao: if(TN==1 && n==57){

Yeah It was done on purpose. Levon2004 has hacked both A(twice) and B with the same technique.

asgardianadhi я просто смотрел решения и увидел что решения Beta_R неправилный и взломал специально нечего не сделал

how to solve D? I found it really hard to find answer for min(n, m) = 3 because there were too many states

Yeah I also got stuck in that case. Waiting for the editorial!!

there are only 4 states. 1)from {(000), (111)}(consider which of these two require min change) to {(010), (101)} and visa-versa. 2)from {(100), (011)} to {(001), (110)} and visa-versa. check this

Has the core idea behind C appeared in a contest in the last year or so? I remember solving a problem which had the same idea (sequence must increase then decrease, find number of ways) not too long ago.

3blue1brown styled Video Editorials:

Problem A+B: https://www.youtube.com/watch?v=KJVigs8w-gg

Problem C: https://www.youtube.com/watch?v=vWHUmtiPRQw

Problem D: https://www.youtube.com/watch?v=kspzot42-uI

Problem E: https://www.youtube.com/watch?v=y62jjZev3pY

Not all heroes wear capes

Nice one! Here's my 3b1b syled GIF simulation for Problem B's editorial:

Thumbnail![ ]()

Link to animated GIF: https://gifyu.com/image/cpDm

For people preferring video format: Link

problem D:

if the matrix is 4 by 4 or greater size answer is -1. and for smaller matrixes, we need to get the answer?

where I went wrong please help me?

so far so correct but real question starts after that if you don't want to brute force every case.

can we solve D without brute-forcing every case separately?

I think we can XOR the bits (0s and 1s) and come up with a simple approach for dp. I couldn't do it in time though.

if(n>=4) must -1 so we care of n<=3

What should be the states for n==3 ?I couldn't figure it out.

all 1 <= e <=m , arr[0][e] * 4 + arr[1][e] * 2 + arr[2][e] can make the bits. then we can use dp to solve the problem. build the array dp[length][8]

I brute forced for n = 6 and m = 3 and my pc crashed.

Problem D: Am I right in thinking that if the no. of 1s in every 2X2 matrix is odd then no. of 1s in every 4X4 matrix will be even hence answer is -1 for all the matrices with n and m >=4? OR am I missing something. If I'm right, then how to go further?

No that's correct, but the hard part is doing the dp for the min(n,m)=2/3 cases

Shame on me for not reading the problem properly. I didn't read that only 'R' and 'D' were valid directions for problem B, so I implemented something way more complicated to deal with all 4 directions cardinal directions XD.

Maybe this will help you fell better but you are not the only one :D

I started implementing the solution with all directions, after about 10 minutes I saw that there was more than 2K Accepted solutions so I knew something was wrong, read the full statement again and solved it in 2 minutes :(

the intresting fact about this contest was that nobody knew the proof for problem C but everyone solved it :))))

I saw that you can have a cycle iff you have a "dip" in the sequence. 95% sure that that's correct, so then I tried to count every permutation without a dip and saw that for every n, it was double the previous one. You're right, no actual proof though!

The permutations that don't work are ascending and then descending. The number of them is the sum of (n-1) choose k from k=0 to n-1, and it's well known that it's equal to 2^(n-1). So the answer is n!-2^(n-1).

Interesting. I'll think about it. I was counting it in a more obscure way where I was summing over every possible leftmost element in the permutation so the answer wasn't obvious to me. Thanks!

One way you can see why it's the sum of n-1 choose k from k=0 to n-1 is that you have a 1-1 correspondence between subsets of {1,...,n-1} and a not good permutation because you place all the numbers in your chosen subset to the left of n and then the remaining to the right of n (there is only one way to arrange these two subsets). Or you can just think of it as there being two choices for each number, being on the left of n or the right of n.

i dont think so..

like when you would see, you will find that when the case is highest number is not at the ends then all such cases will result in cycle and when largest number is at ends there are some cases which will lead to cycle.

That some cases are the cases from previous number so it's a recurrence relation.

`tn = (n-2)(n-1)!+2*tn-1`

How it needs proof!

Non-valid permutations are the one which first increases then decreases, rest all are valid, and number of such permutaions are $$$2 ^ $$$ $$$(n - 1)$$$. So ans is $$$n!$$$ $$$-$$$ $$$2 ^ $$$ $$$(n - 1)$$$

Problem C was really fun. I saw a pattern and yolod it, and hopefully it passes all the tests LOL.

plz share your solution if it possible... now system testing is running so I can't see...

https://gist.github.com/bananabrick/b1e7172b2656a86d71c7f2ff2a169b15

I was in a hurry so the code is messed up LOL

proc C, to me, some kind of math proc isn't it?

fact(n) — (fact(n/2)*fact(n/2+n%2)*fact(n-2))

but large number factorial is needed

just my guess....

you just have to apply mod anyway so while finding factorial apply mod.

Problem C was really awesome and the statements were also quite perfect...

Isn't the answer to C is

`fact(n) - 2^(n-1)`

???Yes, it is!

Can someone please see why my solution to C failed on pretest 6 ? My answer is also

`fact(n) - 2^(n-1)`

?Link : https://codeforces.com/contest/1391/submission/89453457

when fact[n] < 2^(n-1) you give a negative number. you have to add MOD and then apply %MOD again.

Yes...But there is modular arithmetic..

Apparently i misread the question for problem C where i was trying to solve for smallest and largest $$$j$$$ on right side of $$$i$$$ ,where as in question it was to consider both sides and by time i realised i misread the question,i had no mood to solve it,but it involved quicksort .

How to solve question $$$C$$$ when edges for $$$i$$$ are considered only from elements of and involving same conditions right side of the array?

Nice problemset. I think D can be done by bitmask dp, correct me if I am wrong.

How to determine if a round is goodReally nice contest! D was the first dp problem I've done in contest in a while.

Solution for D: If n>=4, the answer is -1. To see this, note that each 4x4 matrix is broken up into 4 2x2 submatrices that are disjoint. If the sum in each of these is odd, then the sum in the 4x4 matrix should be even, which is a contradiction.

Now, we do cases on n=1 to n=3.

For n=1, there are no even sub squares, so the answer is 0.

For n=2, each column alternates between a sum of 1 or 0 mod 2, so theres only two cases to check here (whether the first row has sum 0 mod 2 or 1 mod 2), and that can be done in O(m).

For n=3, you can use dp. Let dp[i][j] be minimum number of moves needed to get the first i columns to satisfy the problem constraints, with the ith row equal to j in binary (so, for example, if j=5, then the ith row would be 101). Then, dp[i][j] = min(dp[i][j],dp[i-1][k]+add), where k ranges from 0 to 8 and is the state of the previous row, and add is the number of moves to change the grid ith row to j in binary (so it would be 2 if the ith row was 000 and j=5 = 101 in binary). Answer is min(dp[m-1][j]) from j=0 to 7, and time complexity is O(m*4^n), but n=3, so it passes. There might be a more efficient solution.

I think we can construct 4*3 matrix. I have constructed a 4*3 matrix in my copy?

`N <= M`

Thanks for such a nice contest!

We want more such contests :)

E is a nice problem

Idk if I'm dumb, was anybody else confused with the "Cycle of length n", for n = 4 there weren't 16 cycle of length 4. Although there were 16 perms. which have cycle.

My solution for problem C failed on pretest 6 using C++. Later, I changed it to python and it worked. Can someone explain why?

(Did n!-2^(n-1))

C++: https://codeforces.com/contest/1391/submission/89438077 changed to: https://codeforces.com/contest/1391/submission/89443077

because (fac-ans) can become negative

(a — b) % m = (a%m — b%m + m)%m

Nice contest, math lovers for the win. I go back to Div4.

Lol

Most of em just AK'd problem C with OEIS!

But it still felt like more or less fair math, at least.

I am so used to seeing your name in blue that it feels weird when it is cyan.

Thanks for your support ;)

no problem i believe that u can get whatever you lost within one contest..

Yep

A — trollforces

B — observation?

C — math