Hello Codeforces!
On Apr/22/2019 17:35 (Moscow time) Educational Codeforces Round 63 (Rated for Div. 2) will start.
Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.
This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.
You will be given 6 problems and 2 hours to solve them.
The problems were invented and prepared by Roman Roms Glazov, Adilbek adedalic Dalabaev, Vladimir vovuh Petrov, Ivan BledDest Androsov, Maksim Neon Mescheryakov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.
Good luck to all participants!
Our friends at Harbour.Space also have a message for you:
Hi Codeforces!
This summer, we want to invite you to Tech Scouts, the two-week summer camp we run from the 8th-19th of July in one of Barcelona's leading international schools, St.Paul’s.
This camp, divided into Creative and Technical tracks, is designed to lay out the foundation of knowledge for high-school students in the fields of technology, mathematics, business and design. Both tracks are taught in English.
We would love to see you guys at our camp this year — if you’re interested in joining, or if you just want to know more, just head over to the Tech Scouts website.
This camp is for anyone passionate about tech or design, so if you know someone who might be interested, be sure to let them know too!
Ps. Don’t wait too long — you still have an early bird discount, but only until May 20th
UPD: The round will contain 6 problems.
Congratulations to the winners:
Rank | Competitor | Problems Solved | Penalty |
---|---|---|---|
1 | Um_nik | 6 | 111 |
2 | Cirno_9baka | 6 | 207 |
3 | Ilovebxy | 6 | 247 |
4 | ivan100sic | 6 | 249 |
5 | ainta | 6 | 411 |
Congratulations to the best hackers:
Rank | Competitor | Hack Count |
---|---|---|
1 | halyavin | 292:-18 |
2 | Haunted_Cpp | 31 |
3 | achaitanya.sai | 30:-4 |
4 | Disappointment | 27:-1 |
5 | czasem_tak_trzeba | 23 |
And finally people who were the first to solve each problem:
Problem | Competitor | Penalty |
---|---|---|
A | iaeyoayao | 0:01 |
B | MesyuraTheOldDumbGoblin | 0:03 |
C | Nazikk | 0:07 |
D | JettyOller | 0:07 |
E | Rezwan.Arefin01 | 0:17 |
F | Um_nik | 0:59 |
UPD: The editorial is out
Good luck to everyone tomorrow! Nice time by the way!
Why does awoo sets problem mostly for educational rounds only ???
Hope to we all have a good luck , with no hacked submissions!
It'll be held at 22:35. I've never stayed up late for a contest XD.
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
Good Luck Everyone :)
Give me that +12 rate change:)
How about +12 up votes?
Granted.... Oops -83
Get to expert then we will talk about it/ until then shut up and keep my rate change out it Eminem after learning c++
m2.codeforces shows 500:Internal Server Error. m1,m3 also not working. Please fix.
halyavin is here.
.
Hmm, I will just leave the link to one of my comments here.
UPD: posting such articles or links during the contest is unacceptable behavior anyway.
It is bad to post it during the round. But also it is not the same problem :)
How to solve E, are there some observations or it's an application of some algorithm?
I was thinking it could be solved by solving System Linear Equation with Gauss Jordan with modules. But I failed in the implementation...
I checked x=0,1,2,3,4,5,6,7,8,9,10. And then calculated all values using Lagrange interpolation.
It could be simpler. Its just check x = 0,1,2,3,4,... 10 and find the coeficients (like you did) and then eval the function over [0, Mod — 1]. AC = http://codeforces.net/contest/1155/submission/53163325
Lagrange interpolation is actually the method to calculate coefficients.
A $$$N$$$ degree polynomial is uniquely determined by $$$N+1$$$ distinct evaluations. You can ask $$$P(0), P(1), \cdots, P(10)$$$ and then interpolate. Then you can find the root in $$$O(mod)$$$ by checking all numbers in $$$[0, mod - 1]$$$.
So, the interpolation would return the coefficients and then we bruteforce over all the values for the function we've found?
Technically $$$O(mod \log mod)$$$ for me bcz my interpolation involved finding the inverse of each $$$n$$$ with $$$0<n<mod$$$.
My interpolation required inverse of numbers in $$$[0, 11]$$$, which you can precalculate in $$$O(1)$$$ using $$$inv(i) \equiv -(M / i)\cdot inv(M \mod i) \pmod M$$$:
Calculating inverses of all elements in modular ring can be done in $$$O(mod)$$$. Refer last section of https://cp-algorithms.com/algebra/module-inverse.html .
Just ask for $$$f(0), f(1), ..., f(49)$$$, pray there is some recurrence like $$$f(i) = \sum_{j} a_j \times f(i - j)$$$. and find it using Berlekamp-Massey. Then you can calculate all $$$f(i)$$$ for $$$0 \le i < MOD$$$. The existance is proved here.
I used little Bézout's theorem. For any $$$a$$$ we have $$$f(x) = g_1(x) \cdot (x - a) + f(a)$$$, where $$$g_1(x)$$$ is a polynomial with less degree. So if we know $$$f(x)$$$ and we have asked for $$$f(a)$$$ before we can calculate $$$g_1(x)$$$.
You can continue, say $$$g_1(x) = g_2(x) \cdot (x - b) + g_1(b)$$$, and so on, remembering the remainder on each step. After a few iterations (about $$$10$$$) $$$g_i$$$ will become a constant function.
If we know $$$g_{i + 1}(x)$$$ we can easily find $$$g_i(x)$$$. So, since we know that for big enough $$$i$$$: $$$g_i$$$ is constant, for any $$$x$$$ we can caluclate $$$f(x)$$$ by going backwards through these functions.
Now just iterate through all $$$0 \le x < 10^6 + 3$$$ and check if $$$f(x)$$$ is zero.
What is the solution to F?
http://www.cs.utexas.edu/vlr/papers/mincon.pdf
It's "minimal", not "minimum". "minimum" is NP-hard, hence the limit.
Sorry for my english, but what is the difference between "minimal" and "minimum" in this case?
Thank you!
It is a mathematical notation.
For set $$$S$$$, a subset $$$X \subset S$$$ is "minimal" set satisfying certain property if there exists no other subset $$$Y \subset S$$$ such that $$$|Y| < |X|$$$, $$$Y \subset X$$$, and satisfies such property.
For set $$$S$$$, a subset $$$X \subset S$$$ is "minimum" set satisfying certain property if there exists no other subset $$$Y \subset S$$$ such that $$$|Y| < |X|$$$ and satisfies such property.
DP on subset of vertices. Note that 2-edge-connected graph admits an ear decomposition. Thus, the base case is where the graph admits a Hamiltonian cycle. For the inductive case, you split the set into two parts: One for the new ear, other for the minimum biconnected subgraph of remaining sets.
The time complexity is $$$O(3^N \times N^2)$$$ because you enumerate subsets for each subset. My code is pretty slow, and I think it could be done faster, something like $$$O(3^N \times N)$$$.
I think you can precalc bunch of stuff in $$$O(2^{n} poly(n))$$$ and then get $$$O(3^{n} \cdot \frac{n^{2}}{64})$$$. My solution from the contest also works in $$$O(3^{n} n^{2} + 2^{n} n^{3})$$$, but the constant factor in first part is very small ($$$1/54$$$ easily), I even think that precalc is the slowest part of my solution (I store all the paths for some reason, so it is $$$2^{n} n^{3}$$$ pushbacks, you don't need it actually).
Randomized solution also works. If we fix the DFS tree of the graph, it is easy to choose minimum number of back-edges to make the graph bi-connected. (It can be done by simple dfs+greedy, in O(N+M)) So, we run the following iteration as many as can: 1. make a random DFS tree of the graph. 2. run greedy on that DFS tree to find minimum edge set. then print the best solution.
Here's my solution:
For each subset of the set of vertices, try finding a simple cycle which contains only those vertices, this can be done in $$$O(n^3 2^n)$$$. If there is a Hamiltonian cycle, then it is the solution. Otherwise, pray that there aren't many subsets of the set of vertices such that they form a cycle, and then do DP on them: I assumed that the solution will always be a union of such cycles. (I didn't prove it but it makes sense). The complexity of this part is $$$O(\frac{n^2 2^n C}{32})$$$ where $$$C$$$ is the number of cycles.
Code: 53156325
Problem D case 5?
Any hints for E?
Finding the constants of the polynomial by solving linear equations (notice or google that 10^6+3 is a prime so it forms a field Zp) and then brute forcing on the polynomial as the degree is <=10 .
How to solve D ?
dp[i][0..2] mean haven't multiplied by x, have been multiplied by x, have multiplied x. So we have follow:
dp[i][0]=max(dp[i-1][0]+a[i],a[i])
dp[i][1]=max({dp[i-1][0]+a[i]*x,dp[i-1][1]+a[i]*x,a[i]*x})
dp[i][2]=max({dp[i-1][1]+a[i],dp[i-1][2]+a[i],a[i]})
the answer will equal to one of the dp array
I think the last transition is wrong. In dp[i][2] you can't start a new segment. EDIT: Well, it is correct I guess, as the problem allows not multiplying x at all. But it is wrong for the dp definition.
You are right, but the value won't be wrong because the dp[i][2] value was equal to dp[i][0] at that time
Brilliant approach, thanks! It helps me a lot.
I let dp[i][j][k] mean now consider the i-th number if j=1 that the i-th number doesn't * x if j=0 that the i-th number *x if k=1 that there is an area *x before if k=0 that there isn't an area*x before so we can find that
My Segment Tree solution was overkill, as it was a DP problem. Because I'm jobless and narcissistic, I'm explaining my solution anyway.
Given numbers $$$a[0] .... a[n-1]$$$, let us calculate $$$upto[i]$$$ and $$$from[i]$$$ which would give you the maximum sum of the subarray the ends at position $$$i$$$, and starts from position $$$i$$$ respectively.
$$$upto[i] = max(0, a[i], upto[i-1] + a[i])$$$
$$$from[i] = max(0, a[i], from[i+1] + a[i])$$$
The first observation is that if we decide to apply the operation from $$$a[L] ... a[R]$$$, and it was optimal then $$$answer = upto[L-1] + (a[L] + ... a[R]) * x + from[R+1]$$$
Let us define a function $$$ f(l, r) = upto[l] + (a[l+1] + a[l+2] + ... + a[r-1]) * x + from[r]$$$. The required answer is the maximum of $$$f(l, r)$$$ for $$$l < r$$$. If we attempt to solve this naively by precomputing $$$upto[]$$$ and $$$from[]$$$ and prefix sums, then this can be done in $$$O(n^2)$$$, which is too slow.
Let us define $$$g_r(l) = upto[l] + (a[l+1] + .... a[r-1]) * x$$$. Here $$$f(l, r) = g_r(l) + from[r]$$$.
Obviously $$$g_{r+1}(l) = g_r(l) + a[r] * x$$$ for $$$l != r-1.$$$
If we keep a segment tree that supports range-max queries and range-sum updates to represent $$$g_r$$$ for different values of $$$r$$$. Initally all the values are 0. This represents $$$g_0$$$. For each r = 0 to $$$n-1$$$, do the following:
If you get the boundary conditions right, then you have found an overkill $$$O(n log n)$$$ solution. See my submission 53151609 to know more.
My solution is exactly similar to yours.Infact i missed by C because of this tedius implementation of D
You have my commiserations.
How to solve 4th one?
My approach :
Let ans = kadane(original array)
If x >= 0 && all A[i]<=0 then answer is 0
If x >= 0 and all A[i] are not negative, then find subarray with max sum, multiply with x. Now ans = max(ans, kadane(modified array))
If x<0 then find subarray with most negative sum, multiply with x, Now ans = max(ans, kadane(modified array))
I have applied the same logic ,but its failing in test case number 10. Code Link Can you please find the error.
Run for this case
5 -1
-5 -2 6 -3 -5 Correct answer : 14
DP! I passed it! But I TLE at the 3th problem
Try this:
5 0
-1 2 -6 4 -5
When x is 0 your solution fails as you can "erase" a negative subarray by multiplying it by 0 and combine its adjacent maximum subarrays, but that negative subarray is not necessarily minimal.
I thought $$$O(k! + 10^{6} + 3)$$$ solution for problem E. Use gaussian elimination for polynomials $$$f(x) = \sum_{i=0}^{k} a_{i} x^{i}$$$ for all $$$x$$$ in $$$[0, 11]$$$. I was stuck at D so I couldn't implement this solution in a rest of time. Any better ideas or approaches for E?
I solved E using Lagrange Interpolation. Also I have just seen a solution with Berlekamp Massey.
I think you meant $$$O(K^3 + MOD)$$$ since gauss takes $$$O(K^3)$$$.
I thought unoptimized approach only during contest :(
I'm seeking someone who debugged their problem D code after getting WA on test 10. What kind of input could be there on test 10?
4 -1
100 -100 90 -101
Try this:
5 -1
-5 -2 6 -3 -5
You are printing 9, but the answer is 14. This case lead me to DP.
Problem B.
Please, can anybody show me where is the mistake in my code?
And counter test if possible. https://codeforces.net/contest/1155/submission/53136294
Can you explain to me your idea?
Let x = (n — 11) / 2 Going from the start and marking first x eights (if possible) and first x non-eights (if possible) Then one more time going from the start and the first not marked element is the answer (if 8 then YES, otherwise NO).
you have a mistake because if cnt8 == 0 and s[i] == 8 then you will try to remove it with a cnt1 value. But this is a waste since obviously player 1 does not want to remove 8 values.
Thanks. I have absolutely no idea how I could forget about this. It costs me 1.5 hours of smashing the table and rating of course. Maybe today I was tired. I do not know. Thanks...
What if s[i] == '8' but cnt8==0? If cnt1 is still positive, you will erase an 8
Thanks. I got it.
Logic for Problem C: I found the difference between first two elements. Then found the least factor which is divisible by the difference. Then decided the answer on the basis of this factor. Code Link
Can u give a test case where it is failing.
You have to have the GCD of every two consecutive differences. Test: 5 2 1 3 5 6 7 2 3 Your anwser is: Yes 1 1 Correct: No
Output is, YES 1 2. I don't think its failing in this case.
Thats a wrong test case, but your code is wrong.
for(i=2;i<n;i++) { ll diff=x[i]-x[i-1]; if(diff%factor!=0) break; } if(i==n) { cout<<"YES\n"; cout<<x[0]<<" "<<pos+1<<endl; return 0; } i will never be == to n bro...
your code will never check the last difference, thats your mistake
consecutive difference is not necessary you can have difference of first with every element and just calculate gcd of all element.rest of the logic is same...
this is pretty much the same ...
3 2 2 8 11 2 3
Correct output:
YES 2 2
Your code output: No
Thanks for the test case.
53163062 could any one help me with my solution on C? i don't know why i got wrong answer in 11; i think logic is fine.... help me please.. i'm stupid...
You have declared
temp
as int.wow you're genius thank you !!!!
wow!
Ну ты и петушара (translate from Russian)
I found this interesting solution, is this allowed vovuh? The code is not visible, so how does someone hack?
it means they will be disqualified, this has happened before
This is not allowed.
See point no 16 of https://codeforces.net/blog/entry/456
Can you please explain your solution of D?
1) don't take any 2) started subarray multiplication with x 3) multiplied some subarray already with x
how did it even get AC.
It is not allowed. The user will be disqualified from the contest.
https://codeforces.net/contest/1155/submission/53152525 Problem B Why does this give runtime error ?
If I simply change the values to some letter, let's say 'a' instead of erasing a number, I stop getting runtime errors but I get TLE.
you should will never stop with undefined behavior while(*****s[j]=='8'*******){ j++; } s.erase(s.begin()+j); ////////////////////////////////// while(******j < s.size()******* and s[j] == '8')++j;
Does anyone have test hack for D ?
5 -1 -5 -2 6 -3 -5
Ans : 14
My overkill solution 53155985 for D is using sqrt decompopsition. I divided the array into blocks and then handle two cases:
1: The endpoints of the multiplied subarray lie in different blocks
2: The endpoints of the multiplied subarray lie in the same block
Did anyone also solve it using this method?
I found what looks like cheating to me.
Submissions 53159161 and 53158255 which are made by different accounts are exactly the same, and submissions 53139289 and 53139670 made by the same two accounts are exactly the same except for an extra
return 0;
line which is commented out in one of the submissions but not the other.How do you find these submissions? Are you running a script for this?
I was manually looking through submissions one by one trying to find hackable ones.
what the moo Bessie why are you asking poor high schoolers to solve your relationship problems with my boy Farmer John when you can code the solutions yourself
I tried to solve C(alarm one). My code is as follows https://codeforces.net/contest/1155/submission/53159102 . I solved it in O(n) but still got some runtime error! PLease help
Runtime Error is because you didnt use long long.
You wouldn't get a runtime error for not using long long. You would get a wrong answer when int overflows. In this case the runtime error is because he is using 2 arrays of size 300001 inside main. You should declare those outside of main.
aisa kyu
The stack space isn't sufficient to allocate so much memory. Global space is much more so you should always declare your arrays outside of main.
Have a look at this and this submission .. ment intentionally hackable and there are many more of this kind
imaginative
I'm new to codeforces, does open hacking means there will be no points for hacking?
Yes.
How to solve E?
Can anyone offer some help as to how Gaussian elimination (and/or Lagrange interpolation) generalise to when the system of equations (and/or set of points on a polynomial curve) is taken modulo a prime, as in today's problem E?
I've been trying to get my head around it but there doesn't seem to be anywhere on the internet addressing it — https://cp-algorithms.com/linear_algebra/linear-system-gauss.html for example asserts 'we can still use the described [Gaussian] algorithm' but I don't see how this follows.
All we use when defining Gausssian elimination and Lagrange interpolation and when proving their correctness is that we can add/subtract/multiply numbers and divide by numbers that are not zero and that these numbers follow the standard rules (e.g. distributivity). As such, these algorithms work over any [field](https://en.wikipedia.org/wiki/Field_(mathematics)), not just over the real or rational numbers. It is a well-known fact that Z/pZ with p prime is a field.
Ah okay — so when changing the cp-algorithms Gaussian elimination implementation for the modular system case, we can just adjust the division of a number with multiplication with that number's inverse (mod p)?
Yes, that is correct. In fact, your code may become a bit simpler because any non-zero diagonal element will do, whereas you want to choose the largest diagonal element in the floating-point case for stability.
Thanks very much — I think it's clear I need to get my head around the correctness proofs etc. better before implementing something, but once I do I'll keep that in mind :)
Spoilers:
first guy:why my rate hasn't change
second guy replies:the system didn't start testing
third guy: why the system didn't start testing yet !.
Problem D felt
Please update ratings and add tutorials, can't wait.
During the contest, my solution for problem B passed the pretests. But, during the system testing, the judge is giving "Compilation Error" as verdict. How is that even possible? Kindly look forward in the situation.
My solution for problem D is taking wrong answer on test 5.But i can't understand why.Can anyone help me pls?(Sorry for my bad english)53179364
4 -1 100 -100 90 -101
answer is 290
thanks for that.still i don't know how can i fix it but i understood my fault
Thanks for the contest. I'm finally Purple Now :D
I'm so confused that I was told I have to be skiped due to my solution for E 53159928 is coincides with solutions 53156214
I'm sure that I just use a third party code Gaussian elimination ,the opensource code is posted in 2018/08/26.
According to Rule about third-party code is changing
Solutions and test generators can only use source code completely written by you, with the following two exceptions:
the code was written and published/distributed before the start of the round,
the code is generated using tools that were written and published/distributed before the start of the round.
Except the opensource part of my solution,the left part is just two loop and the use of function,I think most of the people who pass the problem E has the familiar writing style in this part.
So MikeMirzayanov and awoo is it my fault or careless about the use of third party code?
Sorry.
That's not your fault,you don't need to say sorry
Hesitating will be defeated!
You mean resolute lead to AC ? : (
Decisive will be useless
Such a notorious coincidence that your submissions were the same on D as well. 53150449 vs 53147765
Isn't it you don't noticed that my solution of D is similar to lots of people you clever boy?
If you want to say something,just do it,don't beat around the bush : )
Okay look here. You are currently complaining about getting caught while literally sharing the same code for every problem this entire contest. Just stop.
a: 53128023 vs 53127195
b: 53131283 vs 53129702
c: 53137382 vs 53134674
d and e: see above
Oh Man,have you ever look for some other ABCD's solution is similar with mine which is wrote in c/c++,that's plenty of the similar code about the ABCD So that's your evidence that I'm a cheater? And how can I cheat other people 's solution? Why not @buxing201606 to join the judge? What you said above is just personal affront to me
"have you ever look for some other ABCD's solution is similar with mine which is wrote in c/c++". In fact, I have. I took the first 10 or so accepted solutions for problem C written in C++11. Even if they all implement the same idea, let's take a look at how they differ from your code.
As you can see, all of these implementations differ form yours (in more than 1 aspect), even though they implement the same idea. Subtle differences WILL naturally appear in codes written by different people, even if they express the same thing.
In fact, the probability that two codes are EXACTLY the same (modulo headers, indentation and variable names) is extremely low, even for a simple problem. The probability that all codes are the same for ALL problems during the contest is so small it's not even worth considering.
If you want to "steal your own hat" and cheat, that's fine by me. But the fact that you then come to the blog and complain about being caught, acting innocent, is quite frankly an insult to the CF community.
You can read what I said just before,I just learn some skill from the blog I said below,I don't think the header can be seemed as evidence,maybe,I say maybe,buxing201606 is also a learner from the blog I said below. That's all that I know
What you give us seems the true,but even if everyone don't trust me,I know I'm innocent.
What you said about ABC I think it's not strong enough to prove your opinion.
But,actually myself also think the solution and the writing style about the problem D is so similar. I don't know why buxing201606 has the same simplify operation about getmax function,what can I say is just where I learn this function.
Once I search some solution in the web,I found this blog blog of notnight,and the simplify operatin is just modify from it.
I'm a retired ACMer(retired just last year),I bet my honor as a programing competition participant to say,what I said above is all that what I know about the whole case.
That's my last reply to you,no offend,best wishes in your programing competition days.
I really didn't know him before, and I didn't share my code with others during the contest. The template for Gaussian elimination is copied and pasted from someone else's blog. I searched for Gaussian elimination on the search engine. The first blog is this.
Did you also copy-paste from a blog the solutions to the other 4 problems which you guys solved with the exact same code?
Seriously, I don't know what you two are debating here. It's obvious that (at least) one of you cheated. It's like a kid telling you they didn't eat the cookies, with crumbles around their lips.
I don't even know who you're tying to sell the story to. Mike won't take any action (as it's been shown before), I myself couldn't care less, and neither does anybody else: you are the ones who started the topic in the first place. Just let it go and save yourselves the hassle.
It is not a question of using third-party code. I do not have time to debate on this issue, I once again carefully looked at and studied all the arguments. My decision remains unchanged. A large number of suspicious coincidences do not leave it to be considered an accident:
Probably, there was an unintentional leak, which is also violation. I suggest you both to change passwords and use only https in the future. Good luck.
Thanks,got it.
Editorial link????
I wonder why I got AC from this random solution that I made for problem B. Can anyone explain it to me?
I define
F8[i]
as the number of digits 8 from the 1st to the ith character.https://codeforces.net/contest/1155/submission/53148643
Can anyone tell me how to use dp in D question....? i am new to competative.. and how i recgonise that dp is use or not... is there any trick or it comes with practice... any related question to that so that i can practice.
https://codeforces.net/problemset?order=BY_RATING_ASC&tags=dp
thanks @lakshay_nasa.
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
oh my, halyavin 292 successful hacking attempts? What?