
Привет, Codeforces!
Благодаря поддержке Neapolis University Pafos, продолжается серия образовательных раундов. Университет предлагает получение степени бакалавра в области компьютерных наук и искусственного интеллекта со стипендиями JetBrains. Получите передовые навыки в области искусственного интеллекта и машинного обучения, которые подготовят вас к востребованным техническим карьерам. Любопытно? Присоединяйтесь к прямой трансляции во вторник, 29 октября в 17:00 UTC, чтобы узнать о программе CSAI, ее учебном плане, структуре курсов, стипендиях, стажировках для студентов и практическом подходе к обучению.
Хотите получить больше опыта в программировании и математических соревнованиях?
JetBrains Youth Challenge возвращается в ноябре 2024 года!
Кто может участвовать?
Возраст 13–18 лет.
Все, кто в настоящее время обучается в средней школе.
Зарегистрируйтесь сейчас.
В 28.10.2024 17:35 (Московское время) состоится Educational Codeforces Round 171 (Rated for Div. 2).
Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.
Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.
Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.
Удачи в раунде! Успешных решений!
UPD: Разбор опубликован









qp
dp
pp
qq
bd
cp
gg
Haha, I broke your silly chain.
NO you didn't
LL
I got a question, the penalty of time i.e. 10 minutes is the format of div. 3 and it is in this contest which is div. 2 so will the hacks have -ve points on unsuccessful attempts?
No, hacks are done after contest ends so there is no penalty
If I get minus again in this contest,I will leave CP.
Did you know that 95% of people leave codeforces before their biggest delta ever?
That's why I am still CPing after getting $$$-35$$$ and $$$-8$$$ in a row. (Got $$$+4$$$ is the last contest :))
I am still going to give this contest although got -102 :( in last contest
-140 and -54 in a row :(, for me
means, +250 is waiting for you, only if you practice hard.
only -43? lol
lol. I solved $$$1$$$ problem and got $$$-253$$$ in a contest CF1930
100% actually, even tourist
Don't leave! I'll touch your acc and help you.
help me also!!
Are you planning to leave CP too? :(
-
-59 in the last 3 contests 😎
-297 in the last 4 contests xD
take a rest/leave when it's no longer feels good. Comeback when you feel it or just leave it be.
Will I leave CP cause I am sure that I will get minus... I solved 0 problem...
Leave CF. Go to LC and atc spend 3 months solving mediums and A-D (on atc) there, and when you come to CF stop solving 800-1000, push yourself, gl
I haven't lately been able to see any of the other users' submissions. Everything I see is "N/A" for source code, even for problems I have solved. Any solution to this very annoying issue? Thanks!
Today is my debut contest with Rainboy strategy , gonna start from $$$D$$$
get ready for -250 XD jk bro all the best hope u do best
It's extended ICPC rules, it's not beneficial to do this.
I am not caring about rating for now, for now my goal is to get full grasp of $$$D$$$ as soon as possible so that I can become yellow fast
nice I am also gonna use it now in today's codechef
at least u did it, nice try xD I'm also doing it.
Doing contest, problem B feels weird AF so imma skip it. Please correct me if it's skill issue.
It's too standard problem, Just Binary Search the possible values of K, Solve more problems and you will find that it's a very common standard problem.
Binary search is possible but not necessary. This can be solved in O(n)
Yes but it a standard binary search problem, The O(n) solution will be hard to implement and we don't need this at all,
Á đù hội anh em KHTN.
Figured that the O(N) solution would be just "stitching" a[i-1] and a[i+1] together for every i and check, right?
KHTN
Can you please tell how to solve it in O(n)
N is only 2000 so i was tired with it and decided to go "Fk it" and yolo with O(N^2).
> inb4 "O(N) exist", I know but I'm too tired with B and I just want to get over with it.
$$$A$$$ is hard ._.
"black circles" flashbacks... 2002C - Black Circles
I was able to solve black circle pretty fast that time this one was hard for div2 A
I learned my lesson after failing black circles.
Do guessing sometimes, trade off between a penalty vs a quick solve + spare time for other problems.
u know what in the black circle problem I was able to visualize how it would be moving so I was able to come up with the distance formula solution but with this one I couldn't visualize what was happening so it took me time
$$$B$$$ is also hard ._.
Sucked without seeing small $$$n$$$.
Not quite, B is just tricky
Not quite, A is just output.
A is guess-forces
no, the constraint has
k<=1414, hinting a factor of root of 2 occurred someherewhich gives an hint towards the formation of square with side length =min(x,y)well, at least i guessed and got it right
Idk why i'm getting TLE in A. the constraints were pretty lenient for O(N * N) solution 288664487
Actually, the constraints are on X,Y and K in each test case, not on the sum of them over all test cases. So time complexity of O(XY) (or something else that is second order) requires a worst case of 1000*1000*5000 calculations, exceeding the time limit
What the hell is this Problem B?
took 2 minutes for A and 2 hours for B
hardest B i've ever seen fr
Actually I found A harder than B.
I feel like you either observe the solution instantly for A or you don't at all.
i literally kept testing everything I could think of on A and somehow it passed
Well, you just had to fix any two points of the two lines at the corners of the (x * y) rectangle, then vary the other two on x and y axes. I got TLE tho 288664487
5e3 * 1e3 * 1e3 = 5e9 , obviously TLE , you should always aim for <1e9 (unless the time limit is huge).
Ahh, so it's not just me? I literally have NO idea how people managed to come up with B's solution in such less time :(
B is a standard problem, and it took me nothing to figure out the solution.
how to solve E?
How to solve D? Is it a Segment Tree?
It's just some prefix sum stuffs
prefsums + binary search. you can check my sol https://mirror.codeforces.com/contest/2026/submission/288582700
damn that's a lot of prefix sums
i gave up after trying too much prefix
I used $$$4$$$ different prefixes in total ._.
Yea I just upsolved it and this problem was a pain. It took me quite a bit to implement it and iron out all the bugs...
Also not very "educational". It doesn't really teach you to think differently, just "implement harder".
(assuming 1-based indexing everywhere) consider the b array as divided into blocks as this: (n size block) (n — 1 size block) (n — 2 size block)..... now consider one block which has starting element of pair as i. what is the sum of this block? s(i, i) + s(i, i + 1) + s(i, i + 2) + ... s(i, n) where s(l, r) is sum of a from l to r. you will see that in this expression, a[i] is added n + 1 — i times. so calculate suffix array on a[i] by this rule (a[i] * (n + 1 — i))
now if i want sum of k blocks, i need sum of block 1, sum of block 2, ... sum of block k i.e. suff[1] + suff[2] + .... suff[k] so create a prefix array on the suffix array created before.
now consider this problem: we want to find sum 1 to x, in array b:
first find number of blocks that are completely covered say k — 1 (use binary search) add pref[k — 1] then we are at block k, now if this block has l as left point of the pairs. we want to find (l, l) + (l, l + 1) +.... (l, l1) (l1 depends on where x lies in this block. now for this we can add suff[l] — suff[l1 + 1] directly. but note : this followed rule (a[i] * (n + 1 — i), but now a[i] has not been added (n + 1 — i) times. you will see that now a[i] has been added (n + 1 — i) — (n — l1) times. so you need to subtract s(l, l1) * (n — l1). again have a prefix array on original a for this say this answer we calculated for sum of b from 1 to x, is given by f(x), then given query is answered by f(r) — f(l-1).
I saw lots of max flow solutions.
me too, but why them work?
The solution is a direct application of Project Selection. Here is blog about this: https://mirror.codeforces.com/blog/entry/101354
Why is div2E max flow :(
I hope there are simpler solutions
is flow hard?
answer is n — max pair matching in the graph, where left side vertices are 1,2...n and right side 0,1,2...59 ,edges i <-> j where a[i]'s j-th bit is set.
B?!!!! Why is n < 2000? Is it really n^2 for odd n? How to solve B?
Yepp just brute force for every index For every index I push a[I] +1 just after a[I] and then check the minimum among all maximum You can see my code
Thanks, can you give a case where the picking the either last or first doesn't work for odd n? I couldn't come up with such a case
For n= 7
1 2 3 1000 1001 1002 1003 It's optimal to add answer is 1 If I add 4 after 2nd index (0 based) And then pair (1 2) (3 4) (1000 1001) (1002 1003) But If you add in begining or end it will be 997
I did it in O(N). You can check out my solution: 288539510
please don't write problems like B again
What is the solution for B?
You can binary search for each k from low = 0 and high. = (arr[n-1] — arr[0])
why
return cnt >= n/2;how you got this idea?
I will try to explain it here, let me know if you get it or not.
cnt is the count of pairs, number of pairs should be n/2, as 2 elements make up a pair. Also imp thing is we only have to check diff between conseq elements as least diff of any j with current i will be when j = i + 1 as array is increasing. eg: if n = 6. there should be 3 pairs. if n = 7, there should be 3 pairs and the remaining 1 we can match by adding our available "atmost one addition case".
n is even : Lets say a = {1, 5, 8, 10, 13, 14} and k = 3 here 1 and 14 would not get a pair (as (5-1) = 4 > k & 14 doesn't have a pair to match with), whereas (5, 8) and (10, 13) can make up pair. So cnt = 2. As we can only add atmost 1 number, we can't make pair for both 1 and 14. So k = 3 is not feasible. if cnt was 3 (= n/2) then that means all the numbers have pairs. So its feasible.
n is odd : Lets say a = {1, 5, 8, 10, 13} and k = 3 here 1 would not get a pair (as 5-1 = 4 > k), whereas (5, 8) and (10, 13) can make up pair. So cnt = 2 (= n/2). As we can only add atmost 1 number, we can make a pair for 1 by adding 0. So k = 3 is feasible.
observe if we have
n==even, then we cant take the extra element as that can't be compensated by any other element while making pairs so just find the max difference b/w consecutive elements, ifn==odd, we have the choice to leave one element and find an extra new one for it, we can do this for each element and store the max diff to the right of it and to the max diff b/w consecutive elements to the left of it and take the max of both the overall answer for this case would be minimum of all such casesSolution can be seen here : https://pastebin.com/WyE4dwSL
c's gonna make me cry when i see the case im failing on
please don't write problems like B again
Actually, I think it's a very good and tricky problem. No one on my friends list got it on the first try.
after the first WA2, i waste about 50mins. at WA5 bcos i were minimizing the ans with 1e15 :(
What? It's just a standard binary search problem.
after the contest, i felt like it is somehow harder than the last div1+2
fr
Many low-rated people solved D in the last 15 minutes, I don't know if it's my skill issue but I don't think it is an easy problem. So please skip those who cheated.
no wonder, D is ChatGPT solvable. in fact, first AC was done by hardstuck gray account.
couldn't solve any thing I'm mad but at least the problems are not guessing problem
I mean I like prefix sums, but prefix sums of prefix sums of prefix sums is too much man.
AC D at 1:59 :)
AC D at 2:01 :(
I spent close to 38 minutes for problem A and got one wrong on B just in hurry of choices Struggle is real kn geometry problems
today D feels like a buffed version of 2009F - Firefly's Queries.
Which I regret haven't upsolve the problem yet...
But idk maybe I'd stuck on this anyway.
They are not similar at all.
E: Build a bipartite graph with n vertexs on the left and 60 vertexs on the right. For each 1<=i<=n and 0<=j<60, we add an edge if a[i] has j-th bit set on. For any subset of left nodes, the score is (number of chosen left vertexs )-(number of right vertexs with edge connected to chosen left vertexs ) = (number of chosen left vertexs )+(number of right vertexs without connection to chosen left vertexs )-60, then the answer is (Size of maximum independent set)-60. By the Konig theorem: In any bipartite graph, the size of maximum matching is same as minimum vertex corver, and (size of minimum vertex corver)+(size of maximum independent set)=n+60, we can calculate answer by any maximum matching algorithm.
Can you explain to me what does "set bit" mean ?
If the j-th bit of a[i] is 1. Or if ((a[i]>>j)&1)==1
Or just think of it as the classical Project selection problem.
The bits are the machines.
The numbers are the projects.
Awesome idea
That is... beautiful...
If i've submitted twice of one problem which one will be counted? If first one is hacked then second one counted?
the last submission that passes pretests will be counted
There is nothing educational about B.
B reminds me with this problem
im really confused why my binary search submission failed on B, and then my brute force one passed. obviously n is 2000, so i kinda knew it was brute force, but i didnt come up with any counter test case for my binary search one, can someone give a counter example?
try this
5
1 2 4 6 7
i get 1 on both of my solutions
Binary search would pass. I did it with binary search.
In problem E, what does "set bit" mean ?
bits that are 1 in the bitwise OR
Thank you, I thought that it the last bit which equal to 1, so I used Dp and got wrong ans
But how you become CM without knowing what is set bit. I'm not insulting you just curious to know
This is the first time I have ever knew about " set bit " word. I call it is "bit 1" :D
https://mirror.codeforces.com/contest/2026/submission/288585044
can someone help why this is wrong?
Greedy solution. Logic is that I store all the i where s[i] == 1 in a greater int set. ans = (n*(n+1))/2
I iterate over them{ count = 0; I have 2 variables l and r, I iterate over l from n->0. if I find s[l] == 0, then count++; if I find s[l] == 1 then I check on count, if it is 0 then I move more left.
When my 0s are exhausted, I move to r and only check the 1s from 1->n, if there is a 1 corresponding the I make count++, if there isnt then I break,
if there is a count then I reduce the answer by the indes of the one in the starting loop}
The algorithm I used:
In 2,3 just store the i, in these cases only, you will be saving money.
Yep I have done this only. Implementation is a bit different but yep
If
s[i] = 0, the value $$$i + 1$$$ would be added to thecostno-matter what.Go from right to left. The idea is to greedily exhaust the rightmost $$$1's$$$ with the first encountered $$$0's$$$ from right to left. If we exhaust in pairs, we will be able to remove as many $$$1's$$$ as possible.
Use a
std::dequeto store the cost generated by $$$1's$$$. Larger values are stored in the front.if
s[i] == 0,if
!dq.empty()dopop.front();if it is empty, we can pair it with the already exhausted $$$1's$$$.do
cost += i + 1if
s[i] == 1dodq.push_back(i + 1). Finally when thedqcontains $$$1's$$$, we can greedily exhaust the largest(front) and smallest(back) values.https://mirror.codeforces.com/contest/2026/submission/288593783
PD I know prefix sum. But just too heavy implemention... run out of time. :(
yea, i gave up on d too
same.
Do I understand right that problem F is just:
Code persistent queue on 6 stacks, in stacks we store knapsacks, so when answering the query we can just take left and right knapsacks and bruteforce the sum on each edge
Is large number in cpp necessary to solve problem D?
Is there a great large number template in cpp? emmmmm
nah, it is just 10 millions prefix sums
how to solve C?
I transverse the array from back to front and use deque to be able to pop front efficiently. The greedy part is to match higher indexed '1' with any first '0' found and pop it. Then, if there are still '1's remaining, just pick the lowest half.
main take away is just greedy and 2 pointers
I was knowing it was greedy and came up with this idea but couldn't implement again. Fck my implementation skills fk it
Chill mate, look at me hard stuck in pupils for 4 months already and still die trying. You peaked in specialist is a good stuff, keep going.
ahh mate I peaked there I am trying really hard right now solving 1300-1500 range alot hoping to improve soon
wrong A why cant long long ? https://mirror.codeforces.com/contest/2026/submission/288534007
0 0 68724335200 68724335200 0 68724335200 68724335200 0 0 0 68724335200 68724335200 0 68724335200 68724335200 0 0 0 68724335200 68724335200 0 68724335200 68724335200 0 0 0 68724335200 68724335200 0 68724335200 68724335200 0
wrong output format Expected int32, but "68724335200" found (test case 1)
Looks like weird behavior because of reading before and after
sync_with_stdio. Place it at the beginning.thanks
Can anyone try to hack this submission? I think greedy cannot pass this problem.
In these contests, is wrong answer on Test 1, considered as a penalty ?
I don't think so. Someone has commented about it here: Link
Thanks a lot!
Either I am getting dumb day after day, or A,B,C are actually getting difficult contest after contest.
Yesterday was Div (1 + 2) contest.
Today it is simply Div-2 contest.
I felt like today's ABC were more difficult, than Yesterday's ABC.
Nope
Today I solved ABC, but yesterday C was giving me an insomnia...
I also found yesterday's B much easier than today's A or B. Both today's and yesterday's A were a bit more complicated written than usual. Today's C was much easier (at least for me) than yesterday's C, sadly I ran out of time. :D
A had a really nice hint for the idea that
AB, CD are diagonals of a squarewith sidemin(x,y)i.e. K<=1414 , hinting the appearance ofroot of 2Problem E seems familiar
Could anyone please explain how to do B? I used binary search, but it didn't work.
just brute force the point which will be paired with a point outside the given set.
It's optimal to paint neighbors.
Miss chance to become master AGAIN by declaring $$$a_i$$$ of Problem E as
int, notlong long.Note: shifting more than bit width is an undefined behavior, so I get WA1, not WA2 or WA3, which is confusing to me.
D is very reminiscent of Mosaic from this year's IOI.
Can anyone please explain why my solution fails:
Method: For even n, directly calculate the max distance between all pairs (a[0],a[1]), (a[2], a[3]).....
For odd n, calculate min(max(((a[0],a[1]), (a[2], a[3]).....), ((a[1],a[2]),(a[3],a[4]).....))).
Submission
Consider
1 2 10 20 21Got it, thanks a lot.
Spent a lot of time thinking about E after coming up with the obvious Maximum Matching algorithm, not able to believe its actually the intended solution.
While not having a template for it cost me today's E, I am really surprised Maximum Matching was allowed to appear in E, especially when the idea that each bit should have atleast one unique entry is quite simple.
I agree that it is too much for E. But it seems to me that we have no right to complain, since this is Educ and in fact it is intended for this: you know an algorithm — 3 minutes will be enough for you, if you don't know — you are cooked for the next two hours.
"Euclidean or Manhattan" missing from "A"s statement.
If it's not specified I think you can just assume Euclidan
Are there any ways to solve problem E with dp? I tried to solve it with dp but get WA.
Let dp[i][j] represent the value of mask such that the number of 1-bits in mask is minimized when constructing a subsequence of length j with i as the last element of the sequence.
I think we can combine with some greedy tactics, such as save more than one mask for each dp[i][j] at a time.
Sorry for my bad English.
No it's not possible because even a mask where the bits might not be minimized might be better for bigger j and many other stuff
Using random to solve E: (This is gonna WA on test 2) (OMG, it's running on test 10!) (OMG, it's running on test 20!) (OMG! It ACCEPTED!!!) (I'm going to submit a lot of them to ensure I can pass main test) (passed 6/27) (ALL 6 AC submissions are hacked, rank 103->511 QAQ)
So is there a way to hack these submissions at a high possibility? Or it was just because I was to silly when randomizing? Can these submissions be hacked? 288611596 288611196
Okay, I've come up with a hack and hacked myself:(
thank you counterexample lmao, this one also breaks my code for some reason
for problem B this case
why the answer is 2 and not 1
if k=1 then we paint 1 and 2 and then we can easily paint 2 and 3 ??????????? why I'm reading the statement wrong every time ????
You can only paint WHITE cells. So, after you paint 1 and 2, cell 2 will be black, so you can't use to paint 2 and 3 since you can only paint white cells.
Seems that problem F only have operation 3 in the sample. See here
code copied from jiangly's code and add one assertion on operation 3. Only have 96 tests during the contest while the verdict is RE on 97.
My bad :( We only discovered that during the contest. Somehow all incorrect solutions we had were incorrect even on that set of data and all correct were still correct after the generators got fixed. Luckily, not a lot of people got affected by the incomplete tests.
I now got affected due to some runtime error that only fires if there's actually operations of this type in the input.
could someone provide counter example for this submission , im getting WA on test 5, and the solution seems kinda silly but it runs in O(60*n^2) in worst case scenario, and it seems correct to me. basically what i do is for every element i, lets call it valid, if for every bit that is set in in a[i], it has atleast 1 valid neighbour. first we assume all indices are valid, and then we check if there is an element that isn't and if there is such an element we delete it, and also since it may have made some other indices valid, but now doesnt anymore, we have to repeat this until no changes occur. this runs in O(60*n^2) in the worst case where we delete 1 element per iteration, and every element will be deleted, so its fast enough. but its getting WA on test 5 and i cant seem to find a simple counterexample.
nvm, got it
Educational contest educated me that I know nothing. Nothing: No, you don't know me. Me: He knows me. He: Who, are you? Who: No, I am not "?". Not: No, your not Not. No: I know.
C was easier than B, also A was weird. not a balanced contest tbh,
The pretest of B is quite weak.I solved 5 problems, but I hacked my own B successfully.
What the hell was that B question ?? After several incorrect submissions, I came to a conclusion that its a BS + DP problem.
For even numbers, it is only possible to paint them pairwise from left to right. For odd numbers, you can delete one element and solve it as even numbers.
I can't figure out why this code got WA on D. How mysterious.
Hard A. However, 3k people solve it in 5 mins. I DO think lots of cheaters in A. D is good. I need to practice more prefix sums, to find indexes faster.
Awesome contest!I am rank 3 and will become IM!
orz
Why unrated?
Ratings will change in sometime i guess..
But unrated allowed maybe.
MinusForces
problem D makes me feel like I'm not participating in CP …… All of the difficulty is to write the code. Too little about algorithm and too much about coding. Well, maybe it can help us improve our coding ability ……
problem E is also not good. If you know Maximum Weight Closed Subgraph you can solve it quickly, but if you don't know that you are hardly solve it.
I think Div .2 D and E should have good ideas without too hard code or too hard algorithm.
Isnt the point of Educational Rounds to teach these topics to a wider range of participants?
By your logic, Problem F is also formulaic for those who knows tree division — it is just to decompose the knapsack dp onto a tree. However, in my opinion an edu round is to be formulaic as it aims to educate.
In my opinion, Edu round is more important to teach participants how to solve problem rather than a specific algorithm. In most contests like ICPC, only learned algorithms is not enough, it's more important to know when to use it and how to use it.
It is acceptable to set problems like E or F. But I think problems which have more thinking instead of hard hard code or hard algorithm are better in a 2 hour edu round.
sbsbsbsbsbsbsb
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
Why can't I earn points in the last two games?