Hello!

Finally I am freed from the big part of summer cares and I can continue the preparation of Div. 3 rounds! I decided to add something written by me to this blog because TryToKnowMe (and many others, i think) noticed that i am really copy and paste this text from one announcement to another changing only contest name and start time. But... Who knows, may be this time which is saved by copy-pasting the announcement allows me to prepare the problems better?... Let it stay a mystery. So, let's go.

Codeforces Round #498 (Div. 3) will start at 16.07.2018 17:35 (Московское время). You will be offered 6 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. Probably, participants from the first division will not be at all interested by this problems. And for 1600-1899 the problems will be too easy. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

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

You will be given 6 problems and 2 hours to solve them.

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

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

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

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

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

Good luck!

**UPD**: Also great thanks to the testers uwi, mareksom and ivan100sic for their invaluable help with the round preparation!

**UPD2**: Results table!

Congratulations to the winners:

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

1 | HighPressure | 6 | 236 |

2 | LividFox | 6 | 237 |

3 | Rzuji | 6 | 265 |

4 | Syvail | 6 | 273 |

5 | khadgar1998 | 6 | 279 |

Congratulations to the best hackers:

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

1 | jhonber | 131:-7 |

2 | antguz | 9 |

3 | ducdien2267 | 9:-3 |

4 | djm03178 | 6:-1 |

5 | imlk | 4 |

199 successful hacks and 232 unsuccessful hacks were made in total!

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

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

A | eggmath | 0:01 |

B | eggmath | 0:06 |

C | thidailoc | 0:07 |

D | MoreThanANoob | 0:23 |

E | Student_of_Husayn | 0:07 |

F | NoTrolleNoLife | 0:18 |

**UPD3**: Editorial is published.

hope halyavin the system tester also provides his service this time!!!

I really want to know how does he do that so FAST!

He uses some script.

He should really do a

screencastwhen he is hacking. I mean I don't get a test case for hacking until I have already given a solution which is accepted for the pretests and I have found a test case which is already in the problem statement and not matching my codeThe script is used only for testing the test case he feeds into the script on different submissions. The test cases are not generated by the script. He himself thinks of the test cases and then feeds into the script.

minimize hacking phase to 6 hours at least try it once if everyone agrees implement it permanently.

Yup, 12 hours is too long

24 -> 12 -> 6 -> 3 ....

1.5 _> 0.75 _> 0.375 _> 0.1875 _> 0.09375 _> 0.046875 _>in contest hacking we know the sequence

May be....

Well,it's not good to hack at midnight.

The world in round round sphere. Someone will have mid day when you have mid night.

All right.

So it is unrated for 1600-1899?

Yes.

It's written on the discription....

let's hope strong pretests and fast responding server side...

Next contest starts after 10 days. MikeMirzayanov are you going somewhere?

Ha Ha Ha :D

Please wait....

This is codeforces.

Btw It's summer

I have seen many people having confident profile pictures. None as confident as yours.

:metal:

Good luck everyone <3

There is no choice for choose;b

Expecting more and more mathematical problems.

first contest after world cup ..

Vovuh i think you have to add this

penalte is

10 minutesso people who ask for it get downVote hahaBig thanks to you! Added to the announcement.

until now i have the most rated (upvoted) comment hahah ...

and the most (downVoted ) will become true .. here ?!

This comment really ruined your contribution :)

you do not know me hahaha

i make balanced comments +-

contribution does not matter -101 is so good

I always feel comfortable with div 3 problems. So I love it very much.

Me too...Best of luck everybody....

btw mee with div1

Realy It was the best fun of this year :D :D :D

Sad that I may have to miss the round for my final year project work :(

i put my exams away when a round will take place

harmfull

But now candidate of masters are in both div2 and div1 which one they are???:D

They are the one with spear..

Just mark the changes

For a long time, I am still in Cyan. :) Div 3, the road to changing color.

Many thanks about Div 3 idea.

I love Thu Huyen too.

to green .. you are welcome

:3 Interesting!

Don't worry buddy, we know you didn't copy pasted. Who need that when you have scripts lol

You got me, bro! :(

P.S. Cool idea about the scripts btw

Anyway Vovuh your round is good as usual :D

Thank you :3

Why topcoders hide their faces behind anime profile pics?

because it is 18+

i prefare regular div2 contest style not the ACM-style and hacking in contest time gives points ..

self-bombing

Hope that this will be my last div3 contest from next time I can participate out of contest.

you will looks like ..

Strong pretest :)

Have you read this?

`You may edit your comment only for fixing grammar mistakes or small changes. Do not change the main idea of your comment. All previous revisions are available for others. Are you sure you want to edit comment?`

Main idea of

`Hope that this will be my last div3 contest from next time I can participate out of competition in div3. Never had that feeling :(`

and`Strong pretest :)`

is not the same.Upvote for ivan100sic and good luck!

problem setters are ultimate!! hats off to them

Probably, participants from the first division will not be at all interested by this problems.I am always interested in Div.3 problem sets. :D

you will stay a boy !!

Because of such participants there is a word "probably" in the beginning of the sentence =)

nice hack

such participantsthis seems rude xD.Oh, sorry, I am not so good in English so on Russian this phrase sounds fine

it is super fine hahaha like an "idiots"

Easy offline solution for E using cartesian tree (treap). 40444978

Easy solution for E using simple DFS/ 40428850

same Solution get TLE on test case 2 I don't know why??

I don't think it's the same solution, because it's written in java :)

`id.indexOf`

works in linear timeThanks...easy to store id in array

orz

Easy? The easy way is a preorder traversal

(just realized it is probably sarcasm OOPS)

Easy, because you don't need to think about it, just implement it.

Yep, preorder traversal to save new array O(N), each query we can answer O(1)

(just realized it is probably sarcasm OOPS)Oww, then I just realized my solution is so hard.

How to go faster than

O(n^{2}*k) in B?Use k largest values for maximums of these segments, and then extend them.

I'm stupid

sort the values in reverse and find the index of top k values. then one loop would give you the size of each segment

Can you explain more on how to get size of each segment?

suppose I have [101,3,5,6,10,100]. So, I take a temp array and sort this in desc order. The temp[] = [101,100,10,6,5,3]. Now suppose we want to get the top 3, get the index of 101, 100 and 10 from original array and save it somewhere. idx[] = [0,4,5] (0 based indexing) . The size is 1, 4 and 1. You need to take care of duplicates. For that once you visit save the index and remove the element from original. I am very bad in explaining stuff. Submission: 40426181 .Please let me know if something is not clear. will try to explain more clearly.

Thanks a lot! It's clear enough

answer would be sum of k- maximum elements in array and keep these k maximum elements in a multiset then just traverse form 1 to n and if a[i] is element in multiset remove it and print number of elements from previous partition.

Can anybody explain problems D and F please?

For D you just can see that changes makes cycles i -> n — i + 1. For every cycle find min changes.

The key observation to solve problem D is that each letter in string A has 3 counterparts (except when n is odd and you consider the middle letter). These counterparts are the letter at the opposite position in string A, the same position in string B, and the opposite position in string B. You can think of these 4 letters as a group. Each group, after preprocessing modifications, must contain two pairs of letters. Once this observation is made, a bit of case-bashing can determine the number of modifications necessary.

My solution for problem F was meet-in-the-middle. If you start from the bottom right corner, you can determine the possible values for any grid square which can result in a final XOR-value of k. I calculated these values along with the number of paths which resulted in these values up to the 'middle' of the grid (where Manhattan distance to either corner was equal to (n+m)/2-1). Then, the process was repeated starting from the upper left of the grid.

how to solve F?

hmm

Notice that 20C10 is only < 200k, so we can use meet in the middle to get the answer -> DFS all possible routes from (1,1) until middle of grid and insert it into map, then DFS from (n,m) until middle of grid

What about paths that don't go through the middle of the grid? I assume that middle is point (n/2, m/2).

Middle of the grid can simply mean a certain Manhattan distance from the upper left of the grid (i.e. y+x==(N+M-2)/2), indexing at 0).

Great solution! What will be the time complexity in this case? Thanks in advance!

should be 2^20 * 20, i believe

Since we are traversing just half the graph, once from (1,1) and once from (n,m), cant we just say it will be 2*(2^10)*(2^10) = 2^21?

no, you don't multiply both halves when you traverse the graph. But each half individually is 2^20 ways, because 20 is only the halfway distance, and you have to choose either to go right or down. Last 20 is for the log factor in the maps.

Oh ok. Might sound noob but since one half takes 2^20 moves, and we traverse half the graph twice, shouldn't the complexity then become 2*2^20 = 2^21? And if we use unordered map which is essentially a hash table,can't we ignore the log factor coz of the maps?

unordered_map has test cases to counter against its usage, so I never use it anymore.

Yes, it will take 2^21, but the point is the complexity is n * 2^n still

Nice solution but how do we combine two half subproblems.Do we combine ans use binary search or something like that..

Can you explain any case for breaking unordered map I couldn't find any for that.

Couldn't find the original. This is pretty solid proof though:

https://codeforces.com/blog/entry/21853?#comment-322392

Can you please suggest any good resources/problems with editorials for bidirectional DFS/ meet in the middle? It is a new topic for me. Thanks!

Bidirectional bfs

there is no hacking in Div3?

Yep, thats rule of this round

Great contest, Problem set was so balanced and covered all topics perfectly. Ideal contest for div 3 participants. Dude make one div 2 as well, I would really like to attempt it officially :P

inYourDreaM hacked all his solutions!!

Realized the importance of time today !! :( But it was a great round.

why in Problem D my code get WA on test 3 -_-

https://ideone.com/egWiTd here is my code -_-

Your second condition in temp(=3) (i.e. b[i]==b[n-i+1]) is wrong. When a is "xy" and b is "uu", a can be preprocess to "ux" and then it can be changed into b using given steps.

Check this test 2 aa bb Answer is 0

yes, my answer is 0 swap(a1,b1),(a1,a2) so we can get ab==ab -_-, why it WA

This one 2 cb aa Answer is 1 but yours is 2. Sorry i forgot that "note that you cannot apply preprocess moves to the string b b or make any preprocess moves after the first change is made"

How do you get 1? UPD: got it

My code also got failed, could you please share some more complex test cases.

Check 2 ab cc Answer is 1

`if(b[i]==b[n-i+1]) res+=2;`

In this case, you only need to do 1 preprocess step only. Your aim is to have two pairs of identical characters, so just change a character in string

ato the other one.Thanks..

I think you are rejecting the case when all are four characters(a[i],b[i],a[n-i+1] and b[n-i+1]) are equal OR the case when N is odd and middle element a[i]==b[i].Solution 40472491

my code is giving correct output for problem E in Sublime editor but wrong answer on the codeforces editor.How it is?

## include<bits/stdc++.h>

exactly same with my code

You should return mm[s] in the dfs, and this line is incorrect:if(j+y-1<=mm[x]). Should be if(y <= mm[x]).

thank you so much

Bro pls look into this-> http://codeforces.com/blog/entry/60654

Found some serious cheating going on here-

f20170604 Copied F from Roundgod --

40438080 Copied from — 40428801

Sad thing is that in order to hide it, five minutes later, this guy submits another code, with all the headers removed thinking he will not get caught.

Here is the second submission — 40438951

What?How?I'm pretty sure that I didn't give my code to anybody...

I hope you did not even mistakenly use an online compiler on a public mode. Highly unlikely but still.

Pretty sure that didn't happen ,either. Have just changed my password. Thanks anyway.

Did you try running that code on ideone.com or some other similar website?

Nope. I used vim on my laptop, with gcc as the compiler.

Finally found out what happened here... It turned out that I uploaded my code to my github after solving F... Have just made the repository private. My apologies.

XD The guy wa 31 use the same idea and change your code a little bit But he got a wa So he submit your code directly to make sure that your code is right

a master mistake costs 1000x times newbie mistake ..

So he basically had your github repo open on one tab.google doesn't index so fast.

Lol this has happened to me too.

This can done easily with the help of Second id first he solves a problem and then he lock its problem and then see the code of any other guy and then he submits it with a different id.

In div 3, he can't do that because it doesn't have "hack" and "lock", everyone can't see other's code until the contest ends.

"

halve the grid diagonally not vertically nor horizontally you idiot!"thats what test 22 on problem F would have said to me if it could speak.

I went DP but full brute on bitmasks and got MLE at test 47. Hmm how come I passed that?

My failed submission.

the memory is 20*20*AllPossible xors

All possible different numbers from taking the xor is a big number, thats why you Got memory limit exceeded

Yeah, I meant, even bruting like that, how would I passed test 22 and dozens of tests following until that, while yours stucked at it? Just curious.

Check the first tests they are meant for TLE detection.

numbers are small thus their xor is also small and dp on these constrains work but when numbers are big dp will get you TLE or MLE whatever comes first.

Alright, now I understand — difference in approach :D

Thanks!

How is diagonal better than vertical/horizontal ?

If you go full brute, the maximum amount of bitmasks you have to handle is

nCr(38, 19).Cutting vertical/horizontal decreases half the steps for

onedimension, therefore the maximum bitmasks count lowers to aboutnCr(28, 9) or something similar — still insanely high and might not fit in TL/ML.Cutting diagonal decreases steps in

bothdimensions, therefore further lowering the bitmasks count, to aboutnCr(18, 9).(I'm not actually that certain in those combinatorics — those are estimated. Still you might get my points ;) ).

Hmm... is this normal??

it seems you do not know halyavin

upd ..sorry wronge answer ..

maybe arrays limits .. if conditions !?

Check his solutions, he is using an if condition to hack it. for eg. In problem A, he used

if(x==210400)return 0;Oops, that's bad, I see cheaters coming in waves :S

How he knew that there was no value of (x==210400) ????

Well, you can choose any random number and you'll have a very low probability of coincidence against pretests.

and he succeed for all his 6 problems.

Yes, for the same reason above. It's very feasible. You can calculate the probability for that to happen ;)

ayush347 tried?

can someone help me to find the logical error for Problem D 40443887

Fixed it: http://codeforces.com/contest/1006/submission/40452847

The only change was: "if(ans[3]!=ans[2]) {...}" should be "if(ans[1]!=ans[2]) continue". ans[1] != ans[2] iff we have letters of type 'a a b b' and we shouldn't make changes in that case.

but, in case of 'a a b b' , (ans[3]==ans[2]) ,so it wont increment the sum to sum+1.. So ,why is it getting wrong ljupche98

You shouldn't check ans[2] and and[3] because they can be equal for case 'a b b b' (where the answer is 1) and 'a a b b' (where the answer is 0). What you should do, is check whether the groups have equal number of elements and that is, by checking ans[1] and ans[2].

Got it,thanks!!!

Can anybody tell , why this 40450609 gives a runtime error on test case 2; Whereas it runs fine on removing the for loop for calculating subordinates O(n)

and calculating it when using dfs 40450928.

In Example 1, your code has child [2] = 6, but this is obviously a mistake. In general, the value of child [i] is not determined by the value of child [i + 1].

Thanks, for the help, That was a very stupid conclusion i made :(

When will the ranting be updated?

I think the difficulty differences between problem C and problem D is so big. It make participants uncomfortable.

Problem D :

7 abacaba bacabaa

Answer should be 3. Please correct if I'm wrong

First do pre process , then swap.

Miss that part of question. Thank you

I first swapped to check how many matching cases can be made with given type of swaps after that it was just count(a[i]!=b[i])

another contest saying an array can be a birthday present, how boring you guys are!

Where's editorial ?

It will be soon, wait a bit please

why sysem testing didn't start

I seemed to have used the right logic for B but my solution got hacked. It seems I didn't factor in some edge cases. Can someone help out?. My solution is here. Thanks in advance :)

You should tell your logic too instead of expecting someone to figure it out and tell you whats wrong with your code.

I am sorry. Will take care from next time. My logic was to find the k maximum elements of the array and then find those k elements in the array and mark them as -1. And then print the sum of those maximum k elements to get the first line of output. To get the second line of output I would count the number of elements till I encounter -1 and set counter as 0 again whenever I encounter -1. Further to take care of the test case of the encountering the last -1, I will simply add the rest of the elements left in the array to the counter. Hope that explains my approach :).

you always ask very dumb questions

I appreciate your criticism. Just that codeforces community has been the only bunch of people who seem to cater my dumb doubts. :)

Your in-mind logic was correct, but you made a mistake in your

`invector`

function: after finding the desired element, you must terminate the function immediately (otherwise it will keep marking other elements with the same value).Thanks, I got it now. For multiple occurrences my code was simply making them -1 in all of the positions. :)

when is the result expected to come?

where is the rating changes??

Vovuh it was a good round :)

what does the test 16 in my submission mean? where does 3917963 come from?Vovuh

Very late in rating update.

Remember

this.wow, You forget to make f20170604 unrated... 40438080 is a directly copy from 40428801. Why this guy still rated? Vovuh

After searching through past blogs, it seems like cf admins don't care about cheating instances like these. http://codeforces.com/blog/entry/60377#comment-442301 and http://codeforces.com/blog/entry/60573 were pointed out but the cheaters have not been disqualified :(

Cheating on your girlfriend is a far more egregious crime than cheating on Codeforces, because Codeforces will forgive you but your girlfriend will not.

Therefore I propose that anyone who participates in Codeforces contests must have a girlfriend, so no cheating will occur. #ProblemSolved (This implies that eggmath will not be able to compete, SAD!)

hmm

My theory is that eggmath is actually a monkey who works at Facebook; hear me out.

First, we see that YouTube's error message mentions "a group of highly trained monkeys" who are working to fix the error. YouTube's HQ is located in San Bruno, which is in Northern California. Guess what? eggmath lives in Northern California. This is the first clue that we are given.

The other two clues are given in Facebook Hacker Cup. In the qualification round, Ethan is searching for a string. Do any animals actively search for strings? Yes. Cats and monkeys. Based off this knowledge, eggmath can be either a cat or a monkey.

However, the next clue is pretty damning evidence: Ethan traverses a tree. Hear me out, I know cats can traverse trees too, but which other mammal traverses a tree better than a cat? That's right, a monkey. There is no other animal in the jungle that has such an agile and nimble body to traverse trees. If this evidence isn't clear enough, I don't know what is.

Therefore, I believe that eggmath is indeed a monkey.

Sorry, we will fix it soon. Thanks for the notification!

Maybe I have misunderstood something but...

It is told

`only the trusted participants of the third division will be included in the official standings table`

, but in standings there are many untrusted participants. And trusted participants ratings are affected by them. For example I am on 169th place in COMMON STANDINGS, but in RATING CHANGES and MY RATING HISTORY I am on 220th place, so my rating has been changed as I am on 220th place, Vovuh, MikeMirzayanov.In COMMON STANDINGS untrusted participants show up and then again disappear all the time.

Sorry, it was my bug in the standings parser, the winners table may be wrong also in the some previous Div. 3 rounds. Now it is fixed (i hope) because i extracted the results manually.

`I am not so good in English`

Ой, извините, только что вспомнил.Кажется ничего не изменилось :( Видно проблема более глубокая и время MikeMirzayanov? Да ладно, не проблема. Спасибо, мне(и думаю почти всем) очень понравился ваш contest, а эту проблему можно решить, да?

Also Mike knows about the bug with the standings table and it will be fixed soon i hope (really hope).

How do you mathematically compute the number of possible paths for problem F? I see many different combinatoric formulae here, but none of them are explained.

Misunderstood your question.

The number of paths for corner to corner can be seen as a permutation with repetition with formula (m + n)!/(m!*n!).

The number of paths from a corner to the diagonal is 2^20 at most. When n = m = 20 each path is 20 steps and each step either down or right.

When editorial will be posted?

can someone explain how to divide matrix in problem f clearly.. UPD:GOT IT..clear and short codes are sometimes helpful;