Hi!

I’d like to invite you to Codeforces Round #431 which takes place at 16:35 MSK on 1 September. Please note that the timing is again unusual.

One of the problems is created by adedalic and KAN, while the others are authored by me. This is my second round here, and it couldn’t have been realized without efforts of: AlexFetisov, ifsmirnov, Tommyr7, winger and wu_qing who tested the problems; KAN who appears to be a meticulous guide throughout the preparation process; and MikeMirzayanov with the supercalifragilisticexpialidocious Codeforces and Polygon platforms — my deep gratitude to you!

Both divisions are welcomed as **rated** contestants and will have **five problems** to solve in **two hours**. The scoring will be announced later.

Once upon a time, in a virtual galaxy far, far away, there was a lovely young singer by the name of Hatsune Miku. One lovely day, Miku got a job as a vocalist in Vocaloid, and that was very exciting. People said, “Oh, Miku, you sing so accurately! And so emotive, too!” Soon everyone was talking about Miku, and there were songs and paintings and even lives for Miku. Miku liked that.

And you, are to start a journey following the emotions in Miku’s voice. Oh, by the way, a late Happy Birthday to her — August 31 is (was) her tenth anniversary.

See you then, and wish everyone few bugs and fair ratings.

**UPD 1** Scoring will be:

**500-1000-1500-2000-2500**for Division 2;**500-1000-1750-1750-2500**for Division 1.

**UPD 2** System test is done. Congratulations to the winners!

### Division 1

### Division 2

- lmmortalCO (solved all problems!)
- ltg2030
- FoolMike
- HatsuneMiku
- MisakaKuma

Also, thanks to all who participated! Nicely done!

Check out the editorial with hints!

**UPD 3** Complete tutorials and behind-the-scene fragments are out. Problem packages may be published soon, stay tuned!

Miku? I'm in!!

Miku? I'm DEFINATELY in!!

Bad luck. Solution for A and C was correct. If these two got rated then.... Alas! they got skipped.

want some downvotes, just ask is it rated? Just see my downvotes.

I upvoted you bro....now see my downvotes!

"supercalifragilisticexpialidocious" what ? :|

It means "extremely wonderful". :)

It's supercalifragilisticexpialidocious

Even though the sound of it is something quite atrocious

If you say it loud enough, you'll always sound precocious

Supercalifragilisticexpialidocious :)

https://www.youtube.com/watch?v=tRFHXMQP-QU

There's a Linkin Park song too!

oh, supercalifragilisticexpialidocious, I finally know how to pronounce this word

Two Faced Lovers <3. Tell your World <3. Miku Hatsune <3. Rated Div 1 contest <3.

I am new to codeforces... So can i join the contest? Because its asking for ratings...

Yes, you should register in Div2 contest. However, you should not ask if the contest is rated unless you want to get -2137 contribution.

I just realised Hatsune Miku literally means first sound from the future.

0w0

I as well would like to know in the fullist if this contest on the code force will count towards my codeforce rating on the codeforces.com webite on the internet on the wires that are inside the tubes that the internet is made of.

[deleted]

Happy Eid for you all :D

Probably the best english I've read in a long time on CF, hope the problems will be as easy to read as the announcement :D

6:35 AM? Seriously? Gonna participate it for Miku Hope this round will not be a typical China round :P

bilibili (゜-゜)つロ che.... Oh wait wrong platform.

"Soon everyone was talking about Miku, and there were songs and paintings and

even lives for Miku.I'm sorry, what?

Have I missed the weekly sacrifice? I thought it was called off.

I think Miku will hire all the participants and solve her problems.But If she hire me and I solve any problem of her,In return, I will ask her to sing a song for me. So, I need her address and a spaceship. Wait, a spaceship will be slower. No problem, I will ask Mr.Tesla to build a inter_galaxy_traveler for me. For this Mr.Tesla will hire all the participants to help him build a inter_galaxy_traveler. Miku, you may live far, far away but no one except God will/can stop me to hear your sweet voice. Miku, You just have to wait for the payment untill I become an expert. I promice you it won't be long.

My birthday.Oh yeah! I'll be glad to with you in codeforces.>w<

Winner Winder Dinner Chicken

Hope for good quality problems :)

Codeforces with Miku is so good!I will be definitely in!!!(Although I 'm so weak...)

Happy birthday to HatsuneMiku! =w=

Am I the only one who doesn't know about Hastune Miku?

Are you serious? ._.

Well he/she may be a famous person in your country but I really had never heard this name before.

You can serach her name in niconico or bilibili douga(douga is a website with many acg cultural videos).

You can read more in Wikipedia, but feel free just to enjoy the problems without such background knowledge.

before your comment I was thinking I'm the only one.

I like Miku~It must be an interesting contest!

Please don't use these hard names in problems please. It makes difficult to understand also is it rated?

Eager to participate after a long time -> See Miku in the blog -> Decided to go to sleep instead.

Awesome feature of showing

rating changein leader-board during the contest.i hope there won't be long stories about Miku in the statements..

There won't, enjoy :)

I know a sentence to get lots of downvotes,but I will not say

You just did.

It's out of my expectation

Happy birthday, Hatsune Miku! Thank you for bringing so many wonderful songs to us!

Codeforces means nothing, Miku means everything.

Give me 50$ or I will tell Cristina what you said

Give me 50$ or I will tell reality what you said

bilibili (゜-゜)つロ chess!!!Happy birthday Hatsune Miku!!!

Buy

Baby Products_Your text to link here..._ Online India at Best Prices.Last line of the blog : "wish everyone

few bugsand fair ratings." :(Good news for hacker :(

"few" means "not a lot", "a few" means "some", so in fact wishing few bugs is wishing well, while wishing a few bugs is wishing bad.

I am getting error : 502 bad gateway..

If it is problem of the site please check it so that it wont effect the competition.

Happy Coding!

Hope this round be rated!

Hope this contest goes well!

Another anime-contest?) This year have many anime-contests)

Maybe next year will have >= contests with anime theme? Does someone else want it? :)

Good luck everyone! 502 will not stop us!

Please, don't start the contest till you fix the problem

502 Bad GatewayI am not sure, but looks like it was fixed(I tried refreshing 20 times).

Now the issue will return because everyone who will read your comment will try to refresh 20 times :D

This is not how you check it :)

They need to look at nginx access.log.

How can we see those logs? I think a only admins can see them.

Eid Mubarak to everyone :-)

Hope, 502 Bad Gateway don't appear during contests!

Scoring?

Miku~

And the count down starts...10, 9, 8, 7,...0

a

let it begins

Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).Not able to hack ..... page is stuck at reloading again and again...

This is experienced by some contestants. We're working on this, please go on to other problems first. Sorry for the issue.

same issue here, and i am 90% sure i can't solve any of the other problems. also i am 100% sure the code i am trying to hack is incorrect. :-(

EDIT: after refreshing about 20 times, i was able to successfully hack the above mentioned code. :-)There are no memes in the comment section?

spits coffeeso after forty minutes i didnt solve problem a or problem b

i give up :( i should stop doing cp

This contest looks to be difficult

Welp,not only you, this contest difficulty gap seemed kinda much for Div2 contest..

Is was contest rate plz I need now teechr will fail my?\

Moderator I hacked the solution of user — "redcpp". verdict is saying unsuccessful but in his logs its written that his solution is hacked by me. Update marks.

This happened to me in contest 429. Nothing came of it.

Titles are all Hatsune Miku songs~

Currently 22 minutes left until the end of the contest, and I have been trying to hack one of roommate's codes for the last 5 minutes (with this error).

EDIT: I was eventually able to (successfully) hack this code, however I couldn't hack the (incorrect) code of another participant due to this error. And after repeatedly refreshing the page I saw that the participant had resubmitted a correct code (without being hacked by anybody else).Div. 2 + Div. 1 round? More like Div. 1 + Div. 0 round. RIP Rating.

I also think so, I couldn't even understand statements of c, d and skipped to E(Hope it passes though, or I will get -200 rating change).

Ima get -100 at least for sure. E looks like a problem I can solve, but I just didn't read it. Now I have only A :(

Pretest 3 on C is k = 0.

Your code prints nothing but it should print a single character :(

Oh yeah. I guess this isn't my day :( If I found that bug I would've solved it in the first 30 minutes.

rip rating too , hate geometry so much :C

How to solve div2 d?

sort

sort what?

for horizontal , consider the point to be at ( -

t_{i},y_{i})for vertical , consider the point to be at (

x_{i}, -t_{i})Now consider each diagonal (Same

x+y) at a timeOnly points among the same diagonal will collide and each point's direction will alternate after each collision.

Thank you for kind explanation. Thanks so much.

Such a great observation!!! Thank you so much

thx

First notice that instead of looking at time the person starts, you can simply set their x/y coordinate to -t (depending on what way the person is facing). Then notice that instead of imitating a collision, you can just swap the indexes of the people colliding, since they just swap trajectories. Then also notice, that you can place people in buckets based on the sum of their x and y coordinate (people with the same x+y go into the same bucket). In those buckets, every vertical person will collide with every horizontal person, and vice versa. Now, next thing to notice is that every horizontal person will hit vertical people in the order of their x coordinate. Therefore, the last index that carries that trajectory will be the index of the furthest right vertical person. Yes, there's a lot of noticing in this task. At this point you could probably implement it, but there are a few more things to notice if you want to have a nice, clean implementation, but I don't know how to explain what I did, so I'll leave it as practice (if someone really wants to I can try to explain)

Also, cyand1317, I absolutely loved this task, thanks!

Edit: while I typed this someone already answered. I hope this will still be helpful to someone!

Thanks for the explanation, for me it's much easier to grasp than official editorial. Only last step (how to properly sort dancers and final points, then match them) is to be applied to your solution to get ACC. It's described in editorial, but if you don't mind I will explain it here to finish your solution.

If you sort all dancers in one bucket wrt their initial x positions (for horizontal dancers it will be -t_i, and x_i for vertical ones), and sort all final points for this bucket in order (0, h)->(w, h)->(w, 0), you may realize the next thing:

The same logic could be applied to the next dancers... Just imagine the picture and you will get the idea.

I hope this would be helpful for someone who doesn't want to spend 5 hours on this problem:)

My submission.

Thanks for completing my comment, here's my submission too, if someone's interested: 29986966

Supercalifragilisticexpialidocious problem C. (E div 2). Thanks >__<

The first time getting rank 25 in div.2

:)Happy

Well, wasted too much time on D.

I think this guy is cheating

? Why?

Did anyone pass problem DIV1 C with Mo algorithm working in O(n^(5/3))?

Btw by n^(5/3) I mean this optimization : http://codeforces.com/blog/entry/44711?#comment-292040

i got tle with something like n*sqrt*log lol. used sqrt decomp on queries

But n^(5/3) is less than n*sqrt*log...

My N*sqrt*log passed in 5912ms ._. (which most likely means that it's gonna fail systest anyway)

In theory, n^(5/3) is more :P

;_;

Nice idea, I see what you did there.

Yes 29985009

How to solve div1B? I feel so stupid

Suppose a dancer travelling vertically having

position Xiandwait time Wi, and a dancer travelling horizontally havingposition Yjandwait time Wjmeet attime T. Hence,(

Wi+T) =Yjand (Wj+T) =XiThis will be used to check collision condition and time.

(

Xi-Wi) = (Yj-Wj) andT= (Xi+Wj)Now, sort dancers travelling vertically by

Xiand dancers travelling horizontally byWj. Store dancer indices for eachdistinct difference(Xi-Wi) and (Yj-Wj) for each type of travellers.For one particular difference, consider 2 vectors, 1 of horizontal travellers and 1 of vertical travellers, each element of 1st vector will intersect with each element of 2nd vector. Final positions of dancers from these 2 vector will just

interchange among themselves independent of other dancers.Collision happens in

sequential order. That isifrom vector 1 will intersect withj1 andj2 from vector 2 in order ofj1 andj2, same holds other way.This sequential order can be used to decide final position of each traveller of these 2 vectors combined in

O(n). You just need to traverse these 2 vectors in particular order. Sorting the travellers takesO(n*log(n)) time.Code

Don't, it was pretty hard (IMO).

You can group the people, so in one group all possible collisions happen, and no collision happens between groups. You have to group by

p_{i}-t_{i}. The previous statements can be proved, for same and differentp_{i}-t_{i}s. After that, you can solve the problem for one person inO(1). I'll leave that thinking to you :)How to solve div1C?

Let's change find sum of max-min into sum of nxti-i where nxti is next element with value equal ai and nxti <= r. Now it's a very standart problem, I did it with bit and sqrt decomposition

I came up with this, but you need to subtract the values on the first apparition of an element, how to do that? I'm shit at data structures :P

Actually, only 2 or 3 values will get changed, so you can update it easily.

Nvm I missunderstood your comment, now i get it, thx :D

I am surprised that I found

Div-2 Cpretty hard, but still more than 1000 participants solved it. Looking forward to the solution.a => 0 aa => 1 aaa => 3 aaaa => 6 ... a(n) => (n)*(n+1)/2

16 = 10 + 6 => aaaaa bbbb 12 = 10 + 1 + 1 => aaaaa bb cc

Although I cannot assure this is the right solution, I pass pretest in this way.

Here is the proof that this approach is indeed correct. Firstly, breaking the given sum into characters, it is evident that we can compute the cost of merging characters of one type, and sum across all characters at the end.

Now, we claim that in order to merge

nof one character, the cost required is always regardless of how we merge. We prove this by strong induction onn, the base case being obvious.Now if the last merge is merging a string of length

xwith a string with lengthy, by induction hypothesis we get that the cost so far is Now the last merge itself costsxyso the total cost becomes as claimed.Nice proof! What is the name of this identity?

I don't think it really has a name, but I guess it's a special case of Vandermonde's Identity where

r= 2.First, we'll find the minimum accumulative cost of a string. In fact, we will prove something more: the accumulative cost of a string doesn't depend on the order they are combined.

Imagine that between every pair of identical letters, we have a

tune. Thus for example, in the example string`abababab`

, each pair of`a`

's have a tune between them, and so as each pair of`b`

's. That's a total of 12 tunes. We claim that the accumulative cost is simply the sum of all tunes.To do so, we will remove a tune at the moment that the pair of letters are merged into the same string. For example, when we merge

`aba`

and`ac`

, the two pairs of`a`

's (pick either`a`

in`aba`

, and pick the`a`

in`ac`

) will lose their tunes (the pair of`a`

's formed by taking both`a`

's in`aba`

has already lost its tune). It's obvious that each tune is removed exactly once, since at the beginning no letter is in a string with any other letter, and at the end every letter is in the same string. It remains to show that each tune does contribute exactly 1 to the accumulative cost.Consider

f(s,c) ×f(t,c). Look at each occurrence of the charactercins, and another occurrence of the charactercint. They have a tune between them (because they haven't been merged). There aref(s,c) ×f(t,c) ways to pick this pair ofc's, and sof(s,c) ×f(t,c) tunes as well. All these tunes will be lost when they are merged, and it costs the same amount to merge them. Summing over allcproves the claim.Now that we have shown that we can compute the minimum accumulation cost of a string from just counting how many times each character appears. If there are

nof a character, then they have tunes among them; simply sum over all characters to obtain the accumulation cost.Now, constructing a string is easy. Just take

nas large as possible while keeping ; now we haven`a`

's. Subtractkby and set that as the new value ofk. Takenas large as possible again; we haven`b`

's. Repeat until we're done. Fork≤ 100000, it can be proven that this greedy strategy works (it's impossible to havek> 0 after using all 26 letters).Problem C is shit: simple idea, but difficult implementation. And with TL like this it's not obvious what will/will not pass...

Am I the only one who thinks like "I saw many problem such like this, but I always couldn't come up with idea on this type of problem (simple range query, but also update) so I can't solve this." ?

It's no rocket science to realize that nlg^2n will pass :D

My solution (segment tree of treaps) didn't pass.

I also hate when my sln is rejected for constant issues, but.. Man, nlg^2n is <30M by rule of thumb, and my lazy solution runs in 1.45s. Not to mention that there was several n^1.5lgn AC solutions — it's too much for authors to consider anything which is even slower than n^1.5lgn solution.

And tbh I'm not surprised to hear that segment tree of treaps don't pass..

But it does :-)

29988051

WTF, it was?

we are in div 1 :(

Am I the only one who was stuck on div2 A for a very long time?

Me too. I was feeling so stupid the whole time.

...and failed system test:(

In 2C cannot we do it as {1,3,6,10,15,21...} and find n as a sum of elements of this set?

yes, it turns out that the order of merges don't matter, and we can consider merges of different characters separately and sum at the end so this approach works. The proof of the above claim stems from the identity

please help me :( my code got MLE on first test (D div2) but I didnt use much memory on it.

http://codeforces.com/contest/849/submission/29990097

Harder round than usual.

How to solve Div2(B)? Any ideas?

maintain a map of slopes.

Choose one point as p1.

For each point p2 in the point set except p1, caculate k1 and b1 for line p1p2(y = k1x + b1), then for each point in the point set, test if the point in the line p1p2(abs(k1x + b1 — y) < eps). We can tolerate at least 1 point(since the line must pass at least one point) not in the line p1p2. If we found two points(p3, p4) not in p1p2, then they can form another line p3p4(y = k2x + b2), if k1 == k2, for the rest points we only need to check if it is in p1p2 or p3p4.

Since the p1 we choose may be the only one point in a line, we need to try again with another point as p1 to cover this corner case.

Is there an easy solution for C? I came up with a that I can't finish coding in 30 minutes (probably 200 lines of code).

Hope my solution doesn't FST...(upd: Passed System Test!)

For any two points

i,jthata_{i}=a_{j}, if there doesn't existi<k<jthata_{i}=a_{k}, then we create an interval [i,j]. The query just asks the sum of lengths of all intervals that lie in [l,r], and update changesO(1) intervals.Let's take an interval [

l,r] as a point (l,r) on the 2D plane, and its weight isr-l. A query [l,r] asks about the sum of weights of all points (x,y) thatl≤x,y≤r.You can write a DS that supports add/delete 2D points and 2D rectangle sum query. I used Fenwick tree + balanced search tree. The time complexity is and space complexity is .

As long as you know how to code 2d segment trees, it is. Consider the points of coordinates (prev[i], i) with values i — prev[i]. In one query (L, R), you're interested in the sum of the values of the points with L <= x and y <= R. When you modify a value, at most 3 prevs change

90 lines only 29981295

Am I the only one who took 20 minutes in C to avoid using map with 2d fenwick tree (and didn't succeed)? I had a solution involving any sort of 2d segment tree and didn't know how to properly code it (I though of offline solution that would normalize stuff), but any implementation has, besides the log^2 complexity and extra log or pretty big constant (maybe if we use instead of map some better hash). So, I wasted time and got nervous, but at least I can learn something out of this experience. Can anybody tell me how to properly code 2d segment trees so that you don't need an extra log or hash to access memory spaces? I do know how to do that with a segment tree with binary search trees (treaps more precisely) in nodes, but that is neither elegant, nor constant-friendly:))any help?

fenwick tree is superfast and it was likely that it would get accepted (and it did :)))) btw, even n sqrt log with fenwick gets accepted here

so i think there was no reason to get nervous as TL was pretty big

Is int32 (int in C++) enough for problem B div 2 ?

Yes, int = 2^32 = 4*10^9

Isn't max_int in C++ 2

^{31}(one bit of memory for sign)? The coordinates here can be negative. Either way, it should be good enough.Sorry for my non-clear question, because I think everyone using pair of fraction. But as I see, people use double instead. So I wonder if using fraction to store, could we get integer overflow for multiple operation.

If you do all operations without double, then long long is safer.

Why div 2 B ? ...

My first div1 contest and i think i'm going back to div2(((

Don't worry, you are safe:) your new rating is 1916

I didn't even solve problem a in div2.. How to solve that?

Idea: 1. the sequence must have odd length 2. the first and last elements must be odd

Failed on tests 5 6 7 8 9

Hacks for Div. 2 A and B?

Div2a

6

1 0 1 0 0 1

Answer is no.

For Div-2 A, even this code (surprisingly) passes Pretests, so ez hack is:

`n=3`

and`a=[1,3,4]`

.In problem A my code passed pretests without handling the n=1 case. (Luckily I noticed before getting hacked)

ODDS&ENDS by. supercell ( ryo )

Tell Your World by. 8 Prince

From Y to Y by. OneRoom

Rooter's Song by. DECO*27

Goodbye Souvenir by. Toa

Miku is the best.

shake it!by emon(Tes.), andHanairo Biyoriby Natsume ChiakiAm I the only one who found Div2 C easier than Div2 A and Div2 B??? :|

I think div1C can be solved in this way in O(nlogn) but I suck at implementing it — spent 90 mins and got nothing. :(

The answer of each query is equal to the accumulated value of nxt[i]-i for l <= i <= r where nxt[i] is the smallest value which satisfies a[nxt[i]] == a[i]. (Let nxt[i] = n if there is no candidate for the sake of implementation), minus nxt[i]-i the rightmost elements of each values

nxt[i]-i can be maintained with a trivial fenwick tree.

Denote red[i] to be the sum of values to be reduced for queries [l,r] where r == i, this value could also be maintained with any range structure. (Just increment red[i..nxt[i]] by nxt-i)

My buggy code for the brief idea: https://ideone.com/NPDI0p

Edit: Nvm, I think it fails to handle elements which are not contained within the query range

I think it won't work because "minus nxt[i]-i the rightmost elements of each values" don't really match with

red[i]. (didn't see the implementation, so I might be wrong)It feels good when System Testing is so fast =P =D

Super fast system test! Great!

It seems that there are many solutions and complexities in Div.1 C.

Which complexity did you use?

I have an impression that when score distribution is like "x-y-1750-1750-z" or "x-y-z-2250-2250" it almost always turns out it would have been better to have standard one. Like this contest or here: http://codeforces.com/contest/830

Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).A moment of silence for those who solved A then jumped to C but couldn't finish debugging it on time :(

When ur python code can't perform 1e6 operations in 2s and gives TLE :(

Python should be able to perform around 10

^{7}arithmetic operations in 2 seconds. Your solution might be inefficient. (For example, did you know concatenating strings is ? If you concatenated so much, your estimation of the number of operations might be off. It might be something like that.)I am talking about div 2 B.

I beleive this is O(n^2) only with n <= 1000. http://codeforces.com/contest/849/submission/29979940

It does look like it's

O(n^{2}). Perhaps you're just rather unlucky; you might need to find a constant factor speedup (making the constant inO(n^{2}) smaller). (Note that tests 18-19 haven= 1000 and you passed in around 500 ms.)yeah. #sed_lyf

very surprising. my C++ code 29984431 which is also passed in only

15ms.You can try submitting in PyPy, it runs a lot faster.

I must say, extremely bad problemset. Would require one hell of a disinterested person to write such bad problems.

Very true

EDIT: The editorial is already up, wow. Well, I'll leave it here anyway.

I didn't come up with a complete solution for Div1D, but this is my idea:

For convenience, suppose a change involves the edge (

u,v), and vertexwand edges (u,w), (w,v) are added. Then we saywisbuilt on top of(u,v). We also say (u,w), (w,v) arechildrenof (u,v). We say (x,y) is adescendantof (u,v) if (x,y) is a child of a child of ... of a child of (u,v) (with any positive number of levels). Letcut(u,v) be the minimum (u,v)-cut in the subgraph made of (u,v) and its descendants,minus 1(the edge (u,v) itself). This minus one make things much cleaner.First, suppose

u_{1},u_{2},u_{3}, ...,u_{p}are all the vertices built on top of (s,t). Then ; this can easily be proven by induction (and the base case itself is easy to see: either you cut fromstou_{1}, or cutu_{1}tot).Given this, we can use dynamic programming to solve it. An attempt is to set

dp[n][m] to be the number of possible worlds where there arenchanges andcut(s,t) =m. (Since we don't count (s,t) itself incut(s,t), given inputn,mour answer isdp[n][m- 1].) If we could somehow take care of the similarity condition, this would work:p(the number of vertices built on top of (s,t)).n'_{1},n'_{2}, ...,n'_{p},n"_{1},n"_{2}, ...,n"_{p}:n'_{i}denotes the number of changes made on top of (s,u_{i}) or a descendant of it, andn"_{i}denotes the number of changes made on top of (u_{i},t) or a descendant of it. The condition is that (n'_{i}+n"_{i}) =n-p(we already madepchanges,u_{1},u_{2}, ...,u_{p}).m'_{1},m'_{2}, ...,m'_{p},m"_{1},m"_{2}, ...,m"_{p}:m'_{i}=cut(s,u_{i}), andm"_{i}=cut(u_{i},t). The condition is thatmin{m'_{i},m"_{i}} =m-p.dp[0][0] = 1 (no change needed),dp[n][0] = 0 forn≥ 1 (we may not make any cut, but we must make some change), anddp[0][m] = 0 form≥ 1 (we cannot make any change, but we must add a cut).dp[n'_{i}][m'_{i}] ×dp[n"_{i}][m"_{i}]).^{9}+ 7.)The similarity condition makes things hard, however, since we need to take care not to count the same thing twice. As an example, suppose

n'_{1}=n'_{2},n"_{1}=n"_{2},m'_{1}=m'_{2},m"_{1}=m"_{2}, and yet the subgraph built on top of (s,u_{1}) or its descendant, sayH, and the subgraph built on top of (s,u_{2}) or its descendant, sayH', are different. Then we will get another valid graph by swappingHandH'. This gives the same graph, but our naive DP algorithm will count them as different. So we need to take care of that.My solutions for the problem is perfectly okay but they were rejected during the contest for no reason.

Look at the two solutions below 2991746, 29991714 the only different is at line 153.

Everything is exactly the same. Even the output is same.

Can anybody explain?

It seems that p(x) prints an extra trailing space.

29991794

This is a solution, with extra space that gets passed.

Perhaps in practice the checker is not so strict.

It seemed to me that p() prints

`\n`

only. As your wrong answer states, the verdict is`wrong answer Line "o " doesn't correspond to pattern "[a-z]{1,100000}"`

You may observe that there is an space after`o`

... So I went to look at the code when n = 0, and turn out that`p("o")`

is different from`cout << "o"); p();`

TL;DR: A single space hurts :(

p("o") prints a new line too.

I print extra new lines all the time. This has never happened.

Output for

`p("o");`

is`o \n`

; andoutput for

`cout << "o"; p();`

is`o\n`

.So the only different is really the space. I think the checker this time is strict tho, as normally the checker would trim your output first...

The difference is that you are printing an extra

SPACEin the second code. But I agree that this shouldn't be a reason to get WA if the rest of the code is correct.Nice problems!

my mind was blowing in 2nd question.. :(

super contest !!!

I got AC on Div. 1 D after contest (I couldn't get it to pass during contest because I wasted time on Div. 1 C). Here's my solution :

Let

dp[i][j][k] denote the number of distinct graphs that can be formed after applying the operationitimes so that the max flow isj, andkis something we will describe later. We iterate throughx, the number of times we use the edge s-e to construct a new vertex wherekflow will flow through it. Iterate throughy, the total number of operations spent on this part of the graph (the current edges and all the edges that will occur after it). We need to find the number of ways to useyoperations to createxpairs of graphs of the same type such that for each pair of graphs (A,B), the minimum of max flow ofAand the max flow ofBis exactlyk. Suppose we know the answer to this isX. Then, we can incrementdp[i-x-y][j-kx][min(j-kx,k- 1)]·Xtodp[i][j][k].Let

dp2[i][j] denote the number of ordered pairs of graphs (A,B) we can form such that the minimum of max flow ofAand the max flow ofBis exactlyjand a total ofioperations are used. Then, we can iterate through allk, denoting that we usekoperations to formA, and all pairs (l,m) withmin(l,m) =jand adddp[k][l][l]·dp[i-k][m][m] todp2[i][j].Finally, let

dp3[i][j][k][mx] denote the number of multisets of ordered pairs of graphs (A,B) we can form such that the minimum of max flow ofAand the max flow ofBis exactlyjand a total ofioperations are used, assuming that we can only use at mostmxoperations for each pair of graphs. Iterate throughl, the number of pairs where we use exactlymxoperations. LetC=dp2[mx][j]. There areCways to choose one pair, and we need to chooselpairs, possibly with repetitions. The number of ways to do this is by the balls in urns formula, and this value can be computed inO(n) time sincel≤n. Thus, we add todp3[i][j][k][mx]. We can use the value ofdp3 to find theXwe need fordpabove.I know Div1C

`N * sqrt(N)`

solution but I did not have time to finish writing it :( OffensivelyI solved only one problem on a round for Miku.

I'm feeling terrible.

Just take my score. :(

WTF!!

It's like game of thrones. The more you have, the easier you can lose it!

All my solutions were "skipped" and I was not given a contest rank.I did not plagiarize any code from anyone ....

maybe you used some public online IDE like ideone and someone copied and submitted that code before you did!

Ya i just realised that. I hadn't privated my code on ideone. Pretty damn unfortunate .....

Bad luck. Solution for A and C was correct. If these two got rated then.... Alas! they got skipped.

I think my B was rit too cause i got AC in the system test round and then it later got converted to Skipped. But i guess ders no use crying over spilt milk....

Bad luck. Solution for A and C was correct. If these two got rated then.... Alas! they got skipped.

I'd like to have my solutions skipped... =)

Nice problems!

can someone tell,why WA it's working for the same input on ideone — http://codeforces.com/contest/849/submission/29996525

You are setting the flag to false when the endpoints are odd, you need to set the flag to false when they are even.

Run the same code in custom invocation, you'll get "yes" instead of "No"

thank you ♂sir

昨晚有点崩，本人hack了，以后一定要稳定心态，加油！

Good luck next time!

Also, on CF people write English so that everyone will understand. You can translate it.

hhhh thanks！

Dongda District so many people want to play codeforces, but only the middle of the night to play, hoping to like that last night that time, or later can, or every time the second day of class are listless.

Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).