Hi, Codeforces! Happy Valentine's Day. And happy Lunar New Year!

I'm quite honored to invite you to Codeforces Round #462 which will take place at 15:05 MSK on 14 Feb and last for two hours.

The authors are quailty, skywalkert, visitWorld and me. This is our second round here.

The round couldn't have been realized without efforts of KAN and our testers: cyand1317, demon1999. Thanks for your help to the contest. Also, thank MikeMirzayanov for the fantastic Codeforces and Polygon platforms.

The contest will consist of five problems and it is **rated** for both division contestants.

The background of problems will be about Lunar New Year. (Yes... Not Valentine's Day...)

Hope to see you in the contest! Good luck and have fun, wish you a high rating!

We suggest that those who already have Valentine's Day plans should not participate... You can always upsolve a contest, but there is only one Valentine's Day ;)

The scoring distribution will be announced later.

See you in the contest!

UPD: The scoring distribution is:

div1: 500 — **750** — 1500 — **2250** — 2500

div2: 500 — 1000 — 1500 — 2000 — 2500

UPD2: Congratulations to the winners!

### Division 1 :

- Um_nik (solved all problems!)
- Golovanov399
- geniucos
- fateice
- kriii

### Division 2 :

UPD3: The editorial is available now!

Thank you everyone!

Happy Valentine's Day and happy Lunar New Year!

See you next time!

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).Another Goodbye 2017

Thought of not participating at contests for a while but when i saw the nationality of the writers....

An interesting fact:

Feb/14/2018 is the 72th anniversary of the first computer ENIAC.

(So I'm going to spend the Valentine's Day with computers, codes and algorithms QAQ)

16 contests announced. I've never seen more on the future list, keep it like this codef

Good thing there is a contest on Valentine's day! Now I will be solving problems instead of watching porn :)

:D

After valentine's day, probably:

this meme is old, don't use it please

good meme never dies

.

Girlfriend? Not exists. ┑(￣Д ￣)┍

I thought for a second to skip the contest and go out with my GF, but I realized that I don't have one (sad emojis ...)

But have two? :D

But you have a boy friend dont you~~

I don't think your second warning is necessary -- we are on Codeforces, after all :-)

Hope there will not be combinatorics C like in last Tommyr7's last round

AFAIK It's DP.

UPD. It's combinatorics, you are right

Do you think that div2C is too easy or too difficult?

it was like usual div2c

Finally! Something good on 14 feb. ;)

I hope this round will not like that.

Oh like the past rounds when you could get more with A B and hacks than with A-E ?

Overused meme done right :v

Unhopefully for you it was exactly like that.

Ahh,codeforces doing unpaid job for Bajrang dal :| (only indian can understand it)

:D

Sponsored by

I remember what happened in your last contest mate ;) I hope the mistakes are not repeated this time :P :P

Can you call it "Lunar New Year" instead of "Chinese New Year"? This festival is also meaningful for all East Asia countries (Vietnam, Nouth/South Korea, Japan, Taiwan, Hong Kong, ...), not just China. The background of the festival is based on the orbit of the moon (instead of the sun in the normal Julian calendar), then we call it "Lunar New Year". So if you change the phrase, you can support more programmers in Codeforces where there are so many programmers come from the East Asia countries. Thank you.

But the blog poster knows the holiday as "Chinese New Year", and most people know what it is, so I don't see the point. You can call it "Lunar New Year" yourself if you want to.

I'm really sorry about it and I have fixed it now. Thank you for pointing out!

Not safe for political tryhards, especially during New YearPlease no more political tryhards complaining some places being listed as a country, thank you.

Taiwan and Hong Kong are not countries. Please correct it immediately.

But it originates in china, at all. There is not any problems to call it Chinese New Year. You can see it clearly in the problem background.

'

hey

Codeforc always gives new things in a new event. I want a girls friend from this contest for current event in this world :D :D :D :D

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).Again Tommyr7's Round. I like it!

That moment when the round organizer cares more about your romance life than competitive programming!!

This level is off the charts! LOL xD

I think up votes for this post raised so high cos the writer mentioned the line "We suggest that those who already have Valentine's Day plans should not participate... You can always upsolve a contest, but there is only one Valentine's Day ;)" :P ;LOL

Happy Lunar New Year and hope a good contest!

However,dear MikeMirzayanov, why I cannot open the problemset and history contests?

Fixed, check.

Thanks

Obligatory comment: "Hope the problem statements are as short as the announcement"

0v0

That was my joke. Please don't steal it

LSY! Found ya! %%%

lunar new year or.. Chinese new year....We need to stay with parents and extend family..The contest is very suitable for me to avoid doing some new year's work that day:)

Ended, Happy New Year!!!

baobao wwww

hhhhhh, happy new year

Happy new year~ 阖家欢乐~

lol coders having valentines :/

Codeforces is my actual girlfriend

Someone humanise Codeforces-chan

The image is too bigThis contest is my boyfriend so I hope it has a hard D problem

For chinese prople, maybe a New Year wish is better than a hign rating happy_New_Year Happy_New_2018

Wow, that's fantastic, especially for the time of the contest.

Ahh, although for the Valentine's Day.

Gook luck, everyone. And best wishes for everyone in the New Year!

The contest coincides with Slovakia — Russia hockey match...

Fifteen words,fifteen words,fifteen words,fifteen words,fifteen words

You can easily find a girlfriend, but you can hardly find a cf contest early like this(a contest ends before my bed time).

A great contest for single dog(Just a joke) :P

Tommyr7 registered this contest...

`rank++`

...Just a joke, don't be serious~~~

maybe you can enjoy this round with your girlfriend:D

It is clashing with my dinner could you please shift-up contest more later ?)

UPD: Ok, I will eat KFC before contest, no problem )14, 15 and 16th Feb 3 contests back to back.

Give me a good reason why I'm still at home on Valentine's day, because I want to attend Codeforces Round #462

Looking forward to screencasts of people participating in this contest. Preferably with their dates and a glass of wine.

I have my dates already prepared...

ooom ^-^ — — — — — — — - — -

Tommyr7, how to solve div2E?

brute force

Actually, there is a polynomial solution. Note that instead of generating the permutations we can just calculate the determinant of the matrix

Came here to make a comment on how I don't have a girlfriend and codeforces contest is one true love.

Maha Shivratri >= codeforces round > valentine's day :D

Next time, codeforces should do back to back 7 contests, starting from 8 to 14 Feb. So, we can stay motivated. :)

Imagine , your crush made an anonymous CF handle only for you and knocked you in CF to surprise you on valentine day . But you are finding yourself so much closer to solve the problem on your hand that you u can't reply despite seeing it .

How will be that moment . :(

So, finally something for us(single people) :D

Happy Valentine's day, good coding for everyone at the contest Codeforces Round #462 :)

Two consecutive valentine day and also codeforces round on both days! :O (2017, 2018)

I'm grateful to CodeForces and the contest writers for giving me an opportunity to spend such an unforgettable Valentine's day with my beloved codes and algorithms.

Click

friend standingsand you will find who have no girl friend.Woah, 5 contests in a single week! Awesome!!!

Valentines Present by Codeforces.

Four authors and all of them have different colours, interesting coincidence))

...

btw, Valentine's day is every year :D

Pyaar ek dhokha hai, rating badha lo yehi mauka hai :P

sakht comment

Tommy?Tommy!

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).Are the problems shared between both the rounds? If yes, then Div 2 D would be easy than usual if its worth 750 for Div1 participants. Maybe XD

## TO EVERY PEOPLE IN CODEFORCES:

HAPPY VALENTINE'S DAY

HAPPY CHINESE NEW YEAR!

yay! this is my year according to the chinese calendar, and if I'm not mistaken it is also tourist year since we are both born in 1994

## WISH YOU ALL HAVE A GOOD TIME IN THE RATED CONTEST!

hack is stuck. Infinitely loading.. Is this happen occurs only for me?

close, tab and reopen. bug in codeforces platform

only if I knew this situation 1.5hr earlier, I can hack a lot because I started to hack 10 minutes after the contest begin :( Anyway, thanks a lot!

In DIV2 B for the first test case can 04 be a valid answer?

No, i asked that during the contest

Got it! Thanks for all the positively negative responses.

rating predictor is not working

The rating changes from the CF-Predictor Plugin are all 0's. Is this contest rated?

Why

Div2Ais harder thanDiv2B?:(

First problem was prettier than my girlfriend

Negative CF rating. its Valentine's Day cure for not having girlfriend

Div1B got me so much time to understand that answer for case p < k is just p, and I have to hardcode it. Damn it.

Well, I just transform

`p`

into its negative baseI did the same thing, ofcourse, but didn't figure out that it's actually a negative base.

well, at least you did that, i couldn't figure that out. :(

B seems to be standard: "Represent a number in negative base".

Why does such problem exist? It easy to search on gg: https://www.geeksforgeeks.org/convert-number-negative-base-representation/

The main part of the problem is not doing the base representation itself, but figuring out how base representation helps for this problem. For people like me who are not that smart, it takes time for us to figure out that the solution for B is just to represent p in base (-k). Although it may seem trivial for you, I think that the problem is interesting.

for example, for me its not obvious

I agree, but it seems a bit harder to figure out if you don't know that and try to expand the formula given in the statement instead.

What's tc 8 in div1 C?

Well, what I did was, taking points from (-21, -21) to (21, 21). Since you can't take all of them, I magnified the grid by 100*100, and took all lattice points there. And for each point, find in what circles it lies in.

I didn't take into account this case:

3

-1 0 1

1 0 1

0 0 2

the answer seems to be 5.

my error was that it if there is no commmon area among the 3 circles than also it is possible that plane is divided in 8 regions

Oh thanks, made the same mistake :/

I think it looks like

Happy Hackentine day!

Summary in Div2: Codeforces Round #462 (Div.2) a.k.a. Skip C-D and solve E...

(I know, counting all possible cases for E was still a pain, but to me and many others it is still easier than solving C/D).

Anyway, anyone knows about pretest 3 of C? ._.

The subsequence does not have to be contiguous.

What? So that meant I've got it wrong all along...

Feeling like a dumb right now...

Thanks for the support anyway...

A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k.Doesn't this imply sequence has to be contiguous?

No. It's only contigous when p(i) = p(i-1) + 1 (with 1 < i <= k).

Okay makes sense. Was solving in the contest thinking it had to be contiguous :(

Thanks anyway

Guys, remember that -x * -x = +x²

Case for problema A:

3 3

-7 1 5

-7 1 5

The thing in A is not to use your mind -_- just simulate the process with O(N^3)

after months of participating in codeforces contests i ve come to the conclusion that the problems are generally trash with weak pretests and badly translated statements , written by sad weeaboos calling themselves programmers and problem setters so i will leave forever this site here is my passowrd : codeforcesistrash . bye

I made sure you will not participate again, at least with this account :)

by the way can you change the email thx bye again

btw u werent supposed to change the password so that anyone can come visit my account i will send ticket to email noob

You are like a girlfriend that you are breaking up with, and she like "I'm leaving and never will write you again" and then writes you like 9000 messages about how she hates you and how she won't ever write you again. Just leave, omg, nobody gives a shit.

you are autistic lol

you are just mad i was the first to steal his account lol

I did not know we can change email-id on CF.. Try now?

gut danke

I expect a lot of hacks at div1C, I wouldn't like to see more such tasks in future :

Some participants had finished codes

there is a lot of cases + geometry — more 5h ACM style

Other tasks were great to me.

in problem D Div 2 are polynomial always exist

Yes, substitute x=-k into the polynomial and you will find that f(x)=q(x)*(-k+k)+p=p. Thus, the coefficients of f(x) are just the base (-k) representation of p, and the coefficients will always be smaller than k since it's base k.

Task C div1 / E div2 looks as easy version of one task from Timus.

i hated this contest : - unclear statements - a lot of math tasks - a lot of hacks ( which i don't like personally ) - uninteresting tasks

Thank you for trying and please don't do it again

Agree with

bad English statementsIs this true?

For Div2D, notice that although decimal coefficients are allowed for q(x), in no solution will q(x) have a decimal coefficient (??)

Proof: Suppose some coefficient a_k is a decimal number. Then x*a_k will leave a decimal residue, to remove which you will need another decimal coeffcient for q(x). This cycle will never end.

in g(x) all coefficients are integer.

f(x) = (x+k)(g_{0}x^{0}+ ... +g_{m}x^{m}) +pSo

f_{0}=kg_{0}+p;f_{1}=kg_{1}+g_{0};...f_{m + 1}=g_{m}Since

f_{m + 1}must be integer,g_{m}is integer to. And allg_{i}integer.I am surprised to see a lot of C++ submission for B. It seemed that people would rather implementing big number than writing this problem in a different language.

For C, what is the easiest (fastest to implement) method to find intersection of two circles? My idea is to divided the grid into

k^{2}point, and for each point find the set of circles that this point is in (represented by a bitmask), and then the answer is the number of distinct bitmask. It seemed that settingk= 2000 is not enough (higherkwill not run in time). So I thought about considering each circle center and points near the intersection of any two circles, and got stuck and the intersection thing.https://e-maxx-eng.appspot.com/geometry/circle-circle-intersection.html

i tried this too but had a case i forgot to handle. There maybe more than one (at most 2) region with the mask 0 (point out of every circle). One region is when all three circle touch each other

bitmask is wrong. Two point have the same bitmask can be in different region.

I had a specific case that bitmask is wrong, but only with the "outside of all 3 circle" bitmask. I couldn't find any other case.

one more: Two circle insect inside a large circle.

It seemed that one really had to implement the 100 case-handling solution.

My div2B has been hacked twice,because I regarded the parameter as 34 & 38.I really want to cry.

In the last moment before submitting I changed 36 to 34. Locked the solution briefly after. The next moment I realized I'm f***ed. The right thing to do was to hack myself, but I lost that opportunity.

Sad story.

can you really hack yourself?

I have read somewhere in the comments that it is possible. Haven't tried though.

I thought 1e18 had 18 digits -_-

Me too.

What is the easiest solution for div1 C?

Euler's formula.

What's the value of V and E in Euler's formula if there is only one circle (or two circles not intersecting with each other)?

You can think of a single circle as a vertex with an edge to itself, or 2 vertices with 2 edges between them. In any way, it has

V=E.But if

V=E, fromR+V-E= 2 we haveR= 2. This is correct when there is only 1 circle, but it's incorrect when there are 2 circles not intersecting with each other (Rshould be 3).Euler's formula works for connected graphs only.

Euler's formula is

V-E+F-C= 1, whereVis number of vertices,Eis number of edges,Fis number of faces,Cis number of connected components.Very nice contest for

DIV.2! All 5 problems are solvable, and many hacks on A, B. I was late to contest half an hour, but hopefully nobody was checking for hacks on B until that time.Div2E: Can any one сonfirm that there is no such test in pretests?

Answer should be 4

Contest time was too dificult for me to participate, because it was 7:05 AM in my country, toooooo early ;-(, I was in REM 27 at that time. I think contests need to be scheduled in an hour more accesible to all the world.

Problem E Div2 / C Div1: Is there any tricky cases other than this one:

Answer should be 7

For me every case is tricky :D

For example all three circles have one different common point, or two circles are inside the third one.

I lost 1200 points in the last 20 minutes. Maybe i will never be able to participate Div.1. QAQ

Don't lose heart, welcome to fight together to get a purple name :D

Thanks~n(*≧▽≦*)n

Anyone else thought the subsequences in div2 C had to be contiguous? I should really start reading statements more carefully...

I feel your pain :>

wasted 40 minutes on this too. you are not alone :)

Thank god i'm not alone :D :D

In div2 B for k=39 answer can be 000888888888888888888 is it right?

There shouldn't have any leading zero.

but my answer is positive and has 39 loops

But that is not a correct digits' decimal representation,right?

maybe

yes u are right else i can just print k 0's

However,k 0's is not a positive number:D

i mean k-1 0's and 4

Yes,I understand:D

by the way Happy New Year

Happy New Year for you too.

Why cannot I understand Div.2 D(Div.1 B)......

It seems that there isn't any requirement on

q(x), but ifq(x) has infinite number of coefficients(in other words ), then it looks like there always exists aq(x) whateverf(x) is.(I took

f(x) =xfor example and it didn't seem wrong)So how to explain that? Or am I really wrong?

Polynomial always have limited number of coefficients, that's the point. Polynomial with infinitive number of coeff. calls sequence.

Oh, I see......

It's likely that I'm misled by the paper of matthew99(in fact it's I that treat polynomial as sequence)

Thanks a lot.

Why if we need 1 loop in problem B, '0' gets WA, and Accepted on pretests with '6'.

the output should be >0

The problem requires print a possible integer, zero is not negative and not possible. Therefore, zero is Wrong

Oh, Thanks.

Div 1 C is the worst problem that can be proposed for a cf round, not only it can be found in various sources but also it only requires to just check some cases instead of the general case. D and E are good on the other side...

But I definitely agree that copying task from Timus is bad.

When you need to analyse cases in a general problem it's good but when in a particular case I don't think it deserves to be C.

Also, it isn't only on timus...

This problem is prepared by me and I must apologize that this problem coincide with some problem elsewhere.

I came up with this idea these days and found it hard to discuss all the cases even if

n= 3. So I think it is interesting to leave it as a problem with some hacks, instead of a problem in general case (seems luckily that I haven't did so). However, none of us writers or tester realized that this problem is a special case for an original problem.When I saw you passed this problem in 3 mins, I knew things go wrong but can do nothing. But I am still so sorry for that.

Actually you do not need to worry about it :) It is important only for 30-40 users, for all others that is not big deal ( it is true that is the 40 users with highest rating, but still it is not so big disaster ).

Hope to see more your rounds !

Well... thanks for your approval. But for me it is really an issue, which makes me feel upset instead of delighted for such an interesting(?) task. It seems that my hard works, especially generating some tricky cases by hand, for this problem are in vain.

But... It's harmful for other participants. Because it's just after two very simple problems, a lot of people solved A and B in about twenty or thirty minutes.

You see, div.1 D is super easy to code, and not difficult to think(just a few sigmas). But when I saw a lot of people passing C in 5 min(even 2), I spent one and half an hour thinking problem C. So I don't think it's good to make this round completely rated. Maybe unrated or semi-rated is a good choice?

As you can see, all of us writers and tester didn't notice that. I must admit that it is also a part of ability to realize the original problem. Making this round unrated or semi-rated will be unfair to those who solved the problem by copy-pasting.

At least you did good job with testcases ! More than 100 solutions got WA at final testing, also div 1 users got chance for hacking something during the contest.

Still I do not like task :P But I do not think you done so bad job !

Not only for reds, for example 6 people from my country solved it without even knowing the solution (the judge from the link above has public codes). I don't want to blame the author, it's just that codeforces needs testers from different regions.

I wrote first that I do not like task, so I am completely agree with you !

But I want to say I saw a lot of worse contests in last year than this one :)

What do you have on the following test for d1C?

6

Are there anybody who solved D without expanding the formula?

It's so funny when people who get high places are the ones who actually manage to quickly copy their sources off of other online judges to submit in this round. No hate.

The gift from TeacherQ has receivedQwQ

In div2 C, what does it means to reverse the subsegment? flip all 1 to 2 and 2 to 1 or std::reverse(l, r)?

In my opinion it's probably the latter.

It's first i.e flip all 1 to 2 and 2 to 1.

No. It's reverse.

sorry then, I misunderstood.

I made a typo and still passed pretests for problem A div2

Pretests are always too weak...

exactly the same typo for me, too. So I wasn't the only one who failed systest with bruteforce solution

not a standard contest at all!!!

I have received teacherQ's new year gifts.

At contest

![ ]()

Codeforces community

I enjoyed this contest so much that now I suggest to introduce new contest type. The main goal is to find out, where you saw such problems and then use copy-paste technic to solve them.

I know C today is bad, but come on, other problem is not that terrible.

Ok, you are right, however it doesn't change the fact that even one bad problem can ruin the whole contest, and so the problem C did today.

Div2. A and maybe B were terribble!

if u can't solve a problem it doesn't mean that it's terrible or something ...

and if u solved some problems doesn't mean that they're not terrible:)...

you can just compare these problems with some other contests to understand my talking...

I don't have any problem with div 2 A or B ... :)

what was your problem with them which made you say there are terrible ?! ;)

they're ridiculous problems, and both were just implementation problems and have nothing to think about

getting point from this kind of problems in the contest's needs high precision and chance!

I'm not agree with u,

A good competitive programmer should be able to solve any kind of problems in contests ;)

you can't find any comment from top coders like

tourist or ... that saying some problem is terrible or something else ...

work on your coding skills and don't complain with others :)

yes exercising is so important but i don't waste my time to solve A , B problems that have nothing to teach me...

any way these problems were terrible ;)

So your solution from Timus is wrong or what? :)

I just wrote another one((

BTW, there already exist contests of that type. SnarkNews [season] Series, for example.

I miss when pretests' sole purpose was to decrease the load on the servers during the contest. Now it's just some additional hidden samples.

Why is CF-Predictor not working?

My friends (and I) with Div2E/Div1C...

Hope that the editorial for this problem will be something genius...

genius

Did anybody manage to pass this using Monte Carlo sampling and DFS?

Probably not. Some of the testcases have an extremely small part, with an area less than 1e-6.

upd: It's testcase 113, here is the plot -->`http://www.wolframalpha.com/input/?i=plot+(x%2B4)%5E2%2B(y%2B2)%5E2%3D81,(x-8)%5E2%2B(y-4)%5E2%3D81,(x%2B10)%5E2%2B(y-10)%5E2%3D100`

`http://www.wolframalpha.com/input/?i=plot+(((x%2B4)%5E2%2B(y%2B2)%5E2%3D81,(x-8)%5E2%2B(y-4)%5E2%3D81,(x%2B10)%5E2%2B(y-10)%5E2%3D100),(-0.69%3Cx%3C-0.68,6.36%3Cy%3C6.37))`

I'm still not getting it. I know the theorem, but how to set it up with a plot full of circles? (and to top it all off, many curves between two points may be formed)

what if i solved and proved it 7 years ago?

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).What is the solution for Div2C?

i solved using dynamic programming.

Could you please explain your solution?

My approach for Div2C:

It is easy to identify that, all the possible non-decreasing subsequences will be one of the following type:

1. Starting with 1 and ending with 1

2. Starting with 1 and ending with 2

3. Starting with 2 and ending with 2.

Now for each pair (

i,j), we want to find the length of each type of non-decreasing subsequence and we can keep the length of the largest.We have two arrays,

dp[i][j][k] storing size of largest non-decreasing subsequence of each type [k], in subarray [i...j] andreverse_dp[i][j][k] for reversed [i...j].k= 0 stores maximum subsequence of type 1,k= 1 stores maximum subsequence of type 2 andk= 2 stores maximum subsequence of type 3.Similarly we can store data for reverse subarrays.

Now, we want to find answer when we are reversing subarray [

l...r]. We break this array in three parts [0...l- 1], reverse of [l...r], [r+ 1...n- 1].We can form each type of subsequence by given data.

Type two subsequence can be formeb by..

[Type 1] + [Type 1] + [Type 2]

[Type 1] + [Type 2] + [Type 3]

[Type 1] + [Type 3] + [Type 3]

[Type 2] + [Type 3] + [Type 3]

We can calculate size of these subsequences by using

dpand thereverse_dp.This is the link to my solution.

[Type1] + [Type2] + [Type2],

I don't think this would be there. All the possible options can be —

[Type1] + [Type1] + [Type1]

[Type1] + [Type1] + [Type2]

[Type1] + [Type2] + [Type3]

[Type1] + [Type3] + [Type3]

[Type2] + [Type3] + [Type3]

[Type3] + [Type3] + [Type3]

Oh, yes. You are right. Thanks for the correction.

@sak3t can you please elaborate this part little more?

In the last

forloop, we are taking subarrayA[i...j], and we are finding length of largest subsequence of each type inA[0...l- 1], reverse ofA[l...r] andA[r+ 1...n- 1]a0,a1,a2 store length of largest [Type 1] subsequence, [Type 2] subsequence and [Type 3] subsequence respectively forA[0...l- 1].Similarly,

b0,b1 andb2 store length of each kind of subsequence in reverse ofA[l...r].Similarly for

A[r+ 1...n- 1], inc0,c1,c2Now we want to calculate maximum length of each type of subsequence in

d0,d1,d2 inA[0...l- 1] +reverse(A[l...r]) +A[r+ 1...n- 1].We can create [Type 1] and [Type 2] subsequence easily. Look at the explanation above for how to calculate

d1, and then we take the maximum of these three length.thank you very much.

The same idea is giving me TLE in java. Don't know why. Here is my submission.

Can anybody tell me what's wrong with my solution of PROBLEM A

You set initial values for fans and ans too big. Long long in C++ can only hold up to (approx.) +-9e18.

That won't be an issue.

Yeah, the declaration of array size is wrong. But still, the wrong initialization values for those variables I think would lead to Wrong Answer, though.

You're right, there may be integer overflow. But in this case, the code passed.

I see, the constants are implicitly converted to the max/min value of long long.

That was indeed the issue! Thanks

Here :Array

bshould have been declared with sizem+1Well...I have to say that it's a round full of FST....

I didn't realized that there was a round here until when the round had run for 30 min..

Then I tried but failed on A,then solved B immediately...

It's not difficult to know how to solve C,but I coded for almost an hour...

Before system test, I was #200+ but became #50 after system test..TAT

I have to say that it's an excellent round.

Finally, Happy Lunar New Year to all the Chinese players!

what is FST?

The short form of "Failed System Test" in China :).

Div.2 D: Anyone here used Bezout polynomial remainder theorem?

P/s: In the last 45 minutes, although I knew we have to build f(-k) = p, but I couldn't implement it :'(

gimme privilege to write editorial for Div1C/Div2E: http://codeforces.com/group/qo1icaI3vI/blog/entry/1205?#comment-367474

you can also copy the code and paste exactly from gym with coach mode (sorry div2 poor you)

plz provide editorial

I have to say, this wasn't a nice cf round. It's understandable that pretests in Educational rounds are weak, because those problems are a little bit easier and the main purpose of that kind of rounds is the hacking phase. But making such weak pretests in a normal cf round? Why? I love this kind of contests, but this one is the exception...

in question A;

INPUT 3 3 -3 -2 -1 -2 0 1

Output: -2

Answer: 4

why not answer is 6 ? it is the maximum

Tommy hides

-3so the answer is -2 * -2 if Tommy hides another number , Banban will get -2 * -3 which is larger than 4Love such rounds with a lot of hacks :-) the best present for Valentine's day. :roffle!

Hey guys,

Please can anybody tell me the correct answer for input of problem A Div1:

200

2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 1 1 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 2 2

thank you!

The answer is 116.

I did not notice it is non-continuous subsequence :(

How to solve Div.1 A in O(n)?

You can do a dp using current element, value of last, and the current state (non decresing, non incresing and non decresing again) [n][2][3]. This part that we'll reverse is the part that we consider non incresing

Thanks a lot.

codeforces problem is like you can do both hack and AC..

can someone please help me with my code for DIv2C : https://ideone.com/Nd1oiy

It's an O(N^2) solution but it gives me TLE on test 11!

Edit : please don't mind. I am thinking totally wrong.

Its not O(N^2). You call rev() function into two for loops and every time you call a for loop in rev(). That means 3-nested loops. So its O(N^3)

Your solution is not

O(n^{2}), it goes toO(n^{3}) as for each pair (i,j) you are swapping times. So each pair will beO(n^{2}) and for this you are going at max on average n/4 times, henceO(n^{3}). Correct me if I am wrong.oh sorry! Please don't mind.

For Div. 2 D, I could reach the conclusion that

pmust be in the form ofa_{0}-a_{1}*k+a_{2}*k^{2}-a_{3}*k^{3}..... + ( - 1)^{n}*a_{n}*k^{n}How do I move ahead from this conclusion? Is there a theorem or property that I am missing? Please guide. Thanks.

Now you are trying to represent p as a base (-k) integer.

Seems like I need to go back and revise basics of number theory. I had no clue that a number can be written in (-k) base. >_<. Thanks anyway.

The reason why I don't need a valentine. :P

Codeforces is already my <3

Congratulations. :P

Great hacking today!

Thanks and sorry.. :)

rating is a measure of happiness for you? poor man..

Failed 1C due to the floating point precision error...

Can someone explain why my solution for Div2A failed on testcase 10 35279033

My solution is :

1-Sorting both arrays ascendant

2-check if the last element in Big Banban's array is positive

then i will check for the element tommy[n-2] if its negative answer will be

`cout << '-' << (ll) (abs(x[n - 2]) * (ll) z[m - 1]);`

if it positive answer will be

`cout << (ll) (x[n - 2] * (ll) z[m - 1]);`

and same as if Big Banban is negative

In testcase 10 Tommy has 50 negative numbers and Banban has 50 positive numbers.

so Banbans strat is to pick numbers with lowest absolute value, because product is guaranteered to be negative

but you pick the num with largest abs from Banban's numbers

p.s. by the way, this problem is relatively complex until you make a key observation: the input set is so small that you can just brute force all the combinations

Yea thanks i got it.

Good Time For All!

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).Thanks to your fantastic tasks, I could finally go into a new year with a new rating and a new color.