Hello Codeforces!

I invite all of you to participate in a **special** Codeforces round. It will take place on 29 Jan, 17:05 UTC. It will not be a usual round. Thanks to Wunder Fund, the best participants will win prizes and souvenirs. Here are some words from Wunder Fund:

Our company is situated in the center of Moscow. We are engaged in high-frequency trading — developing high-performance systems and algorithms for automated trading in financial markets. In this area algorithms and data structures (that you love to invent and implement) are vital. Our systems should process transactions in milliseconds! High-frequency trading is a continuous competition of the best programmers and mathematicians around the world. By joining us, you will become a part of this exciting challenge.

We offer interesting and challenging tasks for the development of low latency for enthusiastic researchers and programmers. Flexible and no bureaucracy, decisions are taken quickly and implemented. We are a small team, so you will immediately become a significant part of it. Understand the economics and finance is not required, but the algorithms and data structures is what we need.

Are Russian speaking and ready to live in Moscow? Join us! Visit our website for more information.

We will be happy to give participants prizes and gifts:

1 place — PlayStation 42 place — Xbox One3-5 places — Sega MegaDrive 16bit with games1-50 places — Wunder Fund T-Shirts!51-500 places — 50 T-Shirts to random participants!

I want to thank the following people for helping me with this round:

- GlebsHP for his help in reviewing problems and assistance in preparation for the round.
- LiChenKoh, AlexFetisov, and winger for testing problems.
- Delinur for translations.
- MikeMirzayanov for Codeforces and Polygon systems.
- and of course Wunder Fund for sponsoring the round.

I hope to see you all at the round. Good luck and have fun! :)

If you'd like some practice before the round, you can look over some of my past rounds that I've written (links here: A B C). I will try to give you all some more interesting problems to solve.

**UPD1**: The round will be 2 hours and 7 problems. Unfortunately, there are some time conflicts, so we are unable to extend the duration of the round. The score distribution will be **500-1000-1500-1750-2500-2750-3500**. Note that some problems that we thought are harder may actually be easier for you, so I encourage you to read all problems.

**UPD2:** The editorial is published. Congratulations to the winners

Will it be rated round?

Yes, it will be a rated round.

Is it gonna be 5 problems in 2 hours?

This has not been finalized yet. I can say that it will be between 5-7 problems in 2-2.5 hours (and maybe combined div1+div2). However, we have not yet decided, but I will update the post when I find out.

This is neither here nor there, but do you work for / are affiliated with this Wunder Fund, or did you simply write problems for a round sponsored by them?

I am not affiliated with Wunder Fund. Basically, I wrote some problems for a regular Codeforces round, but then Wunder Fund offered to sponsor a round at around the same time. I felt very lucky to have a opportunity to write for a company sponsored round, as there will be prizes and more participants.

I cant understand the downvotes, i had a query and i asked it.

This thing happened to me a few days earlier as well! I don't why this happens.

Hope to have Some Short & Easy to Understandable Problem Statement in this Contest . Good Luck to All & Me.

Short-and-easy-to-understand statement means hard-to-solve problem...

haha

Let it be combined DIV 1 and DIV 2. It will be more interesting and challenging for the DIV 2 coders as well.

your wish come true :D

My first reaction was, Lewin is the setter, the problems will be awesome :D

And there will be a lot div 1 contestant participating in div 2 to get prizes :'(

tourist gonna play everyday PS4 :)

oh, that's really disturbing here.. (like me)

Prizes and gifts only for Div1?

We are planning to merge divisions, it will be common problemset with 7 problem. Everybody can win prizes!

the contests page say duration is 2 hours, but usually combined rounds are extended by half an hour, so will you keep the duration 2 hours?

Nope. See 51-500 get shirts on random basis. So, try your best, you can be lucky.

3-5 places = the best prize

I can not wait my school holiday which starts with big CF round, continue with World CodeSprint, Serbian Qualifications Round, Codechef Lunchtime, Codeforces div 2 round and finishing with HourRank. This will be an awesome weekend and my parents will kill me because I am using computer so much :D

Win Playstation 4 so you can use your computer less and make your parents happy :)

It is bigger probability to go to some shop and steal PS4 than win some prize on the official contest :P

Even I haven't got t-shirts which I won before 8 months :)

Prizes and gifts only for Div1?

I hope it's a combined round even though I always fail big time in these for some reason. Let's see how it goes this time :D Hopefully it can be better, especially that Lewin is setting this round. I liked your problems in Round 309.

PS4 for the

firstplace, Xbone for thesecondplace. You also think the PS4 is better?*grabs popcorn waiting for xbox and ps4 fanboys to start console war*

Never tried Xbox, but PS4's joysticks are just awesome!)

What's a disk, do I download it?

I loved your last round specially that problem about combinatorics !!

What if tourist preferred Xbox than PS4?

what if he already has both from previous contest wins?

I think there should be an option for every winner to take the prize of a beaten one if they wish.

I guess in this case he can make some incorrect hacks or extra submits.

What if he over-mis-hack and fall to rank 3?

Is that why tourist didn't participate?

memes)

can i join if my age is less than 18 (i am in school not university) ?

They will never choose you even if you were 18++.

Why on earth wouldn't you be able to join?

"Note, Wunder Fund is a Russian-speaking company" -- did you noticed that?

Well, technically being an adult and speaking Russian are kind of unrelated skills.

Also, I took 'join' in his comment to mean the joining the round, not the company.

well, if you didn't mean the company, then you were ambiguously so funny.

Russian can be learned — maybe not in big favour today, but there were times when physists, chessmasters (etc) learned Russian just to be able to read Russian books, so why not? If you set such goal and put yourself in correct environment you can get speaking simple Russian within few months. I bet guys in WunderFund would be enthusiastic to help. But first thing to do is probably to reverse the graph. Mirroring across vertical axis would look much better.

Reason is there ,and here

sure！

As div.1 and div.2 combined, I think the contest duration should be increased at least 30 mins to have more time to challenge and solve problems

Легкий рейтинг++ для Div. 2)

Why not Nintendo！？ Though I think it's impossible for me to get one：）

В описание приза есть опечатка, там написано "сувениврные футболки Wunder Fund".

write English

that's right :))

so there's a high probability that dude at rank #51 won't get a t-shirt....

Higher than for rank #600 so I guess it's still optimal to fight for a good place.

What about rooms? Will they also be combined? Please say no!

No. All rooms aren't combined into a huge room :P

I think he meant will div.2 participants can be in same room with div.1 participants.

Exactly!

Please say no!Why?

Hacked is better than failed system tests.

If your solusion doesn't use hashing)

Because there will be more probability of hacking div 2 coder's solution than div 1 coder's solution.

I really hope that Pretests would be strong enough, because it sucks when someone spends half the time working on a hard problem and gets the same position of someone who spent all the time refreshing the room page for new people to hack.

IMO, being able to hack a lot of people has his own merits. Debugging is pretty important in software development, especially video games (look: literally any Ubisoft PC Game).

Hence, I believe that the pretests shouldn't be EXTREMELY weak. Just somewhere between "hacked by a little toddler" and "pretests = systests". Just so that people that are ACTUALLY pretty good at debugging are able to shine, while the regular coders aren't shut down either.

With the exception of hash coders. I hate you guys with passion, you wonderful, gambling luckers!

My comment is based on my experience from the last round. After I solved three tasks, I found hacks, went to my room and started hacking. There were too many people to hack that I didn't even have time to read the fourth and fifth problems properly, although they weren't hard, but I don't regret it because thanks to hacks in the Standings I was among participants who solved 4 problems. I'm just thinking that it would have been much more fun if I spent time solving the rest of the problems rather than refreshing the room.

it will be a rated contest

it's a good rated contest

yeah

rated contest

good rated contest

yeah

The contest is prepared by Lewin ==> the contest is greatfull :D

Good luck!

Hir shodi :D

the comment is written by amsen ==> the comment will get lots of downvotes :D

I believe you guys forgot to send an email announcement.

Nice, I got it right as soon as I posted this comment.

it is midnight again where i am when the contest is supposed to hold which means that i may miss again. i wish everyone who will be in the race could get good marks.*^_^*

oh lots of contests these days !!

ENJOY !

Will the problems be sorted according to difficulty?

It depends on score distribution which will be announced just before contest

why is it so late? I thought it is always at 2pm(GMT)

so combined round and only 2 hours. pretty interesting.

What way you will use to choose random prizes? For example in one of past cf rounds python code posted on the blog and rand seed was id of last submit in contest.

Is the number of problems and duration of the contest finalized?

When you're trying to win

allprizesiam sure nobody can't win all prizes !!! but trying is good :))

I don't want to win Prizes . I just want to Solve Problems .

Gaming?...Why???

Why so much hate for trunghai95? Whatever he comments gets down voted so brutally :p Or, am I gonna get it now? :/

will the rating system be changed (because it's div 1+ div2) or will it stay the same???

6699 registered! Interesting number (=

Indeed.

7 rpoblems and only 2 hours.

CF running slow for me. Not a good sign.

Yeah, another delay... I think it's good sign.

damn. me too

me 2, i've lost 5 minutes to connect to CF.

Why has registration been closed? Please open registration — the competition hasn't even started yet.

Its saying i am not allowed to view the contest.

Random T-Shirt Winners will be determined using the following code (with the help of testlib). We will run the code with the only command line parameter — the points of participant on the place 500 (or total points in case of tie).

====

Случайные обладатели 50 сувенирных футболок будут определены с помощью следующего кода (использует testlib). Код будет запущен с единственным параметром командной строки — количеством баллов у участника на 500-м месте (или суммой по всем таким участникам, если несколько займут 500-е место).

====

This is a fair and effective process. I like it.

I completely forgot about the T-shirts :D. This is an important milestone for me: not caring about prices and competing truly only for competing.

4 people placed 499. 4 * 2614 = 10456.

T-Shirt Random Winners: 498 218 125 86 452 496 145 405 99 412 260 382 449 461 240 131 337 116 210 249 393 488 457 447 266 416 370 386 497 58 197 104 478 165 254 251 374 181 111 307 132 471 360 124 299 229 425 492 63 363

Exactly! Thanks.

MikeMirzayanov, is the above list the final list of winning ranks?

498 AtomRush

218 JavaInTheSouth

125 dragoon

86 alex20030190

452 gangsterveggies

496 NikitaMikhaylov

145 IlyaLos

405 wu6shen

99 teleport

412 Vetand

260 Andrei1998

382 slava.sh

449 wmx16835

461 og.kostya

240 Danlark

131 namai

337 fraud

116 I_love_tigersugar

210 NelsonMondialu

249 BaconLi

393 shubh09

488 avv

457 duyboy135

447 Petruchcho

266 gut

416 KevinTan

370 KArs

386 spentplaying

497 Bayan

58 andrew.volchek

197 kreker

104 Shik

478 saurabhsuniljain

165 Fedosik

254 RostVel

251 luke0201

374 Inspiration

181 __math

111 DamianS

307 xzj1997

132 Tzn-40

471 cchao

360 PrashantM

124 GinghouLuk

299 mirceadino

229 ATofighi

425 FallenTurret

492 andwho

63 Nezzar

363 Morphy

I'm placed 425th too (and so are yukihana0416 + gsa93). Will all 4 of us get a T-Shirt?

I'm placed 393 too.

I am placed 492th too.

But some places are not exist. For example 452(or 500). It's good?

I think you need to have the array holding the handles of users instead of the ranks because many ranks do not exist and many participants share the same rank.

When this happened previously, they gave tshirts to all of them. Link

Today: funny CF handles!

[user:http://codeforces.com/profile/CantGetAnyACWhyAmISoWeak]

Doesn't seem to be true, considering he's somewhere above 60th place now.

CanJustGetSomeACWhyAmISuperWeak

CanJustGetSomeACWhyAmINotTourist

short and nice questions...enjoyed solving :D

At problem D, when X was equal to Y, I printed N * X instead of (N-1) * X. I locked the problem, then I got hacked. Everything else was correct.

if X < Y then answer is X * (vertices in longest path) + Y * (remaining vertices).

Else answer = Y * (vertices — 1)

Is this correct ?

Incorrect.

3 2 1

1 2

1 3

Write answer — 3 (1->2->3)

got it, thanks.

No, if

x<yyou can use multiple paths in the tree. Letmbe the largest number such that there is a set ofmedges which forms a collection of vertex disjoint paths (i.e. no three edges share the same vertex) then the answer ism*x+ (n-m- 1) *y.Conversely, if

y<xthen the graph could be a star, in which case you'd have to use an edge with weightx.yeah got it, thanks!

It depends what you mean by "vertices in longest path". I'd rather said "max total length of set of paths", because it could consists not connected sub-paths.

And it surely wrong for X > Y case. It could be "x + y * (n — 2)".

For X<Y, it fails if you have this:

You can go 1->2->3, then jump to 4 (by a non-tree edge), then 4->5->6.

For X > Y, it fails if you have:

Here it's impossible not to use an edge from the tree.

I got my mistake, any way thanks

I could not pass the 3rd pretest until the last 3 minutes, and realized that I checked long long everywhere except printf("%d"). Could be a crazy fail too :D

But you've found your mistake, I still can't:D

well next time don't add unneeded ifs:)

I bet both solution for y > x and y < x would give right answer for x = y automatically

Imho, 2 hours is not enough for 7 tasks. Besides that, nice tasks :)

You have passed pretests in only three problems) And no one have solved G. But tasks were beautiful, I agree with you

What is the hacking testcase of Problem C ?

For my solution it was: 4 0 0 2 0 1 0 1 2

As I guess, something like this: 4 1 1 2 1 3 1 5 5 But I don't know exactly and I Haven't enough time to hack anyone with this test

Great to see eatmore performing again.

I want to ask for a bit of feedback on my code.

I coded E, a "standard" segtree (rotation angle + translation vector), except it is TLE-ing pretty badly. Could someone try to figure out why, by reading my code? It should be fairly understandable.

http://codeforces.com/contest/618/submission/15662186

Thanks in advance.

Well I know from practice that sin and cos are waaay too slow. Maybe you should have saved them in arrays sin[360], cos[360]? Try it.

I believe this still gets TLE.

Try getting rid of

`cout`

. I do see`sync_with_stdio(0)`

, but on my system changing`cout`

with`printf`

optimizes 2s out of 7s (after cosines are already precalculated), even if I move`<< fixed << setprecision`

out of the loop.This is really weird. In custom test, I designed some test cases for n = m = 3e5, and they got TLE. But now it is working pretty fast when I actually submit. This is confusing to me.

Thanks anyways.

I think it's something about CF running several solutions on the same machine (but different cores). Try asking MikeMirzayanov to investigate if you're absolutely sure that it's CF-related problem.

Okay please tell me how to solve D. I understand that if x<y we need to find the diameter of the tree and the answer will be diameter*x+(n-1-diameter)*y. And if x>=y answer will be (n-1)*y or ((n-2)*y+x). Whats wrong in this?

It's not diameter. Here's a tree.

1 2

1 3

1 4

4 5

4 6

By diameter, I mean maximum distance between any two nodes. Am I wrong in this?

Yes, you are wrong. Look at the above example.

Not a diameter, you need to split the tree into lines such that the sum of lengthes is maximal.

First of all, watch out for

x>yandread the problem statement.n= 1And if

x≤y, we want to split the tree into as few paths as possible. Tree DP.n cannot be 1. (2 ≤ n ≤ 200 000, 1 ≤ x, y ≤ 109)

nis at least 2; read problem statement more carefully.n is >= 2 from problem statement.

I noticed that in case where x > y one should watch for single vertex with degree n-1, as it forces you to use cost x at least once. Maybe I am wrong.

On Tree DP — sorry for silly question — is it possible to split tree in less then (number of leaves — 1) paths? Can you give an example or somewhere to look for it.

It depends what do you mean that path is. For example

6 1 2

1 2

2 3

4 5

5 6

2 5

has 4 leaves, but you can use 4 of its 5 paths (all except 2 5).

Thank you, that was illuminating :) Now I know my mistake.

Got my mistake.

you could add to path not only diameter. Also you could add some more edges from tree.

I'm good at geometry：（ I think Problem C can be solved by PolarAngleSort，but I failed on test4.

In problem C, I find first three points that made a triangle. Then I iterate over all other point, if a point is inside the current triangle, replace any vertex of the triangle with that point; if a point is on an edge of the current triangle, replace any node of that segment with that point.

No need to do polar angle sort, just sort by X (or Y). First two points will be in the answer. Last point will be the first point not on the same line as first two points.

my submission before 5 seconds did not go into submission queue.. T.T

I pressed submit 50 seconds before the end and still failed to submit — looks like it wasn't a good idea. Anyway I don't think my submission was good, so I actually saved 50 points :)

As I understand, you won't be punished for 50 points if it won't pass pretests, only if got AC. Not sure about system testing.

Anyway, it is a usual thing — last 5 minutes of every contest is very dangerous time to submit anything :)

If you are correct, then this is second place where Codeforces is factually incorrect — admins, please fix it!

First place is Help tab in top menu — if you press it and scan through the rules you will see that Div.1 still starts from 1,700+. In both Russian and English version. I reported to Mike, but he was probably too busy.

For submissions penalty — during the contests, this is what text on the right tab says — "you get 50 points penalty for each unsuccessful submission except if it fails on first pretest, etc." — at least in Russian version.

Admins, please fix!!

I'm not sure how it supposed to be, but just checked some older contests and in fact:

1) No penalty for wrong submissions if you haven't got AC for this task

2) No penalty for AC submissions that failed system testing

If it's the penalty of problem AC score and not of total score, it's correct.

I submitted before 10 sec the problem C

It went in the queue but how frustrated I was when i realized I did not erase a misplaced "return 0 ;" that I used when debugging :(

About same case for my Problem D where I forgot to comment out freopen -_-

How to find minimum area triangle in O^2?

I know I will sound stupid, but I couldn't solve Problem A... (I didn't even try the other problems) My final submission was: http://codeforces.com/contest/618/submission/15665677 which seems to do something different than what problem A requests. Why??? What did I get wrong?

You could have just simulated the process in

O(N) . (Look Here)[http://codeforces.com/contest/618/submission/15651613]one silly mistake and rank moved back a 1000 places >_< .

Please don't do this. Either submit a bad solution early, or don't submit a solution at all. That makes us, hack hunters really thirsty...

wow.. it's amazing that the code above could pass pretests

Open questions:

1) is N!=NP ?

2) What is the fastest algorithm for multiplication of two n-digit numbers?

3) Can the rotation distance between two binary trees be computed in polynomial time?

4) Will a day come in future that Codeforces server problems be permanently solved?

Sorry for my ignorance . But isn't it P!=NP ??

Problem C — Time limit exceeded on test 84... :(

I got runtime error in case 87 on problem C, I have absolutely no idea how that could have happened. Here is my submission: 15659929

Seems to me like you sent wrong link.

Oh yeah, my bad. Thanks, I fixed it.

To your quection: in first cycle mejor can be exactly 4 * 10^18. So in this case you will get uninitialized s, and I don't know maximum possible major in second cycle (maybe >= 4 * 10^8 ant in this case you will get unitialized t)

No "return 0;" in main.

Yeah, that is why he he/she passed previous 84 tests:D

It's allowed in C/C++, compiler will treat that as

`return 0;`

. But that's behavior specific for the`main`

function only.It's because of

`mejor=4e18`

. 4·10^{18}is too small "infinity" when looking for the farthest point when are up to 10^{9}by absolute value. So, the`s`

variables is not set after the first loop and behavior afterwards is undefined.A solution to the hard case of D can be found here:

http://www.austms.org.au/Publ/Jamsb/V44P2/pdf/1761.pdf

Why didn't you include at least test with n = 2 and x > y in pretests for D? There are still other corner cases for hacking.

I didn't include any cases where the tree is a star and x > y. For n<=3, the only possible tree is a star.

All problems are very excellent. Thanks to Wunder Fund Company.:)

And thanks to Lewin.

chill bro, it's A and it's not easy to hack this guy. Why would someone try so hard on A?

someone wanted to lose rating...

Wow, so many fails on problem C.

RomaWhite, maybe, is the unluckiest human in the whole world now... 1 point form XBox One :(

Testing is not finished yet, so he could finish on worse place.

When It was 97 percent of testing I thought that nothing can be changed at the top of the table. That was my stupidity. Egor have sent solution when it was 1 hour and 59 minutes. Congratulations to him!

on the other hand, Wunder Fund are lucky because that point avoided the headache to them deciding who will win the Xbox

UPD:now both dropped one place to 3rd and 4th so no one is lucky and no one is unluckyThat was my mistake, I am so sorry for my previous comment. But now Um_nik is in 6 points from XBox One)

And now he won't...(rank 4)

Interesting that this solution that doesn't map the indices passes the tests: http://codeforces.com/contest/618/submission/15664708.

I think you're wrong. Solution requires two arrays of points — input array and sorted array. Answer building by sorted array. And indexes of input array are printed.

You are completely right.

connor: blue, extremely high. His previous results aren't that great. Seems suspicious.

See this one's contests history: xuanhien070594

Take it easy! Just think like, he is better than you. maybe he doesn't always take the contests seriously like you?

A lot of assumptions for an unrated user!

hi~ Sorry About that. Truth to tell, connor is my small id (alternate id)

After ACM-ICPC World Final 2015, I stop using kybconnor in TC & CF. I also stop training after that. but I still enjoy participating algorithm contest. So I bring back connor and Ronnoc.

QwQ

Can I see my ranking considering only div. 2 participants?

Hello guys,can someone please give me any hint on how could i solve problem B? Cheers

I didn't participate but I had this probably bad idea for C : take any point, then take its closest neighboor, and finally take the closest point that is not in line with those two points. So far I didn't see where it fails, can anyone show me where it fails? edit : it works

This is correct, since this third point will be on the line that is parallel to the line that connects the first and the second point and is the closest to this line.

Thanks ! It seemed too simple with all those hacks and red coders weren't so fast for such a simple algorithm. Maybe I would have failed anyways because of int overflow in vectorial product (had this idea late).

As solution it seems correct. But it depends how you implement it — bruteforcing will be O(N^2) and it is TLE.

I solved it a bit differently in O(N):

Find valid triangle: take first two points and iterate for others, first one that is not on the same line = got valid triangle.

Iterate over all other points. Check if point is inside triangle, if so — replace one of old 3 points with new one so we will have valid triangle again.

UPD:In second step more precise description will be: "Check if point is insideor on the edgeof triangle".This solution is wrong when between first two points exist the thrid one and all three are colinear.

Nope it is not.

Maybe I wasn't too clear with description, in second step it is more precise to say that "if point is INSIDE OR ON EDGE of triangle".

All

Npoints are never collinear . It's mentioned in the statement .I thought about O(N log N) : I sort the points by distance from the first point.

I solved it a bit differently from yours in O(N):

The first point in answer is the first point in input data. Then choose closest point to it from others. Then choose closest point to the segment of to points that we already have. Also, this third point mustn't lie on the line made from two already choosed points. Got AC, but your solution, I think, more easy to prove and understand.

i did the same it was accepted , the approach is correct http://codeforces.com/contest/618/submission/15660749

You forget about overflow and you get Wrong answer on test 93 :/

round is rated or unrated ????

It's rated. Look in the first comments. http://codeforces.com/blog/entry/23084?#comment-274938

but rating has not yet been updated

System test still going. If I were you, I wouldn't expect update sooner than in half of an hour)

A lot of test cases and big timeouts (2-8 seconds each). E.g. right now some E solution is running on test case #53 and each could be 8 seconds. And it is only one participant.

Int fu**ked me on test case "93" problem C

Same here ! Submitted C thrice ( once after getting hacked ). All that for a WA because of overflow :(

And congratulations for 51st place to: FatalEagle!

For the past 5 minutes I was watching aropan's submission, hoping that test 67 might be some strong TLE case.

Nonetheless, congrats to aropan for that incredible luck in server timing :)

Edit: Reached IGM for the first time, so this contest is still a success for me!

For the past 5 minutes I was watching aropan's submission too.

Thanks for the congratations.

FatalEagle be like

Somehow I thought that in problem D there is no Hamiltonian path avoiding edges of path on 4 vertices. That is the only testcase my solution fails.

This case wasn't in the system test, but sadly one other competitor in our room made the same mistake and I hacked his solution. As you probably know, successful hacking cases are added to system test.

If I didn't hack him, we would probably both passed :-(

lol

I thought that too. In graph 1->2->3->4 there is not Hamiltonian path if you start from vertex #1, But if you start from 2, 2->4->1->3 is possible path.

I think you did the good thing in that situation. Of course in hindsight you shouldn't have hacked, but in contest you couldn't know how common that bug was (so other people would make these hacks) or that there weren't 4 node test cases. If you were at a harder problem, which few people submitted, then that's another story.

That's why I like TC SRM the most :( no problem for int or long long .

WA at 93th

AC

whatever my logic was right. I should be happy :)

You probably should add after "I will always use scanf and printf", "I will always use at least int64 type" :)

Really almost every contest have int32 overflow in some form. And in many tasks it is present to cut some specific fast algorithms, like counting in array where index = value.

True :) Actually Div 1 & Div 2 combine contest never went good for me. Today i was hoping to break this :p Anyway it was a great contest .

Thank you Lewin :)

What is wrong in this approach for problem C? First i am finding two leftmost points i.e. points with minimum x co-ordinates. Then i check for all other points such that they donot from a line with these two points and r1 ^ 2 + r2 ^ 2 is minimum where r1 and r2 are distances of the point from first and second point.

E.g. if you have 5 points with the same X value you just pick first two, while other three could be inside them. So they will be inside the triangle that you've found.

But in that case, whichever triangle you form will have zero area. That is not valid.

E.g. you have points:

Your algo will pick points 1 2 and 4 as a result. And it is wrong, because point 3 is inside this triangle. Valid answer will be 1 3 4 or 2 3 4.

Thanks for that case. But i am still getting wrong answer. Now i am finding two points with minimum x and if they are equal then i am finding points with minimum y.

I'm not sure, but it is possible there are two triangles (p1 p2 p3) and (p1 p2 p4), where distance from p3 and p4 would be equals and p4 would be inside (p1 p2 p3). But I'm not sure.

Thanks a lot for debugging! :)

I guess the condition r1 ^ 2 + r2 ^ 2 should be minimum was wrong ( I don't know why ). I just changed it to finding third point with minimum value of x and minimum value of y and it got accepted.

didnt debug your code . Just wanted to suggest that finding 2 points with minimum x coord can be done easily by sorting and picking the first two points . Refer this .

Can any body tell me why my approach is wrong for C

sort point by x .

for each 3 consecutive points make sure that their not in the same line ( horizontally or vertically ) if its the case print these 3 points and return .

It was the right idea to solve C . May be Int flow issue was there same as me . btw its not essential that only they will only horizontally or vertically in line . point ( 0 , 0 ) , point( 1 , 1 ) and point( 2 , 2 ) can also form a line .

if you only sort by x , then you could choose 1 point on a vertical line ( P ) and 3 on the next one( P1,P2,P3). In that case, you may choose P , P1 and P3 where P2 is inside of the triangle(on the border). You should sort by y too

It's not enough. For example, points A(0,0), B(1,1) and C(2,2) can't form a triangle, in spite of they don't have the same x or y. You should check that the area of that triangle is 0. If it's not 0, print that 3 points.

Thanks i got AC

The approach is broadly correct. I just implemented it to test: 15667843. However:

it's not enough to sort just by x (or y) coordinate; points that have the same x coordinate should be sorted by y coordinate (x, respectively).

points can be on the same line that is neither horizontal nor vertical; this case should be recognized and skipped.

When the T-shirts will be announced?

Hello...this is my third contest on codeforces. In my first two contests I only solved one question. Today I solved two but my rating decreased! Can somebody explain this to me ? Is it because that this round is a combined round ?

Rating increases if you solved better (more tasks OR equal, but faster) than the participants with the same level (or greater) as you.

And it decreases, if you solved lesser or slower.

So it is not based on the amount of solved tasks itself, but on the comparison on your peers.

The Rating increases does not depend fully on how much problems you have solved in the round. It depends also on the time you have spend solving the problems. Try to solve problems fast.

good contest

Problems with awesome quality. Nice, Lewin. And for me drawings in E were extremely helpful. Thanks for a round.

Hello, what can i do to make my code more efficient? thanks. http://codeforces.com/contest/618/submission/15668412 it's O(nlog) 0.5 seg on test 4

Just use scanf instead of cin ,your code is fine .

you are right! In efficiency,is there a lot of difference between cin and scan? how many milisec?

Difference isn't big but you must write

`ios_base::sync_with_stdio(0)`

when using iostream (cin, cout).Your code using scanf take only 93 ms.

Finally returned my yellow, thanks for the round! And like it if your first submission for problem D was a diameter too!

First idea was diameter, was about to code it, but then looked at the case with 2 large chains and realized that it's something else.

I got Wrong Answer on test 15 in problem C, but when I run it with the same code in my computer, I get a different output. How is it possible?? this is my submission http://codeforces.com/contest/618/submission/15662738

`dmax`

15672460

Thank you, I will be more careful with precision and bounds. By the way, #define double long double ???????? I didn't know that it's possible to do that.

C preprocessor operates with text, nothing more complicated. It doesn't know what the

`double`

is so you can replace that way anything you want.In problem C, my submission gives output 1 1 2 in CF . But, in my pc it gives 1 2 3 . Why is this happening ?

http://codeforces.com/contest/618/submission/15671958

Whenever there are large value such as 10 ^ 9 you should use double constant instead of default float constant. Change 1.0 to 1.0L to get accepted.

Short answer: precision. Your solution with

`long double`

passed 15672148.Long answer: try to avoid floats as much as possible. For example in my solution 15657222 I use fact that you can compare the squares of the distances to determine which is shorter so there is no need to take root. Also I search third point by comparing areas of triangles and they are always N/2, where N is some non-negative integer, so I simply doubled them. Owing to those facts I have only integer operations, no EPS, no precision problems, also faster solution.

I was trying to solve question D. On codeforces it shows runtime error on test case 1 while same code gives correct output in ideone. Here is my ideone solution link. IDEONE

Here is codeforces solution link Codeforces

PLease help.

This line is incorrect:

`height[v] = 1 + dfs(node[v][1].first);`

Arrays and vectors in C/C++ are zero-based, so if

`node[v]`

has size of one, there is a single element here of index zero, not one. That's undefined behavior and you was lucky enough to get a crash instead of spurious wrong answer. I would recommend you to adapt zero-starting arrays instead of trying to enumerate everything starting with ones.For problem C , I am sorting all the points by the distance from origin and then choosing 3 points closest to origin but it seems to be giving WA 4.This idea will fail if three points are colinear but the reason for WA — 4 mentioned by CF judge is triangle is not empty.I am unable to figure out how this idea fails in situation where 3 points found are not colinear. Here is the wrong code http://codeforces.com/contest/618/submission/15677172 .Thanx in advance.

This is a wrong way of comparing longs. Contract for comparison methods in Java is that they return either zero, or something positive, or either negative (depending on relation).

`a - b`

is not ok even for general integers, and here you subtract two`longs`

, get some big result (which may not fit into`int`

) and then truncate it with explicit typecast with data loss. Simply, overflow. You do not have control over sign. Correct way is to use`Integer.compare(a, b)`

or`Long.compare(a, b)`

.Thank You !

Congratulations to winners I'm so happy to them

When will be T-shirts sent?

I have great news!

WunderFund approved additional 43 t-shirts for all participants shared the same winner places!So random t-shirts will be sent to:Finally I'm lucky enough to be randomly selected to win a t-shirt. Thanks! :)

For the first time ever, I have won a T-shirt from a CodeForces contest! Feels great, I hope there will be many more to come. :)

wheeeee

oh~ so sad...

MikeMirzayanov Any updates on T-shirts ? I am from India.

Has anyone received a T-Shirt yet? :)

No for here.

Off-topic: besides Mike pmed me in-site that the Memsql 2.0 Tshirt (which happened 2 years before) is going to be sent, did anyone receive that either?

Do you mean MemSQL 2014 T-shirt? I received this 9 months after the contest :)

MikeMirzayanov has not sent me the package's track info. So maybe the T-shirt has not been sent yet.

Not yet for me.

Not yet.

finally

Not yet received.

Why different people get T-shirts in different colors?

I guess it's the idea of the organizers.

It would be nice if you provide us tracking numbers. Each time I winn a T-shirt I have to call FedEx to confirm the shipment (I don't know why they can't call me :( )