Hello! Codeforces Round 667 (Div. 3) will start at Sep/04/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that **the penalty** for the wrong submission in this round (and the following Div. 3 rounds) is **10 minutes**.

Remember that only the *trusted participants of the third division* will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a *trusted participants of the third division*, you must:

- take part in at least two rated rounds (and solve at least one problem in each of them),
- do not have a point of 1900 or higher in the rating.

**Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.**

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

**UPD**: Huge thanks to Ivan Gassa Kazmenko for testing the round and fixing some issues with statements and the round in general! Also thanks to nuipojaluista, kocko, Ilya-bar and infinitepro for testing the round!

**UPD2**: Editorial is published!

are technocup rounds rated ?

can someone tell rules of these rounds?

.

with "with ratings up to 1600" so me a 380 rating can participate right?, sorry this is my second contest still a noob, is div 3 problems easier than div 2 last time where I participated?

Yes div3 problems are easier than div2

oh I see thank you for the answer :)

yes div3 is easier than div2 and don't worry about your low rating .Initially you start from 0 according to the new rules but over a span of 5 contests you are provided with 1500 extra rating (500 rating is added for the first round which you have already given xD).

Sometimes,it is really difficult to understand why you got downvoted

Well, I didn't downvote you, but I think that's because that guy didn't say he is worried.

yeah but he had written "still a noob" and it was pretty evident that he did not know about the new rules so.. But yeah, even then I think you have a point

`<too-old-joke-about-copy-pasted-part>`

Too old joke

It might be, but div.3 rounds by vovuh will never get old

`Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.`

Can anyone explain how this penalty is calculated?It is the time in minutes for each solved problem. Plus 10 minutes for each submission but the last of one of those submissions per problem.

So if one has a wrong submission for a particular problem and he is not able to make an AC until the round ends how will that penalty be calculated?

if he does not make AC till round ends then no penalty ,else 10 minutes for every incorrect submission till AC.

Are you sure Sundaram_Sharma that if one makes many wrong submissions to a problem and is not able to get an AC for that problem will he be exempted from these penalties?

Yes

So penalties work for question wise and not total score wise?

Primary tie break is # of questions solved. Secondary tie break is time penalty, calculated based on submission time plus any penalties for wrong submissions on

onlysolved problems by adding 10 minutes per wrong submissionIs this true for Div 2 rounds as well?

This is only true for rounds specifically held with "educational rounds (extended ACM-ICPC)". This is how ACM-ICPC contests are held, and usually tend to be true mostly for educational rounds. Most Div 2 contests are held with point penalties subtracted from pre-defined scored distributions.

`Primary tie break is # of questions solved. Secondary tie break is time penalty, calculated based on submission time plus any penalties for wrong submissions on only solved problems by adding 10 minutes per wrong submission`

Will this be valid there as well?No. Score distribution can give harder problems higher point values such that a Div 2E might be worth 2500 points, while Problems A and B are only worth 500 and 1000 points. For example's sake say that Person A solves Problem A and B instantly, getting 1500 points. They would score less than a person who solved Problem E instantly, getting 2500 points. Notice that person A solved two problems, but would have placed worse in a regular Div 2 round. In a round held with ACM-ICPC rules, person A would have placed better than person B, having solved more problems, despite them being easier problems.

Actually, I'm asking about penalty. If till the end of the contest there all WA to a problem will there be any penalty?

In both cases, only solved problem penalties are applied. If you had 10 wrong submissions on a problem, they are not applied if you do not solve it. If you solve it at the last second, the penalties are applied. However, note that there is no case where it is more beneficial to not solve a problem, even with lots of penalties on it. Solving a problem in an ACM-ICPC round with a hundred penalties would still move you ahead of everyone who had solved the number of problems you had solved minus 1. Likewise, in Div 2, you are comparing 0 points for not solving to a positive number of points, no matter how many penalties.

What does it mean by -"I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over." Are the pretests too weak or are they strong enough so that there would hardly be changes in the accepted solutions before and after the contest in the main tests?

Pretets are quite strong so that less people get sad after main tests

They aren't necessarily strong, they're just not intentionally weak.

Curious the ratio of problem setters who intentionally make intentionally make pretests with hacking potential to those who try to make strong ones.

Problem setters do not try to intentionally make weak pretests.

My rating is 1603, is this round rated for me? base on description I am a "trusted participant of the third division", but I don't understood It is rated for those who have rating lower than 1600 "and" the trusted participant of the third division or just for first group.

"trusted participant of the third division" != "the contest is rated for you"

If you are trusted participant of the third division,your name will be on official standing.(Because there are so many fake accounts,u n r a t e d = L G M)

Being a trusted participant of the third division means your name will appear in the standings.

This round will be rated for you if your rating is strictly less than 1600.

Because your rating is higher than 1600, this will be not rated for you, but because you are a trusted participant if you join the contest your name will be displayed in the rankings.

Hope no long queue :>

Hello! I have got a question: do pretests too light to catch wrong solution? Why another person has an opportunity to make tests, which will "kill" solution of the problem?

There can be a situation where the author did not think of the edge case before the contest so it was not included in the pretests.

So authour makes this "mistake" meaningly? To give us chanse to hake someone`s solution?

No, it is usually not intentional.

No,it is because he missed some corner conditions

Does this mean that system tests are made after the contest ends ?

how to register for this? this will be my first one

Go to the Contest page . You will get your answer .

Thanks!

no side story ?

rating has taken a major dip :(,hope to improve it in this round

During my school time :(

No worries better luck with next div.3 contest

usually every contest happens at the same time.

Really waiting for Div3..

Let's hope this time finally I am able to break the 1599 barrier after falling back from 1590+ rating many times

SPOILERI think you are very close, it just a matter of time and you will hit expert very soon.

Thanks! you were correct indeed

Congratulations on your recent achievement :)

Thanks, hope to see you getting blue soon enough!

Can someone please tell me why is there a trusted participant definition created when the contest is rated for non trusted participant too. Is there a difference beside the official standing table or anything i am missing?

Trusted participants will appear in the official standing but non-trusted participants will not. But it will still be rated for both of them.

is there any change in rating for non trusted participant compared to trusted ones for the same rank?

No there isn't

what is the fastest set solve for div3? william lin did today in 23 minutes!! that's just amazing!!

.

Nope, I think it was

a little biteasy for Div 3.How to approach problem E ?

Spoiler 1Y co-ordinates are useless

Spoiler 2Sort the X co-ordinates.

From X[i] find till which index you can cover point with the first platform. let's call this index pos. You can do binary search

then find the maximum points you can cover with the second platform after the pos index. but how to find this?

Start from the last point. every time at ith index store what is the maximum points you can cover after the current index

Code Explains more than words

Is Y coordinate of any use in E?

No use at all

I don't think so

Then it is solvable using segment or Fenwick trees I have an approach! PS: Solved using Binary search 91881046

Can you kindly tell me why BIT and BITS are used for?

Actually Earlier my thoughts were to use Binary Indexed Tree but on further look I left that approach and tried something easier then binary search came to my mind. BIT is an array which is used to store the maximum point till which we can go from current point to next point if we were to place the board of exactly k length at this point lets say this maximum point till we reach is represented by BIT[i]. BITS[i] is just the suffix maximum array for array BIT[i].

B solution please?

There were two cases first try to decrease a to minimum possible then try for b. The minimum of both case is the answer

Any proof for this? That this will yield the minimum product?

To minimise the product we have to maximise the difference between two numbers. Hence the two cases

Hint — For a particular sum, maximum product happen when both numbers are as close as possible.

kazuya and ctyx you two are mentioning completely opposite things

They are saying the same thing, read carefully.

Basic premise here is the fact that, given a fixed perimeter, the area of rectangle is

maximisedwhen the rectangle is a square.Since you want minimum area, try to keep the two edge lengths as far apart as possible.

I thought of doing a ternary search on the possible interval but realized that min can occur only in one of these three points including mid-point as the curve formed will be a regular parabola. Now realized that checking mid is not necessary as interval lies strictly either to the left or right of mid.

My accepted (till now) solution

Was E solvable with two pointers? I tried so but getting WA on test 2.

codeProviding testcase would be great help

I tried two pointer but it does not account for test cases like this: 1 5 10 1 3 8 13 20 where two pointer finds the 3 8 13 on the first rod, when 1 3 8 and 13 20 are optimal. I tried to come up with additional cases, but ran out of time. Trying to look at your code, I am not sure you even used two pointers? Seems as though you calculate the second pointer each for all i, which would likely fail in terms of time complexity.

For each b[i] you need to replace it with the maximum b[i] among all b[i] from i to n-1 as it is not necessary that both segments have no points between them.

Yeah I missed that too but it's still wrong answer https://codeforces.com/contest/1409/submission/91877808

Checker says somewhere I printed 8 instead of 7. I think it was some silly mistake.

Great contest. Thanks vovuh

Help me with E and F

Though F is easier to think, E is easier to explain. So I will try to explain E first

SpoilerAre y coordinates of any use ? — No

What can be the best way to store x coordinate to proceed ?

Spoilervector<pair<int,int> > where pair<int,int> is x coordinate and corresponding frequency.

Let's sort the vector of pairs as per x coordinate. One more precalculation that will be useful is, prefix array on frequencies, basically on .second of pairs in vector.

Now let's make a dp table size of vector * 2 Either we take the current index or we don't. So if we are at i, and we take the current index, we need to find the other index, so that .first at current + k <= .first at end index for current platform. How ?

SpoilerBinary search

So once we have the end index, dp(i,j) = max(dp(i+1,j), prefix (end) — prefix (i-1) + dp(end+1, j-1)

Implementation of above idea is 91831346.

Idea for F : let's us assume that we have a 3-D dp table 200*200*200 where at i,j,k we store the number of subsequences of t, in first i characters of s, using j exchanges and having occurence of first charcter of t, k times.

To proceed to next state we 3 options, Set the current character as first letter of t, as second letter of t, or let it be same.

We need to handle few cases carefully

SpoilerWhat if the current charcter is already either first letter of t or second letter of t.

A little effort and the following code will make sense. 91846302

Idea behind F?

How did you solve E?

Well it's obvious that our two segment mustn't overlap. Now lets sort our dots by their x coordinates and calc ans[i] for i dot. ans[i] — a number of dots, that belong to the segment that starts at position x[i]. We can calc it using binary serch in O(nlogn). Lets second segment have larger cords that first one. Lets calc max_suff[i] — max dots that can belong to segment, that have the same or larger coordinate than x[i]. We can do it in O(n) just max_suff[i] = max(ans[i], max_suff[i + 1]) Lets calc now_max — the position of first dot, that have larger coordinate than the end of our current first segment. tmp_ans_i — answer if first segment start at i position Now look over first segment start coordinate and calc dots belong to it with binary search then add their number to the tmp_ans_i. Now update now_max: if (x[now_max] < (end of first segment)) now_max += 1 then update tmp_ans_i: tmp_ans_i += max_suff[now_max] Now choose the greatest tmp_ans_i — it is the answer. Code: 91848373

Very nice problems. Solved all but F (WA39). Any ideas about F? Maybe some dp? Greedy didn't work

no, it's not a dp problem

I solved it using dp,

`dp[i][f][r]`

is the number of sub sequences in`s[0..i-1]`

if the frequency of`t[0]`

is`f`

and there are`r`

replacements you can doHow to pick the two segments in E after coordinate compression? Will greedy work?

You can ignore the y coordinates. First sort the points according to the x coordinate, we'll call this array

`pts`

(for points). Then create two arrays`suffix[n]`

and`prefix[n]`

. They will store the maximum number of points you can save if you use one platform for points with`x <= pts[i]`

for`prefix`

and`x >= pts[i]`

for suffix. These can be calculated in`O(nlogn)`

time using binary search. Your answer would be`max(prefix[i] + suffix[i+1] , where i=0...n-1)`

, also`suffix[n] = 0`

See my submission : 91851604

I think there is a tricky edge case in problem D

Did you check if sum of digits of n is already less than or equal to s. I solved this one but still unable to figure out the corner case in test 3

just set the maximum possible value for the elements every high.

can anyone help to solve 2nd question?

You can just check both possibilities first try decreasing a then b (till their limits and n obviously) then other poss would be decrease b and then a. Find min of both you got ur answer...

.

Can someone pls tell what was wrong with my D? https://codeforces.com/contest/1409/submission/91874703

Problem E: you(y coordinate) vs the guy(x coordinate) she tells you not to worry about.

How did you solve E?

using queue to find how many points are there from i to i-k and i to i+k for each x coordinate

then find how many max points you can cover from left and same for right

answer will max of sum from both sides for every point

E was nice!

## Useless cheating, but still

His code.91803529

His alt code91859832

Same situation at B and C

Imagine coding the shit out of myself with digit dp just to realize that people get AC'd with simple greedy

My greedy got WA39. Can you link some accepted greedy?

Is there a greedy approach that works for F? I spent a bunch of time on a few ideas but couldn't get them to work.

I can share the solution of Gassa but I didn't get deep into details. It's also $$$O(n^4)$$$ but he said it can be optimized.

CodeYep I also had an $$$O(n^4)$$$ greedy, but it gets TLE. It should be optimizable to $$$O(n^3 \log n)$$$ with a Fenwick tree, but at that point it gets much more complicated than the DP solution (and is still slower).

Will an unsuccessful hacking attempt increase my time penalty in this round? I tried 2 hacks both were unsuccessful.

`NO in div-3`

I like the contests by vovuh because the statements are clear and precise :)

Anyone else solved E by binary search?

Yes! So for finding out how many points you can catch from a point with x-coordinate value A with K length, you can binary search the point with x-coordinate with value A+K. This can provide you with points you can catch while standing at ith position in nlog(n) time. Assuming that you sort the array of x-coordinates

are these cheaters phamquan-cbg and papaya.ahaha?: 91808904 91812659

I found these two VERY similar submission (when I was looking for people from my country to hack): + same strange input and output file name + exactly same loop

If you cheaters read this, please stop this immediately !!!

How do you look for people who are from your country? Are they in your friend list?

By using this extension you can see your country based standing..I collected it from a post..

Crome extension

Firefox extension

*I am using crome extension..thats cool.

actually, i was just search for people in my country that are similar in rank with me manually :v

lmao

My screencast + live commentary, enjoy watching :)

https://youtu.be/nloGFTpdTJo

can you Explain cnt + (i == t[0])) + cnt * (i == t[1]) part in your F solution?

Edit: I understood

Can anyone tell the idea how to solve E efficiently if we have $$$k$$$ platforms?

Thanks

ur welcome but don't forget to add nxt[i]-i to the first transition because all the points between them will be taken by this new platform . sorry i forgot it

Guys, could anybody help me understand whats wrong with my code for problem D? It gives the correct answer for all test cases in my machine, but it does not work at the Codeforces' server.

I'm sure the logic is correct, but don't know what happened. And unfortunately it was a valid submission in contest time.

MikeMirzayanov 91865709

https://codeforces.com/contest/1409/submission/91865709

https://codeforces.com/profile/enigma_13 Looking at this user, all his submissions have been hacked, because each of his codes has statements like if(t==xx). Although I think this way of raising ratings is very witty, should it really be encouraged?

How will it raise his/her rating?

I am not sure that this method can improve the rating in div3 and edu round. I am also a novice. But in ordinary div1 and div2 (especially div 2), you can use a small id and submit such a program. If the algorithm is correct, it can easily pass the pretest, and then you can hack it with your large id. After being hacked, you can change the value of the condition in the if and resubmit. Then you can use your large id to hack it again. This process can be repeated almost countless times. So you can get rating easily?

Nice contest, thanks. Got stuck on C until late in the game when I discovered the constraints were easy, then ran out of time. See you next contest.

this type of hack should be banned right ?

91859832

91860660

91861276

91817628

91879637

91879985

91880404

91880766

Such a nice round it was! It deserve more upvotes...

nice contest

How can we solve E using DP?

System testing is in quarantine.

Why the ratings has not been updated yet..?

I think it s because of the new update of this great condition of being a

"trusted participant".. While waiting for the rating too, I ve seen some friends of mine getting higher places in the final standings.. the reason is maybe non trusted participants got banned from the official participation.who is a "Trusted Participant"?

Who

`take part in at least two rated rounds (and solve at least one problem in each of them),`

Why is rating change taking time?

`The round will be hosted by rules of educational rounds (extended ACM-ICPC)`

Educational rounds usually takes roughly 20 hours. (12 hrs of hack period +a)12 hours of hack peroid + ?

why is this solution giving time limit exceeded?...i just ran it now...it got accepted

## include <bits/stdc++.h>

using namespace std;

## define endl "\n"

int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

int t; cin>>t; while(t--) { long long int n,x,y,i,j,num1=0,num2=0,mn=INT_MAX; vector v; cin>>n>>x>>y;

}

}

Obviously TLE......

waiting for rating change.. solved 5 of 6 problems

is it rated?

this code is giving wrong ans.can someone please help me to find the bug.? this code is for question 3rd.

## include<bits/stdc++.h>

using namespace std;

## define ll long long int

int main() { int t ; cin >> t; while(t--) { ll n,x,y,i,j,dif=0,ans=0,i1=n,j1=n,k; cin>>n>>x>>y; vector<ll,ll>v1; // ll long long int ans=y-x; dif=ans; if(n==2){ cout<<x<<" "<<y; } else{ for(i=n-1;i>1;i--){ if(ans%i==0){ dif=ans/i; break; } } // cout<<dif<<" "; v1.pb(x); for(i=1;i<n;i++){ if(x+i*dif<=y){ v1.pb(x+i*dif); } else{ i1=i-1; break; } } // cout<<i1<<" "; for(j=1;j<n-i1;j++){ if(x-j*dif>0){ v1.pb(x-j*dif); } else{ j1=j-1; break; } } // cout<<j1<<" "; for(k=1;k<n-i1-j1;k++){ v1.pb(x+(i-1+k)*dif); } ll r=v1.size(); for(i=0;i<r;i++) cout<<v1[i]<<" "; } cout<<endl; }

return 0; }

Your text to link here..._ this is the link to code.

My Java solution for E is just like everyone else's and the provided tutorial O(N Log N) and yet it keeps getting a TLE on test 5. Can someone have a quick look?

https://codeforces.com/contest/1409/submission/91970662

I've used FastIO, tried Java 8 and 11, nothing worked so far.

EDIT: I added some conditions to narrow down the problem, turns outArrays.sort(A)is taking too long, which is very weird. Not sure if I'm doing something obviously wrong. SolutionEDIT 2: Turns out, randomly shuffling the array before sorting it worked!! Why would the unshuffled array take WAY longer?!93053565 To solve problem F, I use an dp algorithm which has O(n^4) time complexity. It spend 1996ms, when this problem limits 2000ms. Lucky.