Hi everyone!

Missed me? I bet no! In either way, here goes another one round which I dared to spoil by my participation in problemsetting. Welcome to the world of extremely unoriginal problems, awkwardly long and boring statements and trifling jokes in anouncements.

This time round was prepared by Ildar Gainullin (gainullin.ildar) and me (I'm ashamed to place link of such color here, you know who). We want to thank Vladislav Isenbaev (winger), Konstantin Semenov (zemen), Alexey Shmelev (ashmelev), Ivan Smirnov (ifsmirnov) and Alex Fetisov (AlexFetisov) for testing problems and help in preparation. Also special thanks goes to Nikolay Kalinin (KAN) for his help as coordinator and, of course, MikeMirzayanov for polygon and codeforces.

We hope that you will enjoy the problems, good luck and have fun!

**UPD**. Also thanks to akvasha for completing our problemset by his problem.

**UPD 2**. The contest is over, congratulations to winners!

Div. 1:

Div. 2:

Here are editorials.

Man! I need such sense of humour!

Anyways, GL and HF.

Guess who is more pr0?me me me. Do you even code bro?

how to get a better Contribution?

stop commenting or you will get more down vote :)

Seems interesting :D

Great Grand Duke Olexandr Kul’kov

I'm sorry but you have some small mistakes.

It's more correct to write Oleksandr (or Alex if you are lazy to write long words).

"Great grand" is a bit tautology. But if you mean that Oleksandr is a great guy then maybe it's ok.

Sources: link, standings of some competitions and wikipedia.

I hope my comment will help you :)

Help Post, Why my solution was getting WA? Problem My Solution. Why WA Plz Help me. To Find Out Plz.

Logged in just to upvote you

Thanks man. Means a lot.

And I to down vote you. Bish.

When the announcement is so exciting, I bet the contest will be awesome!

`Welcome to the world of extremely unoriginal problems, awkwardly long and boring statements and trifling jokes in anouncements.`

sees some problems from his past contestsOkay I'm bracing myself :D

How many problems in the contest?

Isn't this clashing with Topcoder SRM 726 ?

how many number of problems will be there?

FUCK TC SRM. It is clashing with cf round so no way i'm missing it!!!

hope for no long queues. c:

And hope for no geometry :c

awkwardly long problems??? why??? ):

negative comment seriously? do you really like them?:D

Nooooo... CF and SRM are clashing :/??? Seriously?

Hope either Codeforces or Topcoder will change starting time as soon as possible.

Unfortunately, when we announced this round, there was no SRM on this date on their schedule. When they announced it, it was too late for us to move this round.

Hi, I think there was Data Science Newsletter (of Topcoder) titled "It's Data Science Newsletter Time! SRM this Saturday & the 19th!" in December 9th (10 days ago) and it has a schedule — "SRM 726: December 19 at 11:00 UTC -5". And I remember that the date that announced this round was less than 10 days ago. So I think "When they announced it, it was too late for us to move this round." is not true, isn't it?

I've put Round 453 on the schedule on the 7th. You know, it is the end of the year, we have a lot of rounds and I also have a lot of other things to finish, so wasn't able to move it, sorry about that.

But that's a matter of 90 minutes, was it so hard to put the contest in the 'usual' time (19:30 MSK)?

After SRM we can start no earlier than 21:05 MSK, it is too late. Before it we can start no later than 16:35 MSK, it is too early.

1) So if I understand correctly following events happened in this order: a) you scheduled round on today, b) topcoder announced their SRM date, c) you announced cf date. If that's correct you can't blame them for putting SRM at clashing time.

2) 21:05 MSK is too late? Many people from Russia participate in SRM at 5:00AM MSK. Or did you mean some other issues?

1) By scheduling I mean posting it on the public schedule at /contests which propagates to calendars and so on. So I use this word in the same meaning as announcing.

2) Yes, it is too late. Rounds are made not only for red coders who write contests even at 5:00 AM, but for everybody.

1) In that case I'm sorry for suggesting wrong statements.

2) IMHO 21 is perfect time to have a contest. 18 or something can always be troublesome because some people still have courses on university or work. 21 is safely after all such activities and 23 is not too late to end contest (for me, but it depends on a particular guy). And even if it is too late for some people then I guess that having two contests, one at 19MSK and second at 21 MSK is significantly better than one at 18:35 MSK and 19 MSK. Did you try contacting TC to reschedule their SRM since CF was announced first? I guess this is worse for TC than for CF, so if they value what they do they should at least consider this.

Will the rounds be rated?

Maybe! It will be specified Later. Anyway, That is enough to have contest to

learn and enjoy. :)Maybe semi-rated!

Or x-rated!

xxx-rated round, not safe for work.

I am your follower Adamant!!! I am waiting for your contest eagerly Hope Someday I have a chance to meet you :)

phew...and i was worried no one's gonna ask that...XDDDDD

After retired from ACM-ICPC, I still have something to do with Codeforces, something like becoming a MASTER, just for fun. # Hello the world without training!

Intriguing announcement :D !

This shit better be unrated, ami right or am I right boizzz?

Every Third Contest I do on Codeforces becomes unrated due to Server Issues / Test Cases Issues etc.

FINGERS CROSSEDNot today, I hope :D

Let's see what type of problems comes in today's round.

First two problems will require Geometry/Math. Calling it.

lmao fail

I request the problem setters to restore the difficulty level of problems, the last 2 contests were a bit easier.

Even then you didn't participated.

Help Post, Why my solution was getting WA? Problem My Solution. Why WA Plz Help me. To Find Out Plz.

adamant gonna be pulling our strings tonight (ahem).

This was the contribution to Global Warming :) [ LOTS OF TREES ].

Why can't I see other's solution to hack? Only thing I see after clicking the solution is Update adobe flash. I use chrome browser.

Have you tried updating Adobe Flash Player?

I too cant hack after locking the problem. I have all the tools installed

Try Firefox

I m using chrome and am able to view my solutions.but not others. Next contest i will try firefox.

maybe flash is disabled in chrome, click the circle near codeforces url and allow flash.

Thankyou.. i will check

How to solve Div1 C?

for each i , find smallest j such that [i,j] induced subgraph has a cycle , to do that , build a max spanning tree(weight = min(i , j) for an edge i <-> j) , now its just some path queries.

thought this. couldnt implement in time. sad.

nice !

How To Solve Div2 Problem A? Can anyone Explain?

It is possible to solve it by maintaining an array of booleans:

reachable[0],reachable[1], ...,reachable[m](initially all elements are

false, exceptreachable[0]which istrue).Then, while reading input do the following:

(a, b), ifreachable[a]then iterate byxfromatoband assign true toreachable[x].The answer is

reachable[m].How to check discontinuity in this case?

It depends on what you mean by discontinuity.

No Path from source to destination.

Link is broken?

You probably meant the cases when

b_{i - 1}<a_{i}for somei?Suppose that

a_{i - 1}is reachable (reachable[a_{i - 1}] =true).After (

i- 1)-th step, we will havereachable[a_{i - 1}+ 1] =true,reachable[a_{i - 1}+ 2] =true, ...,reachable[b_{i - 1}] =trueNote that

reachable[a_{i}] will remainfalse(becauseb_{i - 1}<a_{i}).On

i-th step (as well as during all other subsequent steps) we do nothing becausereachable[a_{i}] =false.The answer will be

false, as expected.Full code is also available (33420669).

Yes.Thanks For Help:)

Maybe I can.

So, you should initialise "int RightCan[submission:33422641] = 0" — the farthest point you can reach. (And you can also reach ALL the points before it — from 0 to RightCan).

If a[i] <= RightCan — then we can reach the start point of teleport[i]. So, we can change RightCan to b[i], if (b[i] > RightCan). (This if very impotant... becouse otherwise we can decrease RightCan!).

It's know that a[i] >= a[i — 1], so we don't miss anything.

And now, if (RightCan < m) you should print "NO\n", otherwise — you can reach your goal and print "YES\n".

Here is my solution: 33422641

Thanks For Help :)

If it is possible. Can you help me, please? In pretest 5 we have:

In what way can we teleport from 11 to 13? Thank you in advance. In my solution http://codeforces.com/contest/902/submission/33436932 i had wrong answer.

Starting point should be 0 always as state in the problem statement. In Test-5: it's start from 11 so answer should be for this case is "No".

I'm afraid that you got the problem condition wrong. Didn't you?

Specifically, if

a= 11 andb= 39 (as in the first line of the quoted example), then you can teleport from 11 to 12, from 11 to 13, ..., from 11 to 39.If I understand correctly. We must take into account all the previous iterations, if the current position does not change.

If the

x= 11 point is reachable through teleports only (after processing all the previous input),then 12, 13, ..., 39 are also reachable through teleports only.

(

x= 0 is always reachable because It is the starting point.)Well, look here:

3 7

0 6

1 2

4 7

Your solution gives the answer "NO". But your can reach point 7: 0 -> 4 -> 7.

port 1: [0 _ 1 _ 2 _ 3 _ 4 _ 5 _ 6]

___port 2: [1 _ 2] ___ [4 _ 5 _ 6 _ 7] <-port 3.

This happens because your looks only on the 2 last teleports. _____________________________________________________________

And yes, isn't mivael right?

Thank you very much. I will try to implement the correct solution.

Thank you for your time Can I bother you a bit more

have we answer NO ?

Oh! I understend. We must begin from zero I solved! Thanks for help.

The basic idea behind the solution is you have to find is there any discontinuity between 0 to M.

To check this Take an array A of size M or greater having initial value 0.

now take the input [x;y] and do this.

A[x]+=1;

A[y]-=1;

after doing this take prefix sum of array a using A[i]+=A[i-1] form i=1 to M.

now if any element in array A [ 1 to M ] is equal to 0 except last value then answer will be 'NO' Otherwise 'YES'

Can you explain how prefix sum work in this case?

Take an example.

N=3 M=5

0 2 ; a[0]=a[0]+1,a[2]=a[2]-1

2 3 ; a[2]=a[2]+1,a[3]=a[3]-1

3 5 ; a[3]=a[3]+1,a[5]=a[5]-1

after doing this your array will look like

[1 0 0 0 -1]

now after taking prefix sum your array will become.

[1 1 1 1 0]

no element is 0 except last one so your answer will be "YES" in this case.

Why array consist of only 0 and band 1? It should store sum of x and y?

What's the pretest 3 on C ?

How so solve Div2D?

Also, though I was able to solve Div2C , someone please share the logic of it. I saw some people did C quite quickly. That was like fucking awesome.

Was it so easy or some general problem that I don't know?

What I did was for one tree, I kept adding all the children to a single node. And for the other tree, i just remove one child and put under some other parent. Hope this is the right logic though

Hmm seems nice and same as mine. :)

Although I was able to come with one more logic though a bit late but I believe this will work.

No two consecutive terms should be not equal to 1.

I mean to say that no two non unity terms should have distance less than or equal to 1.

This will suffice as a condition. For designing a tree, your and my logic should work I suppose.

There can be consecutive 1's. The condition is there should be atleast 2 consecutive 2's(or numbers >1)

Yes..That is the thing what I wanted to write. :)

This is what I implemented. Let's see if it is right, lol.

How to solve Div2 D/Div1 B?

B. I went for a DFS solution. set the root color and then dfs iteratively coloring the nodes

He's mentioning the Div1B, not the Div2B.

He is asking Div1B.

lets work on

f_{0}= 1f_{1}=xf_{i}=f_{i - 1}*x+f_{i - 2}answer is

f_{n},f_{n - 1}Yeah I did exactly the same.

Overlook the condition that that co-efficient should be -1,0,1 and got the wrong answer :(. Else did exactly the same.

Or use Google: https://en.wikipedia.org/wiki/Fibonacci_polynomials

Usually I self-proclaim myself as someone who knows many things about math, but here you proved the opposite.

Thanks for the enlightenment you brought ;) I got stuck for an entire hour with D and not even knowing about this ;)

How do you use Google in such problems? I guess that searching "polynomials euclid algorithm small coefficients" would yield no useful result and even on that page you provided I see no useful info (without that mod 2 trick that I still don't understand these Fibonacci polynomials are useless).

You can do it by arbitrary mod. Mod 2 is to keep coefficients below 2. The thing is that if you calculate gcd using some mod and has

ksteps you will have at leastksteps calculating it in rationals.Using this formula,

f2= x*x + 1 = x^2 + 1 andf3= x*(x^2+1) + x = x^3 + 2xSince, the coefficients should be from -1 to 1. So how did you handle this part?

mod2

Thankyou! :)

Instead of mod 2, can we multiply it with (-x) ?

Yes but some higher degree polynomials may contain coefficients outside the range. So you need to multiply with x or -x depending on the current situation.

But the coefficients won't be -1 0 or 1 right?

(I don't know.. I am probably wrong but please tell me where I am wrong)

Working in means the coefficients are taken mod 2

f3 = x^3 + 2x, however all the coefficents must be in [-1;1]. How did you solve this issue?

UPD: solved

What? I have no idea why this works :f. This seems like key idea here, but I see no meaning behind it.

It's well known that GCD takes the longest time on fibonacci numbers. This is just an extension of the idea from numbers to polynomials

If we abandon condition about coefficients being from set {-1, 0, 1} then this problem is trivial, I was well aware that without it we can do

f_{i}=xf_{i - 1}+f_{i - 2}... What is tricky here is that reducing mod 2.if we work on instead of , then this obviously works since

f_{i}modf_{i - 1}=f_{i - 2}sincex*f_{i - 1}+f_{i - 2}modf_{i - 1}is obviouslyf_{i - 2}in , this fact still remains true , since degree of

f_{i}= degree off_{i - 1}+ 1 and powers ofxare independent over .I still have no clue about your solution. It is of course true that over , but I see no connection of that fact to Euclid algorithm in and have no idea what this independence has to do with anything.

well

f_{i}modf_{i - 1}=f_{i - 2}even in , are you sure you didn't misread the question and thought that coefficients should be {-1,0,1} even for immediate steps?Let's make it clear what is obvious ans what is not:

Obvious fact 1: If we define

f_{i}=xf_{i - 1}+f_{i - 2}over then we have overObvious fact 2: If we define

f_{i}=xf_{i - 1}+f_{i - 2}over then we have overObviously false statement: If we define

f_{i}=xf_{i - 1}+f_{i - 2}over then we have overSince that last fact is not true, I see no connection of your solution to Euclid algorithm.

And regarding "are you sure you didn't misread the question and thought that coefficients should be {-1,0,1} even for immediate steps?" — during contest I was solving that wrong question you mentioned (however I am pretty sure you meant "intermediate" not "immediate" :)), but I realized it was not necessary some time ago and still have no clue about it.

EDIT: Sorry, I made a typo in first version of that post in "obviously false statement"

ah , i finally get your point , i completely forgot this during contest and just implemented it straight away thinking "its just a div1B , it can't be that hard".

Let me think about it for a while

The proof isn't that hard. Start from the two polynomials

f_{n},f_{n - 1}. Now do Euclidean algorithm over on these.You can show the following claims by induction. First, all fractions during the process will have odd denominator. Also, the numerators of a polynomial

p_{i}(x) you get during the Euclidean algo over will have even numerator if and only if the corresponding coefficients inf_{i}(x) is 0. In particular, all leading coefficients will be fractions with odd numerator and denominator.okay here is a much simpler reasoning of why this takes

nstepsSuppose on the contrary , it takes <

nsteps , then for somei,f_{i}modf_{i - 1}has degree <i- 2.f_{i}=f_{i - 1}* (ax+b) +r(x)degree of

r(x) is less thani- 2let

f_{i}(x) = ... +px^{i - 2}+ ...and

f_{i - 1}(x) = ... +cx^{i - 2}+ ...dx^{i - 3}+ ...then we have

p=bc+adin , since each of them are rationals and 2 is obviously a prime , each of these terms exist in as well hence this holds in as well and we have degree ofr(x) is less thani- 2 in as well which is a contradiction.Just try random polynomials: one of degree

nand another of degreen- 1 till it works.Alternatively, you can set

P_{0}(x) = 1,P_{1}(x) =xand fori≥ 2, setP_{i}(x) =x·P_{i - 1}(x) ±P_{i - 2}(x)for some choice of sign. Exactly one choice of sign works once you fix $P_2(x).$ A computer can verify that this works, but I have no proof.

how to solve c and D?

...... ( f(x) , x+1) -> (x+1 , x ) -> (x,1) -> (1,0)

каждый раз надо находить такой f(x) что f(x) mod (x+1) = x (в нашем случаи ) но я так и не смог написать )

I think Div2C Greedy problem

can you please help me with my code : https://ideone.com/talzy9

test

5

1 2 1 2 1 2

You program is wrong Answer is "perfect"

can you please explain why the answer is perfect in this case?

EDIT : my bad now i understood thanks a lot for the help ! :)

btw if i am correct the cases of perfect are those which don't have two consecutive ai > 1 ? if i am incorrect please correct me!

I change you code. I think its correct

"awkwardly long and boring statements"Lol so true

i dont understand problem C, output sum(a[i]) E i = 0->h

That refers to the number of integers you are to print. The summation is nothing but the number of nodes in the tree

How to solve div1B?

What was the purpose of putting "tree" in title of D? To give a hint for contestants :f?

In Russian is graph instead of tree :/

For those who ask about seeing others' submissions/hacks/adobe flash player:

set these settings:

Allow website to use Flash

i am able to see others submission history but unable to see solution even after locking!

Lol, I hacked a few people on Div1A because they did something like

`cout << ans[i]`

where`ans`

was of size ~10^5.NOOOOOOOOOOOOOO!

1e5 ?

Can you elaborate?

Nice contest. Couldn't understand C for an hour and after i understand it i solved it in 20 mins. But in general nice.

What Div2 (A) pretest 6 ?!

May be something like.. 3 10 0 9 1 5 7 10

Ooooh, I did break while getting input. My output in pretest 6 was: -- NO NO --

This is the way a codeforces contest should be prepared.Kudos to problem setters.

Overall, the problems are good. I think ive seen Div2B & A with some changes, the C and D are so challenging. Even though, i almost made it, apparently i didnt. (._.)/, I'm actually really tired but i rushed to join this contest because i wanted to get my expert rating (AHAHAHAH), I ended up doing really sucks, and sloppy (Because of my skill in graph). Lesson I learned in this contest, sometimes you need a rest between contests. :). Merry Christmas !

Update : I think B is easier than A. A is kinda "tricky"

I've just ruined another div1 contest and now i'm thinking whether it's even possible to come up with an idea for div1B if you've never seen anything similar before -_-

Well everyone had their own bad day :(. I can relate to what you feel.

Anybody anything to E? I can only generate 10^8 pairs as candidates for (sum of

a_{i}, sum ofa_{i}^{2}) :/There will be editorial very soon, please be patient :)

Hey, is he a cheater or acts like tourist in the last cs round ? :‑Þ

Could you explain exactly what makes you think he could possibly be a cheater?

maybe submissions time?

How is solving three problems in 1 hour and 52 minutes suspicious?

so you c am asking if a cheater || !

Are you a cheater, by the same token?

with 2 years in gray ? -___-

I finished coding C/div1 5 minutes after the contest with O(n log n) solution :(

can you please share your approach for this!

For each vertex i find the minimum vertex X such that the graph consisting of vertices [Xi i] is bipartite, this can be done using two pointers.

Now iterate over vertices from 1 to n, for vertex i add 1 to the segment [Xi i] then answer all queries that end in this vertex by finding the sum of elements of the segment that describe the query.

UPD: I got WA, seems like the tow pointers approach is wrong

Good contest, problem D div2 could have been better. but in total, it was way better than what you described.

Can't believe I messed up Div2 A :/ Bad day, I guess

Same :/

Can someone hack this , or explain why fit time limit?

Such a Great contest! thanks guys XD

How did this guy submitted after contest ended?

even you can get query for big n in problem D(dive2) and make it more interest!

Most of it was graph theory.\ I LOVE GRAPHS <3 really enjoyed it , keep up the good work.

how to solve DIV-2 D?

Really Simple :p . Check out the editorial.

Help Post, Why my solution was getting WA? Problem My Solution. Why WA Plz Help me. To Find Out Plz.

.

In div2B why dfs gives the minimum answer.when to apply dfs or bfs i am weak at it plzz help

I guess depends on the logic. I thought BFS way. You need to color root of tree at least once. Just color it in first go and this will make all childs of same color. Put neighbours in queue for bfs and go on like this. Link: http://codeforces.com/contest/902/submission/33421572

You can use both bfs or dfs to solve this problem.

Keypoint is to note that bfs or dfs produce same result in case of tree.

Mostly people use dfs in such questions because it is shorter. :)

Div 2 problem C 902C - Hashing Trees, Testcase 2 working fine in my computer. But TLE in CF judge 33450049.I'm unable to find any TLE reason.

Undefined behaviour or bug in compiler. The first is more probable. Look at the output of your program.

You mentioned "unoriginal problems", evidently I found almost similar problem of div2 A — A. New Year Transportation :D

@adamant: One doubt was this the source of motivation for this problem? :D

How To Solve This Problem. Help me plz

How to solve Div 2E? I need some implementation details.

Help Post, Why my solution was getting WA? Problem My Solution. Why WA Plz Help me. To Find Out Plz.