Hello everyone! The first round of the 8VC Venture Cup 2017 will be held on Sunday.

I am honoured to be the problemsetter of the round. Reyna helped me a lot. Huge applause to KAN for his valuable coordinator's help, and MikeMirzayanov for his admirable work for the Codeforces comunity. I also want to thank testers very much (Alexey ashmelev Shmelev and Alex AlexFetisov Fetisov).

This round is a first stage of 8VC Venture Cup 2017. If you want to acknowledge yourselves with the competition, try here.

The main character of the round is PolandBall. It's a small friendly Ball who lives in a forest along with other Balls. You'll surely like it :)

I tried to fulfill your demands with a various, interesting and challenging problems described in a concise way.

Hope to see you soon, good luck and have fun!

**UPD1: Scoring** 500 — 1000 — 1500 — 2250 — 2500 — 2750 — 3500.

**UPD2** Thank you for participation! Contest is over. Did you like the problemset? Feel free to comment =)

**UPD3** Editorial

**UPD4: Winners**

Hope you've had a good time with PolandBall solving the problems.

Congratulations to all the winners and TOP-200 who advances into 8VC Finals =)

will be 7 or 8 problems?

7 problems. We will inform about the scoring later.

With only 2 hours? Are you sure it would not be better to extend to 2:30 or 3:00, most rounds with 7+ problems are longer than usual I think.

7 problems in 2 hours, I think it will be great contest

Me too =)

it will be great contest for tourist not us :(

Börk, börk

What a cute polan! I decided to take part in this contest.

Give him a hat, and now he's become Indonesia ball

Nah, asiaballs are distinguished by slanty eyes.

So this is Voltorb's round. Really excited about it.

Whose round?! xD

Rating for div2？

"I tried to fulfill your demands with a various, interesting and challenging problems described in a concise way."

Now I really have something to look forward too ^_^

Concise challenge:

"Can Poland into space?"

Hahahahahaha,that's great.

I don't know why this meme originated. Poland has already had an astronaut in space.

Yes, we can. In 1978 Miroslaw Hermaszewski was in space thanks to the INTERKOSMOS program.

It's 2:05 AM in my local time.. too late .. sad ;(

Will it be rated?

Yes

Is everyone who can participate in this contest?

community*

poland ball <3

Balls War 2-

I tried to

fulfil your demandswith a various, interesting andchallenging problemsdescribed in a concise way.Grabs popcorn and wait for comments whining problem C/D is too hard again.Excited about the contest... All the best Miyukine for your first contest as an owner. Loved last contest of KAN. The problems were really good. Hoping for the same.

7 problems,2 hours :/

kurwa

Is it rated or not?

Yes, it is.

As I understood, there will be 7 problems, Div1 and Div2 combined. As 2 hours isn't too much time for 7 problems, I think that I have to choose between Div1 and Div2 and I'm not gonna solve all the problems. If I misunderstood something, please someone explain it to me.

Long Live CODERS...

It's first time I see deleted comment )

Yeah same here friend

sorry you missed :: The scoring distribution will be announced later ;)

is it rated ?

just do well and codeforces will increase your rating or verse versa .

now, should I do the contest or watch Liverpool vs Manchester United :/

both of them XD

i will play the match in the background , and watch the dangerous attacks; the contest will start at the same time with the second half of the match; So we can enjoy the first half :) <3

you can participate in the contest then watch the highlights while ratings are updated. The best way to get rid of complainers about ratings being late:D

nice

Schizophrenia !!!

is this a rated contest? ok i got it its rated

Will tourist's comment be upvoted or downvoted if he askes "** ** *****?"

Of course upvoted, he's tourist

I don't think he's a rating addict. :)

Tomorrow at 12:00PM(BDT) is my Algorithm exam and today at 11:05PM(BDT) 8VC Venture Cup 2017 — Elimination Round. As I am not known of so many topics of my course I choose to participate this contest. Hoping my color will change.

Totally same situation about exam, but I hope my color won't be changed :)

Is it Rated ? got it. It is rated

The contest starts in 18 minutes. Good luck all!

Solution for A stays queued for 5 minutes, help

same here

Custom invocation isn't working as well. EDIT — It works now!

Got 2 WA's which I could've fixed WAAAAY sooner if they didn't stay queued for 10 mins :(

Problem-B's statement should more clear . It makes a lot of confusion.

Why do you think the statement is poor? We didn't need to clarify it any single time. You could've asked a question.

Nope.I solve it with simple approach.Making no sense both are playing optimally, i think.

To play optimally, a player has to know, that the opponent knows that word too. I read the description a few times searching for that sentence, but then just assumed it to be true.

I think so.

I have a confusion please, in the first problem , should we print all m so that n*m + 1 wont be a prime number ?

No, just only any of the m so that n*m+1 wont be a prime number.

Is this contest rated???

yes it was

Definitely the best contest in a while, thanks for the very nice problems :D

It's the most beautiful contest I ever seen.

What was the hack for D?

i have the same question

5 3

Answer should be equal to the answer for 5 2

Phew im safe

Well that was hack 1 for me. Hack 2 must have been the 10^6 case.

Phew safe there too :D

damn i will get failed too

Im crying now.

Well, at least that's the first time I came so close to solving D during the contest time.

Fu.........................................nny, didn't think of that.

1000000 499999 => many used int for result

I TLE'd on this hack, amazingly :(

meh I'm an idiot... :(

oh no

Oh shit. I used long long but I printed it as "%d" :(

12 7, you should have k = min(k, n-k), unfortunately i will be failing for this reason

I firstly use 1000000 999997 because I think it will cause Int overflow. However, the true answer is not cause Int overflow but most people failed this hack.

The answer is 2 3 4 ..., but most people (including me, print 2 4 8 ...).

How to hack A?

Some people used m=n+2. But this is wrong when n=999 or n=1000 since m must be <=1000. So they have to handle that case separately.

Hack for Div2B:

2 2

a

b

b

c

Hack for Div2A:

330 or 726

Whats the logic behind D ? Also, I have a feeling that a lot of D solutions are going to fail.

My logic (though it TLE'd on hack 2), was simply to check the number of diagonals from vertex x to vertex x+k that have been drawn, and add to the answer (1 + number of diagonals). However, I kept track of diagonal through a circular array that I was traversing everytime, so it must not have fit..

Weirdly...the 10^6 case passed on my system

Edit-nvm, the case did not pass. I'm an idiot >.<

D was almost similar to this https://www.youtube.com/watch?v=K8P8uFahAgc&feature=share

Here's my soluton.

can u pls explain your solution!! thanks.

Pleaseeeee

The amount of segment changes by

`1 + (amount of other diagonals crossed)`

. Each diagonal connecting the i-th and j-th node nesessarily crosses all the diagonals in range (i+1, j-1).Just use the segment tree to store the diagonals in each node. When you add a new diagonal (i,j), increase the amount of diagonals in i-th and j-th node by 1 and calculate the answer.

Here is the example: http://codeforces.com/contest/755/submission/23866075

(unfortunately, i didnt realise the int overflow during the contest)

Was Problem F checking if subset sum = k for min and greedy for max?

I think so, but I got WA with this approach.

EDIT: I guess I have a bug. :/

Yes. Is there any solution for F faster than N*sqrt(N)?

Bitset... I still think I will TLE though.

Is there some way to create a bitset like this instead of creating a custom bitset object?

Just make it larger than the largest it needs to be ; )

Templates are evaluated at compile-time, so you can only do that to consts.

Actually even well written N sqrt N can pass.

It's possible to do (N sqrt N)/32, however. See tourist submission.

tourist submission is actually , in this order of nesting. There's an loop (for each cycle length

`i`

), then there's an loop (subtracting powers of 2 from`cnt[i]`

) and finally anO(10^{6}/ 32) shift+or operation. Would you please explain this solution?Actually I think that is (N sqrtN)/32. See this comment.

Thanks for pointing that!

Yes. I got AC using Monte Carlo Method and letting it run for 10 ^ 6 iterations. Basically, you keep a set of active elements, as well as the sum of the numbers in that set. At each iteration, you either:

At each step, you also need to update the sum of the active elements. The code is simple enough, you can check my code here, though I wrote it in a rush and it's a bit more complicated than it needs to be.

This method has a very high probability to find an answer, if it exists, given enough iterations.

For E, What's impossible case for n, k?

http://math.stackexchange.com/questions/485493/diameter-of-a-connected-graph

It seems as though min(G, G') <= 3.

N <= 3, K >= 4, K == 1 or (K == 2 && N == 4)

Am I right that in F we have to solve knapsack problem? Is it solvable with FFT (either using forward transforms for all, and only one backward, or successively multiplying the smallest arrays)? I doubt it will fit into time limits.

You can solve the knapsack in O(k*c), where c is the number of different cycle lengths you have, so c=O(sqrt(n)).

I did that and passed pretests in 700-800ms, but this problem has a reduced TL (1.5s compared to the standard 2s), which is very odd considering O(N*sqrt(N)) for n = 1e6 is already 1 billion. I think the time limit and constraint on N made many people not even consider this solution.

Well, you can do that with bitset which is significantly faster

Can you, please, give a link or explain how to use these /32 or /64 optimizations with bitset?

check someone's code for that problem e.g mine

It's 10^9 and I believed it's too much.

4th Very weak pre-test cases.

Hack: Long Long overflow or k > (n-k) eg 7 4.

naive O(nk) solution also passed pretest

i submitted my solution for problem D at the last second . i mean i hit the submit button and after it displayed the end of contest . but its not showing my submission !

2

k>nin DF is like the worst problem one could give for a contest.

Why?

Because the intended solution is Nsqrt (N) for sure. It reduces to knapsnack problem with limited sum which is solved in Nsqrt(N). F was really nice but with very bad limits...

Of course it is reduced to knapsack but I think that it was intended to also use bitset and make it . Why is it bad that you need one more small approach in one of the hardest problems of the contest?

Well I thought about that(with 1/32 constant), but it is not actually Nsqrt(N)/64, because just one part of the algorithm can use bitset at its maximum, so its more likely something like Nsqrt (N/64) which is not a very good or relevant improvement. And the problem was really nice without it

I never enjoy solving something that looks 100% like the problem that appeared before, where a lot of people know the idea. It fits for educational rounds, but not rated ones.

It cannot be ensured that all problems have never appeared anywhere.

Believe me, Codeforces staff and writers did their best to make the round enjoyable.

Why? I really enjoyed solving it, and the idea (of optimizing knapsack with repeated items to perform log(cnt)^W O(1) passes per item, not cnt) is beautiful, I don't remember seeing it before..

(all this assuming my approach is correct — we'll see soon if it is the case)

I'm not defending Al.Cash's statement that this problem is the worst one ever, however I've seen the idea of replacing

`cnt`

objects with`log(cnt)`

ones many times in the past (at least in 3-5 different problems).OK. Less activity in contests => forgetfulness => more fun solving problems even if ideas aren't original :)

Replacing cnt objects with log(cnt) ones? If I understand correctly, you're talking about an O(n*sqrt(n)*log(n)) solution, not O(n*sqrt(n)).

Do you mean you take, say, 10 objects of size 3 and replace them with 1 of size 12, 2 of size 6 and 2 of size 3? So instead of k objects of the same size, you have O(log(k)) objects of some other sizes, and the same solution set?

I passed with this idea with really small running time (327ms), is this solution supposed not to pass?

My N*sqrt(N) implementation barely passed and you're saying that it exists a Nsqrtlog implementation that passes as well? How is that possible?

This is N sqrt N log theoretically. However, it can be proven that some applications of this method are still N sqrt N. Look at POI 20 booklet, problem "Polarization"

Why was this comment downvoted?

I don't know about O(N*sqrt(N)) solution but it is probably because high constant factor of O(N*sqrt(N)) and low constant factor of O(N*sqrt(N)*log(N)), actually it's not possible that both sqrt(N) reach 1000 and log(N) reach 20 at same time.

UPD:ok it seems it's O(N*sqrt(N)) as mentioned by AlexDmitriev hereI'm looking at your code: http://codeforces.com/contest/755/submission/23860782 and currently I believe it has quadratic time (e.g. when we have two stacks of O(n) size).

Upd. I see, "break" in the innermost loop prevents it from happening.

It will be still O(NsqrtN) because after replacing they have still N as their sum (and at most O(sqrtN) different)

Maybe, but in this contests it happens to be the best problem

Agreed.

My performance was so bad , however I have to admit that the problems where really so good and short. Thanks :)

Using int in problem D :) good bye cruel world

Awesome round, Kacper! Thanks :)

WTF was this contest!!!!!

Your name says it all :D

Feeling proud after making hack for a red one 'D

I know lots of people will ask how to solve A so here is the solution:

answer is min(999, n+2)

Why not 500 — 750 — 750 — 1000 — 2000 — 2500 — 3000 or dynamic scoring? Hacks have very low cost otherwise.

But then by not putting 2*k>n case in pretests you can't completely ruin the contest for some people

Oh, hacks are already worth way more than they should be, lol.

Locking D and feeding on people who used int or didn't watch out for 2k > n should give nowhere near as much points as correctly solving another problem, but it does.

I haven't read

Dfor long time because it marked as 2250 — difficult, but it was not... :(Where did you see the label "difficult"?

tourist got penalty on A :o

"Idleness limit exceeded on pretest 4" What does that mean and why did the exact same code pass the tests later (giving me -50 points for wrong answer ans some more minus for slow solving)? http://codeforces.com/contest/755/submission/23846772, http://codeforces.com/contest/755/submission/23851648

Dear authors / pretest makers of problem D, you are both evil and awesome! =D

What could be the reason of WA5 in G?

I don't know. This is a maxtest, nothing special in it.

Use Custom Invocation to check your running time on Codeforces machine.

Mine running maximum test in 8.7 sec :(

Maybe divison by 0 (n could be larger than 998...)

In my case the problem was following: I tried to store values of

dp(N, * ) in fft-transformed way to avoid running transformation twice on every step. However, at some point it may happen thatdp(N,j) forj>Kis non-zero which means on the next step it'll screw up the result (as it won't be a product of required two polynomials anymore) so I needed to explicitly setdp(N,j) = 0 forj>K.What if i submitted a correct solution then submit one more solution which pass pretest but is hacked (previous submission is correct) what will happen :( (changed long long to int to save memory in D and resubmitted)

From 950 pretests passed to ~400 accepted. Nice pretests and evilest cases in D :(

D so many fst ....

Don't you think D is a bit too harsh?????????

My room 10 pass pretest and only 1 pass system test..

in my room no one pass it Hahaha

Thanks for beautiful problems! I enjoyed a lot and it was the best round I have ever participated in CF

That feel when you drop from sub-200 to 340 because you were too lazy to write a sieve for A :'''''''''''(

EDIT: nvm i scanned up to sqrt(n) instead of sqrt(n*m+1) >>>>.<<<<

why would you need sieve? the constraints are pretty low. n*sqrt(1000001) should pass just fine.

n*sqrt(1000*1000) = n * 1000 it is, but still ok

I managed to pass with 2 for-loops in 15ms though, how did you get TLE :/

I had a prewritten sieve from last contest :D

If it is rated contest?

Perfect difficulty level distribution .

:<

Sad story.

Can we see test 6 on D? Or someone who made a lot of hacks (not talking about overflow-like hacks), can you share the idea, please?

UPD:Thanks to all of you :))5 3

no, that was not it. mine works fine for 5 3 and died in 6

Edit: it's 1000000 500001. wow.

2*k>n is test 6.

Why is 2*k > n special case?

Because when k*2>n, for example with test 7 5. Then 2 will be connected with 7. But you should consider this line as 7 2 rather than 2 7 to avoid repeats.

1000000 500001

It catches both people who fail testcases with 2k > n and people who forgot 64bit data types to store result.

Accepted solves are less than WA 6

Why on earth don't you put it in pretest T_T

I can offer you a solution that passes system tests, if that's of any use. :/

Could you explain your solution a bit?

Most of the solutions failed on test cases when k > n/2. So the example hack can be: 5 3

As the circle is symmetric one could just take k = min( k, n — k ) at the beginning of the solution

The most basic hack was 5 3 <-- should have the same answer as 5 2 because the circle is symmetric.

How am I supposed to score 13 hacks in D (as some people did on 13 different users) if I hacked all wrong (not mine xd) solutions which amounts to 3 submissions :/?

Hey that's me :)

And that's why hacks are a stupid concept that doesn't belong in programming contests.

Life is not fair and it will never be :)

That's why many people find ACM-styled contests better than life — because they are fair. :)

When you are in a stupid university and you are the only competitive programmer in this university and you have no choice but to put 2 teammates with much lower level than you while most other teams consist of 3 strong participants then ACM is not fair.

Do you want me to mention them? Luckily codeforces just implemented notifications :P

AmrMahmoud Transfer to Aleppo University :)

It is not prohibited to change "stupid university" to a different one.

easier said than done

Kingofnumbers

How about coming to Tishreen university and participating with experienced ones like Deadwing

Thanks for someone hacking my D solution...

`random_shuffle(participants.begin() + 1, participants.end());`

Evil pretests X(

nice contest :(

So week pretest on problem D!

When will ratings change ?

NBHEXT stoped working, did anyone else have the same problem?

Yes, unfortunately, it is not working. I've already written about that in the main post NBHEXT 2 weeks ago, but have not got any responses.

What is NBHEXT ?

click

So there were 5 pretests for D. What's next — only samples in the pretest? — Angry n00b who failed systest

Exactly that should not happen many Coders used the inappropriate approach like submitting the solution using brute or something and then hacking the solutions of others.

There are milions of values in the pretests. Ekhm.

Also, there isn't a single pretest in which k>n/2, which was the reason for most WAs.

I guess another problem with such pretests is that it encourages hacking to an extent which is overkill. People can get too many points with just hacks. D is of the same worth as F due to the available hacks.

Also, the point difference between D and E/F seems a bit low :/

Intentional.

Sad. Randomizes results as hell.

Actually we didn't expect that so many people will fail. If one problem has some hacks, its's acceptable, isn't it?

Great Contest! Maybe on the easy side, but who cares, my rating will increase!

what is the hack for this submission http://codeforces.com/contest/755/submission/23862816 ??

Given that lately there were quite a few combined Div.1 + Div.2 contests (and they went well), I'm starting to wonder whether we need the division system at all.

Yes, we do. For the participants, the division system is not optimal. However, few writers are able to provide 5 problems difficult enough for the best of Div. 1. Then, you either don't have a lot of contests, or you have a lot of contests in which ~500 guys solved all the problems in less than an hour.

Also, what was the deal with C? Isn't it

toostraightforward and classical : I read the problem 5 times to make sure I didn't miss something....If you solved with DFS or find/union, then it might be. Check the editorial approach. It's quite cool.

You can B test 16 please?

The irony is real.

Haha. What are the chances? xD

Not blue again :(

Really nice problems, thank you

Non-sample pretests for individual problems: 4, 6, 4, 3, 6, 12, 2. Was that intentional? The only problem with a decent number of pretests was F... no wonder there were so many hacks and failed systests.

Interesting problems and I liked short problem statements, Thanks :D

who can solve me this problem https://www.e-olymp.com/ru/problems/566