Hello Codeforces!
On Jun/25/2020 17:35 (Moscow time) Educational Codeforces Round 90 (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 or 7 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 the participants!
Congratulations to the winners:
Rank | Competitor | Problems Solved | Penalty |
---|---|---|---|
1 | Geothermal | 7 | 130 |
2 | ksun48 | 7 | 143 |
3 | 300iq | 7 | 147 |
4 | vepifanov | 7 | 168 |
5 | Radewoosh | 7 | 175 |
Congratulations to the best hackers:
Rank | Competitor | Hack Count |
---|---|---|
1 | EduPeres | 40 |
2 | Grey_Matter | 39:-3 |
3 | lx430621 | 26:-1 |
4 | killa_vanilla | 25:-5 |
5 | checkingagain | 17:-1 |
And finally people who were the first to solve each problem:
Problem | Competitor | Penalty |
---|---|---|
A | Geothermal | 0:01 |
B | ksun48 | 0:01 |
C | ksun48 | 0:03 |
D | Noureldin | 0:09 |
E | Geothermal | 0:22 |
F | ElOrdyh | 0:15 |
G | dario2994 | 0:29 |
UPD: Editorial is out
The best educator of them all!
Unfortunately, I am not sure that vovuh is back :(
This group of people is always the creators of Educational Codeforces Rounds. For example, you can check the last one -> vovuh was among them, but was not mentioned in the tutorial
He also said he would return with a div 3 round in this comment
He is coming with a DIV.3 round :)
why vovuh is popular ?
(From this contest editorial)
I'm done with memes. No more memes from now!
Still waiting for official Editorials. Problem setters should make editorials along with problems.
yeahhh!! vovuh....big fan...so much excited!!
can somebody explain me the way of scoring in educational rounds? I think you will only get scores due to the number of solved problems regardless of their difficulty. am I right?
Yes. How many AC, then how many minutes (penalty).
And bye how many minutes do you mean the total time spent to achieve the score or in some other way?
If you solved any problem in 40 minutes.Then your penalty+=40.and every wrong answer penalty+=10 Generally..If both solved same no of problem then standing will be sorted with penalty.
algorithmic reply...lol
I did not find any "lol" thing here
Good to know, I have participated in a few educationals but did not know this one. :O What I noticed about them is that they tend to be harder than normal Div2 rounds.
Can you please tell what's the difference between educational and div-2 round? I'm new here.
which means
![ ](
Bruh Bruh Bruh Bruh
Seem like an Educational round's announcement is incomplete without someone reposting this meme.
Just curious, in educational rounds announcement, why its mostly written like "6 or 7 problems". Is the number of problems and problems itself not decided till few hours before the contest? Or is there something, which I am unaware of?
I think entire blog is almost copy pasted, maybe so
Typical Indian households
fucked up my contest today, couldn't solve even one question.
Sonic_Master Everyone has their bad days. :) What matters most is you upsolve those problems.
True AF
That's why it seems peaceful to do contest in hostel room.
If you feel peaceful to do a contest in hostel room, you got no hostel life probably.
Possible if and only if all roommates are contest programmer.
Damn, right in the feels.
It's way better than what I experience almost every time.
Or when they don't talk to you for the entire day, but the moment your contest starts, they decide to hold a party in your room.
So true, XD
xswl
:D
HTML IS A PROBRAMMING LANGLUAGE!
It's a hyper text MARKUP language.
Nikita will leave you
and the earth is flat
Pretty excited for this contest !!
![ ]()
hope to get a decent rank this time
I have one question!, Know the Educational rounds are more than the div1 and most of the Educational rounds have 6 or 7 problems It is a good idea to add one hard problems and make educational to div1 ? :)
Good idea, but they wont accept. We are doomed =(
But there may be room for discussion. :|
Of course. I would be so happy if they accept.
Educational round is nice but div1 contest is rated for 2100 <= and it is a Competitive for 2100 <=
When I find People Cheating in Rated Rounds
But after seeing that there code are same even comments are same my heart like "OOOH LALA";)
Excited for vovuh div2 round after a long time.
Good luck everyone
More than 20k people registered for this contest! Looks like it will be a fun contest.
Having fun? :p
No. Spent too much time in C and still couldnt figure out simple logic. Then moved to D and solved it. Rating will go down steeply :(
how to solve D?
(https://ideone.com/NT3pbQ) This is my code for D which got accepted
Main Logic is quite similar to Kadane's Algorithm of Max Sum Subarray. Just a small modification.
Who is this
vovuh
and why are people so excited about him?Spend some time on cf giving contests regularly and you will be able to answer this yourself.
He is the chosen one who sends all undeserving people like me from specialist to expert.
If I get WA1 on A and I can't proceed with the contest, will my rating drop?
Yes
Nobody:
Problem A in every Educational Round ever:
1 < t < 1000
1 < a, b, c, x, y, z < 10⁹
Seriously?
</almost copy pasted part>
Of all bad and misworded As, today's A was the worst.
Again B is easy than A -_-
Actually, in Educational round it doesn't matter at all)
matter brother..If a,b swap then my penalty only for A B will be (6+17)=23..But now it was (11+17)=28.
If everyone finds A difficult than B, than it is actually difficult, and if everyone else finds it difficult, then all would take time to do that question and eventually your rank would be good even though you had more penalty
And currently, mine is $$$(6 + 7)$$$ = $$$13$$$, but if they would have swapped $$$A$$$ and $$$B$$$, it would have been $$$(1 + 7)$$$ = $$$8$$$. But that doesn't matter much, rating would have been affected by $$$1$$$. Focus on improving skills brother!
idea was simple but problem statement could have been worded better
OK, E is above my level. Go to bed instead.
I would suggest don't give up and keep trying :)
and what are you doing ?
Trying to motivate others. That's a good thing to do I guess. What are you doing?
I am also trying to motivate others.
If you read my comment properly, I was trying to embrass you so that you go and focus on your work.XD
Bruh
I am feeling that nowadays competiton is increased so much, not able to secure rank under 2k from past 3-4 contest.Contestant now even solving problem D like B, please tell me what do you think.
i feel the same way, contestants are doing much better recently
todays div2D<<usual div2D
I wonder how people solved C that easily :/ it was really hard for me
Off-topic:suddenly notice , after a long time you change your profile picture..
I wanted to put it after I reach expert but I guess that will take a long time .. I'm so disappointed about my performance
don't worry brother..be continue your practice your desired day come quickly.Wished you Good luck <3
i got WA and spent so many times to realize ans can't be store in
int
Thats were im wrong too but i changed the int to long long in the last 8 minutes of the contest
I think with enough practice on this types of problems, it would become intuition. I used to find these types of problems really hard, and after solving and understanding them they become easy to solve.
How to even think about the problem E.
Yeah man, the difference between D and E was huge today.
Yeah true I was trying to apply digit dp for 1 hour in the contest .XD and than after the contest i saw that people did it with brute force ...facepalm.And so it became typeforces for most experts.
My solution for problem E: https://mirror.codeforces.com/contest/1373/submission/85070127
The key insight is that K<=9 so you can only overflow at most once. For example if you pick the last digit to be x%10=7 with K=5, then it must look like this:
So for every fixed starting digit and K, the sum of all digits is:
Where front is the variable we want to solve for and the rest are constant.
If numOverflow is 0, you can solve for:
If front doesn't end in a 9, you also know that
sumOfDigits(front) + 1 == sumOfDigits(front + 1)
, which again lets you solve forOnce you know a target for the sum of digits of front, you can greedy it.
This isn't complete because I didn't cover all the cases, but I am guessing other cases are impossible via proof by AC. :)
You can check out how to come up with the solution here :D
Did 0 based indexing ruined time in anyone's D?
Yeah bro I also initially wrote code for 1 based indexing and after checking for test case 1 I felt something is wrong & and read the question again and realised that it is 0 based indexing
I had a hard time trying to crack C, can anyone please explain me their approach?
void solve() { int n,i,j=-1; ll ans=0; string s; cin>>s;
}
Why the prefix sum array? Just maintain a variable.
Got it thanks for correcting me.
You are not wrong! It is just a tip!
How to solve E?
Thanks in advance
Here is a detailed explanation for the problem
Test case 3 for E?
Nevermind, figured it out:
Sometimes it is optimal to put an 8 as the first digit after the 9s and 1s digit, rather than the remainder of the excess sum divided by 9.
How to solve problem D?
The video editorial for the D problem . Please subscribe to our channel :)
$$$O(1)$$$ solution for E.
How did you generate those values?
For $$$k = 0$$$ greedy algorithm. For other $$$k$$$ just check all $$$x$$$ from $$$0$$$ to $$$10^{9}$$$.
That means you checked for all values in your laptop, really clever idea
Yea. Precalc took ~$$$1$$$ minute.
Wow, I couldn't find $$$ans(150, 1)$$$ for twice as long XD
1e9 operations per second or what?
You can iterate by $$$x$$$ from $$$0$$$ to $$$10^{9}$$$ with fixed $$$k$$$ and store the sum of digits of numbers. If this sum appears first time, you found the answer for this sum and our $$$k$$$.
This huge brute forse is needed only for $$$k=1$$$, for other $$$k>1$$$ it is enough $$$10^{6}$$$ candidates.
To speed up the whole brute force, you can do transition from $$$x$$$ to $$$x+1$$$ by $$$O(1)$$$ instead stupid $$$O(log(x))$$$.
So, it's only 1 loop from $$$0$$$ to $$$10^9$$$, I get it. At first I thought you did that for all $$$k$$$, hence the question..
How did you map all the values, did you get any online tool to calculate that ?
How did you generate values?
Is that allowed? Or would it be considered cheating
I mean it isn't technically cheating, more of a hacky solution
It is not cheating at all.
Why do i hear your comment in petyr baelish voice in my mind XDXD
Meanwhile setters: Am I a joke to you.
FBI wants to know your location
Codeforces be like :
Can you prove it?
How to solve E?
I used — if (k >= 2) then apply brute to find an optimal answer, and greedily solve for k = 0,1 but got stuck at T-3
you can find a detailed explanation here in the video
nice explanation brooo
I ended up using Kadane's for both D and F; I feel like it made sense for D, but was there an alternate solution to F that I missed?
Or prefix sums while maintaining min
Isn't that exactly what Kadane's is?
Yes same thing but i used different implementation as Kadane's requires max and current sum
Can you help with some intuition on, how to solve F with kadane's ? Thanks
So, not sure if it is correct, but this was the idea I had: if you consider the bipartite graph of households and connections (NOT cities and stations, i.e. the first sample has 9 households and 9 connections), and have an edge between a household and a connection if their city and station are adjacent, then the problem becomes finding whether or not this graph has a maximum matching equal to number of households.
The problem is that this graph is way too big to construct (it can have 2e15 nodes), so you need to use some general arguments. First observation is that if there is any subset $$$S$$$ of households such that its neighbor set is smaller than $$$|S|$$$, then it is not possible. If all subsets $$$S$$$ of households have neighbor sets that are greater than or equal to $$$|S|$$$, then we claim that it is possible. I didn't prove this, but it sort of feels like the proof will be similar to Hall's Marriage Theorem if it is true. Someone can correct me if I am wrong about this.
Now, we obviously cannot check all subsets. However, we notice that if we are trying to find a subset $$$S$$$ such that the size of the neighbor set is smaller than $$$|S|$$$, we will always be able to use all the households from some contiguous set of cities (why? go through the proof, it's a good exercise).
So, we are trying to find some contiguous group of cities such that the sum of their households is less than the sum of corresponding network connections that cover those houses. I'll leave this as another exercise to make the connection to Kadane's. You have to do quite a few modifications to the algorithm.
I will definitely try to use the hints and to solve this problem. Thanks
How did you know it is guaranteed that the sum over all connections is equal to the sum over all households? I mean, the samples do match the argument but how were you so sure so as to proceed?
Not sure I totally understand your question. The sum of all connections isn't necessarily equal to the sum of all the households; in test 3 on the sample case the sum of connections is greater than the sum of all households, and it is still not possible.
Oh, I misread your comment earlier. I thought it was perfect matching you were talking about. Now it makes sense, thanks.
Using you hint i tried to solve this with kadane's kind of approach, But its getting TLE on test — 9. Can you please help me figure out why is this getting TLE ? https://mirror.codeforces.com/contest/1373/submission/85147824
Thanks in advance for the help.
I fixed your solution by adding one nifty line at the beginning of main:
85152881
The idea is that cin is actually quite slow at reading in input, and this only really matters when you are reading in something on the order of ~1e6 elements. It's generally accepted practice to include this line at the beginning of main, or otherwise use scanf for all your reads. If you look at the top 5 people in the standings you'll see they did this.
If you add this line, though, you should NOT use scanf/printf while also using cin/cout. Choose one and stick to it, because the addition of this line essentially allows these operations to occur asynchronously and it will totally mess up your program in certain instances.
Thanks a ton for the help. I will remember this from now own.
Feels so good to to see it getting accepted.
my solution: i simply assigned all of the capacity of the i-th edge to the i-th node and greedily give the next node the cumulative excess capacity while paying attention to the capacity of the edge. i traversed through the graph twice since it is a cycle and checked for validity on the third pass. 2 passes might be enough but i was being safe and did not want to waste time on checking for correctness. in all honesty i am surprised this simple solution worked.
edit: fst :(
What was test case 4 in problem D? ;-;
i also got stuck in testcase 4 of D, but it is just integer overflow, i did't realize it until the last fifteen minutes.
oh sorry it was testcase 3
you can find a detailed explanation here in the video
I almost took 90 min to solve A question. Soo confusing.
My brain: 30 minutes on A and 20 min on B+C -_-
did anybody get a flow solution to pass for F?
I completely ignored flow because the limit was so large. Is it possible to pass?
worst case runtime of Dinic is very bad, but it's very often misleading, since it can run wayyyy faster on certain types of graphs. On bipartite graphs, Dinic runs
in O(sqrt(|V|)|E|) time in the worst case(edit: jk this is wrong, it still runs quick though), so I thought it was worth a shot. I think you can derive a solution by analyzing the augmenting paths of the graph.I know that when Dinic's algorithm is applied to bipartite matching, the time complexity reduces. Its called Hopcroft-Karp algorithm. However, I have no idea when it comes to just finding a maximum flow on bipartite graph, not matching. AFAIK, the major reason why such bound holds is because the capacities are unit, which is not the case for this problem.
https://en.wikipedia.org/wiki/Dinic%27s_algorithm
in bipartite matching, you have both unit capacity edges and a bipartite graph. each of those restrictions individually can speed up Dinic, since each allows you to find blocking flows very fast, which reduces the number of iterations you have to do on the graph.
edit: oh i see what you mean, the runtime i posted above doesn't always apply. AFAIK it still is true that it runs fast on bipartite graphs though.
Its memory limit gets exceeded anyways with Push Relabel (with gap heurestics). https://mirror.codeforces.com/contest/1373/submission/85062675 (Total 2 * n + 2 nodes are needed to model the problem into flow, with capacity taken in long long).
Is think explation in C and D can be useful in figuring Problems more easily.
How to solve D ? give some hints
Hint kadane's algorithm.
you can find a detailed explanation here in the video
For me today B < A and D < C.
No way C is more difficult than D, unless you coded some weird solution.
It took me more time to figure out correct solution for C than D.
According to me
b < c < a < d
problem A just ruined my contest ;(
Always 'A' makes me so Panick...
Was staring at problems for 1hr 12 minutes. Zero solved! And then solved D->C->B->A. Honestly This was the difficulty for me. As soon as I saw D I got the solution.
I wonder how are you still green?
F*uck int, F*uck integer overflow, int data type should be removed from C++, got AC on D just after the contest
You better think before writte int or long long.
But isn't 'overflow' in your name?
Hahaha I did not notice it.
I always use long long no matter whether it should be.
Though long long is slower than int and some kinds of problems will return TLE when you use long long instead of int, but the timelimit on CF is far more loose, so I just use long long every time to avoid the integer overflow.
BTW, I'm very sympathetic to you, I can understand your feeling because I had many times when some stupid mistakes blew my whole contest up just for dropping 50+ ratings.
I have same feeling with you
Also, I got WA in D because of int. Yes, data types can cause havoc.....
Was not able to solve C..any help?
maybe you need long long
How do you solve D? I came up with O(N*N) DP but it will TLE and I have no idea how to optimise. One observation I have is that there is no point in reversing a subarray of odd length as it'll yield the same sum. My DP solution was to go through all possible lengths of even subarrays and find the maximum value that can be obtained as sum at even positions upon reversing that subarray (which I do in squared time). Also, E seemed very interesting but apart from a few basic observations I found nothing. So, any suggestions on E are welcome too!
I found the problems very interesting, thanks for the round!
The problem can easily be reduced to maximum subarray problem
We can solve D simply by building (sum of odd indices — sum of even indices) for every prefix, and some simple calculations.
Me bro. Feeling guilty after seeing kadane solution
Here is my dp solution to problem D which is very different from Kaden's algorithm.
Problem D was really cute.
Can you share how you solved it?
This is the link to my solution... First observation is that the array that you want to reverse has to have even length in order to get the elements swapped. And you can start considering that the initial array is the best..and then you can use kadane's algo for finding the best subarray to reverse. Reversing an even length array means in fact subtracting from the result the elements that were previously in the sum and adding the others.
Can it be solved using two pointers ?? considering the largest even subarray such that the sum of elements at odd position is greater than sum of elements at even position and adding the remaining even sums at both ends ??
I don't really know. Maybe it is possible. That was the only idea i had..and thankfully it worked
I tried to implement the same idea during the contest but failed. If you find someone's code using this method, let me know.
you can find a detailed explanation here in the video
How to solve F?
ToughestMost confusing A ever.Actually for n = 150 and k = 0 answer is much bigger than 10^10
It is 150.
It's not
1 + 5 + 0 = 6 != 150
Right my mistake.
Yes, but not difficult to understand that it's a number with a lot of 9 at the end and first digit n % 9, if n % 9 != 0, and simply many 9 else.
Well, yes you're right, it seems for k >= 1 answer is bruteforcable and k = 0 is not difficult to guess
but its less than 10^18
Why NlogN TLE'd on D?
After seeing the constraints, I assumed it should have passed.
Submission
You mean why $$$O(n^2)$$$ TLE while $$$O(n)$$$ passes?
Your solution isn't NlogN it is O(N^2) . Since number of even length subarrays is (N * (N + 1))/4 -> O(N^2)
Can you explain why? I was thinking it is NlogN, so wasn't optimizing during contest.
you have commented in your code that " so we can check every len of 2, 4, ... , n using tc = Nlog2N."
it would have been Nlog2N if it was 2,4,8,16...N but here it is 2,4,6,8,10....N
damn.. Thank you brother. I didn't consider that.
How to solve D??
check this. It's a link to my comment where i explained a little
85011757
I solved D without kadane. My approach is that store prefix even -prefix odd in one vector and prefix odd indexed values -and prefix even indexed sum values in another vector. and then try reversing maximum difference of odd indexed -even indexed sum values sum even length subarray if the array ends at odd index and vice versa for subarrays ending at even index. Try thinking on building intuitions. My submission link is :- 85056177
Hope I would be hacked!
Check out the detailed explanation for it here, you can read more about Kadane's algorithm if you have further doubts :)
You can check out my video editorial here
I stuck on c for one and a half hour because of forgetting using long long...
same.. got no time try D
Tough day for us pal. At least we could learn from this and avoid making the same mistake.
me too
85052253 is ...weird. Who would if(a==165) that deliberately, if not for other accounts to hack?!
Also some of the other A problem Hacks too. Weird.
This one
And for his first try on problem A he wrote (a==7) but it didn't work :D. I also accidentally reviewed these two solutions in hacks section and was confused :DD
Guess it's the same person with two accounts
Here's another one
Fuck it , I need a urgent editorial. Hell yaaa..
Could anyone please confirm, Shouldn't the verdict for this would have been Runtime Error signed integer overflow? Instead it gave Wrong Answer
https://mirror.codeforces.com/contest/1373/submission/85049895
Same with long long got accepted. https://mirror.codeforces.com/contest/1373/submission/85056498
Most languages do not error on arithmetic overflow.
But sir, it gave here https://mirror.codeforces.com/contest/1373/submission/85054448 :(
Oh I actually didn't know about the diagnostics. Apparently they were introduced here? https://mirror.codeforces.com/blog/entry/55902
Looks like the diagnostics only run in some cases: "If your solution:
from the blog post.
Thanks for the info sir, but it seems https://mirror.codeforces.com/contest/1373/submission/85049895 (Wrong) https://mirror.codeforces.com/contest/1373/submission/85054448 (Overflow)
consumed same time and memory, and the other 2 points are correct for the first link.
Anyways, I will always use long long from now on.
From experience, the overflow error only shows when solving problems out-of-contest. For some reason they're disabled inside.
Can someone point out the mistake in my submission for D? 85049220 I used maximum subarray approach. Don't know where its going wrong. Test case is too big to understand.
Is it because you are casting ad to int32_t at the end?
Mistakes like these are always remembered :( Just changed that part and Boom 85058120 Thanks a lot. Would have never figured that out. Also, a silly question, I use: define int long long int because of which I have to use int32_t and stuff. How do you use library functions then? Because when I use max with just ad, it says no matching function calls. So, how do I use (any)library functions on long long int variables?
Just ensure that you typecast the other value to long long int as well.
Yeah, its working. Thanks mate :)
when will the official analysis ?
vovuh I'm curious, was the following solution intended for E:
If $$$k = 0$$$, greedy.
If $$$k = 1$$$, notice some patterns, come up with a rule.
If $$$1 < k <= 9$$$, write a brute force up to something on the order of 1e6 (possibly, with optimizations).
I also noticed many users did precalc (calculated all the answers offline). However, the vast majority did something totally different (idk what), so I wonder, whether the straightforward solution was intended or not. Thanks.
And find the minimum value among them. No special cases.
Wow, that's totally elegant, thanks a lot!
In your code, how did you know to insert an 8 in the middle when
lft
is greater than 8?I need to put as large digit as possible, but I can't put a 9 there since I fixed the number of 9s. So here comes an 8.
I see, thanks!
As far as I can tell, you don't even need to iterate over the number of 9's
If the rightmost digit would wrap around from 9 to 0 in your sequence, then the number of 9s before the last digit is always 0
else the number of 9s is as large as possible
If someone want a poorly coded and inefficient DP solution for E : 85057205
Fucking D . Any solution? Waiting for help.
Here's one solution — 1.Standard problem to be used. Maximum sum subarray of even size (you can google and first geeks link can help). 2. Observation : reversing an odd sized subarray is useless. Problem is reduced to find a subarray of even size, where sum of odd indices elements are more than even indexed elements . 3. Actual solution - sum all even indexed elements , call it sum_1 , multiply all even indexed value by -1. Find the maximum sum of even sized subarray in this modified array, call it sum_2 . Ans = sum_1 + sum_2
thk you
by the way thank you for aur sharing your approach . but can please explain why "multiply all even indexed value by -1" is done (how is it helpful??).
If after this modification, there exists a even sized subarray with positive sum, that means of you reverse this array, you will get most benefited.
Some Hints:
Submission to D:85025959
thk you guy
I think after see the solution you understood all.Just Using prefix count
Hello!
I am MrPupsik. Help me to solve problems pls.
Can anyone help me understand where my attempt to problem C goes wrong?
I think that this might be due to some overflow error, but i am unable to see where it occurs, as almost everything is
long long
.I guess that
ans = ans+it-vc.begin()+1;
causes pointer overflow which leads to undefined behavior? As changing the line toans = it-vc.begin()+ans+1;
(submission 85085422) orans += it-vc.begin()+1;
(submission 85085571) solve the issue.Thanks bro
What was the complexity of intended solution of F?
I solved it in O(n)
It's really annoy :(
My solution for the E:
If
k = 0
we can build the number, we simply put the largest digit to the left whenever we can.If
K = 1
and n is an odd number, we simply put an 8 at the end of the number, so when putting it together it would be:XXXXXX9
XXXXXX8
But if
N <17
we can check with brute force.If
K = 1
and n is an even number, we simply put 89 at the end of the number, so when putting it together it would be:XXXXX90
XXXXX89
But if N <26 we can check with brute force.
The last case is when we have k> = 2 in this case we can search for it with normal brute force, because at most it will have 6 digits
Did a semi brute-force solution for E and it worked. https://mirror.codeforces.com/contest/1373/submission/85047398. Precalculate the answer for all numbers that are I9JK, I99JK, I999JK etc.. Where I,J,K can be any digit and there is a bunch of 9s in between (0 up to 20). Then do lookups,
At the first glance I read the last line as "Then do hookups".
I saw the tags for problem F, and I did not see the greedy tag. My solution is only based on a greedy approach. I do not know how to prove its correctness. If it is wrong, feel free to hack it.
The solution is here: https://mirror.codeforces.com/contest/1373/submission/85035196
PS: They added the greedy tag.
What's the reason, so one has accepted while other not?[submission:85006751][submission:84997771] (Thanks in advance)
Solution is failing due to this line
input=sys.stdin.readline
At end of each testcase, readline will take newline character '\n' along with input, which gets accepted in else part of logic, increasing value of on. To correct this behaviour, strip the '\n' character at endst = st.rstrip('\n')
What was the name of website which kept track of all codeforces rounds and show us which questions were solved by us and which are left? It also kept track of rounds by there format. Eg:- Different categories for Educational,Div1,Div2,Global rounds. It tells us for this round we have solved A,B,C and left with D,E,F,G.
here
I really liked problem C as it tests your ability to read, understand and reason about a piece of pseudocode. Very useful practice and skill.
Yes true. If I encounter such piece of code in the industry, I would never think to optimize it. Tried it out here just because I knew there was a solution
Can somebody explain me why n*log(n) F solution gets TLE? I think I'm missing something, as I would expect it to easily pass. Thanks
sorry, n*log(b0), but question stays the same
This is what you need:
ios_base::sync_with_stdio(0);
Indeed that was the case, now it passed. My main language is java, I only tried c++ because I was confused that I got TLE. That being said I'm not sure how to fix it in java (will try to google it, or if you know, please let me know).
Explanation: city[n] can get connection only from station[n-1] and station[n] (don't forget about modulo — but that is clear). So if I provide X connections from station[0] to city[1] I need to provide remaining connections for city[1] (city[1] — X) from station[1]. If there isn't enough I need to increase starting X. If there is enough I can take remaining connection from station[1] (call it Y) and give it to city[2] and again get remaining connections for city[2] (city[2] — Y) from station[3] (if there isn't enough start with higher X).
If I was able to do it for whole cycle I need to check if station[0] has enough free connections (station[0] — X) for remainder of city[n]. If yes it is solvable, if not I have to decrease starting X.
Yes, nice solution, I did something quite different, for each subarray of cities, I checked whether it can be satisfied by the stations which enclose it. Solved it using sparse table
Could you explain your solution?
Does there exist a testcase that (the ans)%100+k>99? I just iterate 0~99-k for the last two digits of ans
I checked every possible n and k combination with my solution, and none of them have ans%100 + k > 99, so it doesn't look like it, but I don't have a reason as to why yet.
sorry, i think its wrong
Me too. But I can't find the testcase whose ans%100+k>99 or prove that it doesn't exist
no, your solution is correct (but not sure for larger $$$n$$$), that comment is for my rev. 1
i also use the same solution and just intuition, now i try to prove
i refreshed the page 3 times in problem C .. i thought it was a bug showing the editorial solution xD
When you click contests, you can't access it. Only an active contest is visible.
https://mirror.codeforces.com/contest/1373/submission/85001977 Could someone pls tell me why my code submission 85001977 for C can work perfectly for n=500(testcase4) but for testcase5 n=197, it shows TLE??? How can this happen. I implemented the same code they provided in the question, just a small change I brought was to make an array where I could store previous val of curr and the index where curr ended. And in then next iteration started at that index only, so effectively my code had complexity of O(n). Tell me if I'm wrong also how could that thing happen which I stated above.
that would result in tle brother as the iteration for the string would repeat and would pass the time limit.
No it wouldn't repeat. Only one iteration takes place. From 0 to no. of '-'s. I kept the record of last iteration and carried on from there for the next iteration. Had it been that case, why did my code didn't show TLE for n=500 but shows for n=197
500 and 197 is number of testcases not the
string.length
yeah i got that later but I've tested.... and in fact sum of |s| wont go more than 10^6. My algo iterates over this only once. Why should it show TLE??
Enjoyed solving the problems :)
*repost
How the answer for the third test case ( problem E) is 4 . Why not 3?because starting from 3 till 9(3+4+5+....+9) gives me 42 .
K has been given as input. Why??
Because you have to add values f(x+i) from i=0 to i=k, not from i = 1 to i = k. so, total of k+1 values
Hey crystal_clear
Check out the detailed explanation of Problem E: Link
Wrong ans in C for 2h because 'int' expect 'long long'=))))
What's the binary search solution for F? I think the possible amounts of connections that can be given to the first city by $$$b_1$$$ lie in a contiguous range, but I can't think of how to apply binary search to find any number in this range.
Yes. It's possible to do so. You can binary search on how much of the connections from $$$b_1$$$ you assign to $$$a_2$$$. Basically you assign a potential number, and then perform greedy and see if it works.
The greedy strategy is like this: If you assign $$$x$$$ connections to $$$a_2$$$, then you still need $$$y = \max(0, a_2 - x)$$$ connections from $$$b_2$$$ for $$$a_2$$$. That means you only have $$$y$$$ connections available from $$$b_2$$$ for $$$a_3$$$. Be greedy, so you assign all of those to $$$a_3$$$. Now you need additionally $$$a_3 - y$$$ connections from $$$b_3$$$, and so on...
I think of it in a flow/pipes analogy. You just push as much water forward to the next one, which then can push more water forward, and so on. Or in the rope interpretation (see a few comments below) fixate on the of the rings and push the others as far as possible.
Now let's think about the extremes. If you assign $$$0$$$ connections to $$$a_2$$$. Then you will probably be not enough, and at one point you will no be able to fill all required connections.
The other extreme is exactly the opposite. If you assign all $$$b_1$$$ connections to $$$a_2$$$, then you will do a lot better connections. This is the best case for all the cities $$$a_2, a_3, \dots, a_n$$$ and you will satisfy their needs (unless of course it's not possible at all). The only problem that occurs is that you don't have enough connections remaining for $$$a_1$$$. You might end up with a demand for $$$z$$$ connections for $$$a_1$$$, and you don't have any connections left since you all assigned them all to $$$a_2$$$.
Now if you assign $$$b_1 - 1$$$ connections from $$$b_1$$$ to $$$a_2$$$. What happens with the demand? It can get one higher, but it also can stay equal (if some of the pushed connections we assigned greedily are unused). Which means in that case we are better, since we still have one unused connection remaining. If we assign less and less connections to $$$a_2$$$, the difference between the demand and the unused connections will shrink, until it is zero (in that case we have found a solution), or until we gone to far and we can't fulfill and demands of the middle cities any more.
To summarize: if remaining demand for $$$a_1$$$ can't be satisfied with the unassigned connections of $$$b_1$$$, we have assigned too many connections to $$$a_2$$$. Or if the assignment breaks somewhere and some of the other cities miss some connections, we have assigned (pushed) to few connections. Using these rules you can perform a binary search.
Now that I think about it, there is no need for binary search at all.
First assign all $$$b_1$$$ connections to $$$a_2$$$, and push as much as possible. This leaves the demand $$$z$$$ for $$$a_1$$$.
Now assign $$$b_1 - z$$$ connections from $$$b_1$$$ to $$$a_2$$$, and push again greedily. This one will be a solution if it exists.
Solution: 85077333
thanks
thanx a lot
Thanks!
What is the correct solution for A. Many people are getting A hacked.
.
I have a physical proof of problem F at https://mirror.codeforces.com/topic/79862/
Let us consider a circle segmented to n arcs with n nodes N1, N2, ... Nn. the length between Ni ans Ni+1 is ai(the number of households in the i-th city.) and there is a small ring in arc_i, note as Ci. there is a rope with origin length bi between Ci and Ci+1. the rope can be stretched if neccesary.
Now if we can arrange all the rings so that no rope need to be stretched, there is a solution.
We just let all rings move freely. if no rope are stretched, it is ok. If some ropes are streched. there are 2 conditions:
a. all ropes are streched, it is condition 1; b. some continues ropes are streched, while the rope before and after them are not. In this case, the start and end ring of these ropes must be at the node. so it is condition 2.
Cool proof! There is also a more well known proof for the general version of this problem, known as Hall's Marriage Theorem.
Heard that first time, thanks for sharing, it must be author`s solution.
Video Editorial For Problem — D . Hope you like it.
In problem D, I multiplied the numbers at even positions by -1 and found the sub array of even length whose sum is largest.Since this will give me the difference between the original sum of elements at even positions and max sum at even positions after reversing,I'll just add the difference to the original sum. But somehow i got WA at tc 3. Can anyone please help me find why it didn't work? I'll really appreciate it. Here is the link to my solution : https://mirror.codeforces.com/contest/1373/submission/85045234
PS: It isn't kadane, it's just the name of the functions and was too lazy to change it again.
Maybe because in your function kadane your array dp is int and also the answer is int, but it can be long long (around $$$10^{14}$$$), and so it overflows?
Wow thanks brother,it worked. I don't know why i didn't think of that during the contest.
I would like to bring to notice these 2 users who wrote solutions so that their code can be hacked. Please ban these accounts; who create new ids just to disturb the competitive spirit in code forces rounds issafake and orkunisitmak
Too much yapping for a specialist,dont you think?
At least better than cheaters and newbie ig
Well I solved D in a different way, I have used dynamic programming ,first we know that only reversing the order of the l,rth border matters where l(mod 2)!=r(mod 2).
Next wherever this is the case we see that the odd positions interchange with the even position upon reversing. That means there is a net change of value of sum of elements in odd indexes — sum of elements of even indexes.
That means we need to find the maximum such value where all elements in range of l,r. To this extent let dp[i] denote the max such value where the right border is the ith index.Now transitions are as follows
if(i%2==0)
dp[i]=max(dp[i-2]+a[i-1]-a[i],0);
else
dp[i]=max(dp[i-2]+a[i]-a[i-1],0);
as a[i] is on odd index in this case, and we need to find the value of sum of elements in odd indexes — sum of elements of even indexes.
finally the answer is max of all dp[i]+ the sum of numbers previously on even indices from 1->n.
q.e.d
Fun fact- Kadane’s algorithm counts as dynamic programming as well!
How long before the editorial drops?
It'll be available right after the end of the hacking phase
Solutions to A-F are available at the end of my screencast of the round for people who are interested.
Educational round without editorial, how ironic! We need editorial!!
It will be available after the hacking phase.
Is there a correct greedy solution for F? Without binsearch
See if it helps my submission.
My solution is the same:) During hacking time I was thinking that my solution is wrong, but lol it passed. For me it was unbelievable, because I've spent on solving about 5mins
My solutions for problems A-E.
I failed to finish
E
during the contest, but if anyone's interested, here is a non-bruteforce solution I was working on, the version I tried to make during the contest actually failed only on two test cases in the entire input space lol.Hey please can someone help me out by explaining how to solve E.
Also , are Educational Rounds harder than usual ones ?
I explain it at 2:11:35 here
Hey thanks you guys :')
https://mirror.codeforces.com/blog/entry/79277?#comment-650107 I found this easy to understand and easy to implement.
It is possible to precompute the solution for all possible n and k in a separate file and then paste the entire array into your solution and read the answers from it for each test case like this: https://mirror.codeforces.com/contest/1373/submission/85074779
For k = 0, you can use greedy to precompute the answers.
For fixed k >= 1, it suffices to check x from 0 to 1e9.
The reason you only need to check x from 0 to at least 1e9 for k >= 1 is because when k = 1 you can use x = 999,999,998 to get a total digit sum of 80 + 81 = 161 > 150 = maxN, and when k > 1 you can achieve an even larger maximum sum. So by checking all x up to 1e9 you can achieve n up to 161, which is enough. I guess it can be proven that you also wont miss any n by not going above 1e9.
The values of digitSum(x) from x = 0 to 1e9 can be stored in a vector and can be computed in linear time using a simple recurrence relation. To efficiently answer sum queries (f(x) + .. + f(x + k)) you can turn the vector into the vector of its prefix sums.
In the end, the dp array can be calculated in O(9 * 1e9) time, which takes 10 seconds on my laptop.
The non-bruteforce solution sketch is as follows.
The code is here.
thnx man i have learnt something.
Solution to F
There is a solution iff all the cities are full at this point
Submission link: 85057681
It's clear, Thanks a lot!
A well coded O(n*sqrt(n)*log(n)) solution could get AC on G?
Solution for G using max prefix sum segment tree:
First, note that for each pawn $$$i$$$ we can easily calculate the minimum row $$$r_i$$$ it has to get to. Then, let's pretend that we can place pawns on top of each other, and the question then becomes "how many rows must be added to the board so that all pawns are on the $$$k$$$'th column and no two pawns are on top of each other?" If a pawn can reach $$$(k, r)$$$, it can reach $$$(k, r')$$$ for all $$$r' > r$$$. Thus, it is only of interest to us what the earliest row each of our current pawns can get to is, and then we will simply propagate them all forward until no two are on top of each other.
I think it's easier to think of the new problem in terms of arrays: We can imagine the special column as a vector of length $$$n$$$ containing all $$$0$$$'s. Each time a pawn gets added, we add a $$$1$$$ to the index of the earliest row it can get to (where we add new indices if needed, never going over 2n indices). Now, given some array, how do we tell whether we need to add more rows? Playing around with it a little, if we assume our array is either of length $$$n$$$ or has no trailing 0's (i.e. the last entry is nonzero), then we need to add new rows to our array if there is some suffix sum that exceeds the number of elements contained in the suffix. For example, if $$$n=4$$$, the array $$$[0, 0, 2, 0]$$$ is fine but the array $$$[0, 2, 2, 0]$$$ is not since the suffix $$$[2, 2, 0]$$$ has sum 4, which is greater than the number of elements it has (3). The number of rows we need to add is actually exactly the number that the sum exceeds the number of elements by.
If we reverse the array and look at 1-indexed prefixes instead, then we are essentially looking for any $$$p_i > i$$$. This is identical to looking for $$$p_i-i > 0$$$, so we can actually initialize our array to be -1's rather than 0's and now our problem becomes looking for any $$$p_i > 0$$$! If we can find the maximum $$$p_i$$$ with our segment tree above, then this becomes an easy query.
Now, all we need to do is keep track of the maximum $$$r_i$$$ of all pawns currently on the board to keep track of where our prefixes should start from.
There is also apparently a solution that uses RMQ and lazy segtree, but not sure what the idea is. Anyone care to share?
My solution for G: (I could not AC within contest, ACd after that)
Every point has a time range when it is active. We load this into a segment tree, and then traverse the segment tree. That way we can simulate adding points for ever query. We need another aditional DS, where we can do Arr[index]++ where we add a +1 to index. We will only add +1 to a previously 0 location, so we also need to have a binsrch thing to find the first 0 position(note that when we go return from a node, we need to do Arr[index]-- as well). Complexity is mlog^2n though.
click
There is also apparently a solution that uses RMQ and lazy segtree
I think this is what you are looking for https://youtu.be/Nuym8ejFH_w
After 6 failed attempts, I am still unable to figure out, why is code for Problem C failing? Can anybody help me. Please!! Here is a link to my submission
common man , still no editorial , do they prepare it after the contest ?
You can check out the detailed explanation of E : Link
And Problem D: Link
Video solutions for A,B,C,D,E....Hope you will like it!!!
Problem A
Problem B
Problem C
Problem D
Problem E
Hey, is there any official editorial for this contest?
After hacking phase is completed, it'll be released.
If I uphack some solutions after the open hacking phase, but before systest, will the hacked solutions fail in systest?
upd: Yes they fails
They do fail, but not necessarily by your hack, at least in this Submission it failed systests on test 48 which is not your uphack. So I am not sure that uphacks after the open hacking phase are incorporated to the systests at the end of the contest.
After wasting so much time on C, I found that I was using int instead of long long int. Now i solved C and D both. Hope I could solve it during the contest only.
Hey anjanikp1303
Check out E as well, it's just smart brute force: Link
come on why I can't write more than 1e9 in first problem. :(
i too missed that when b+1 > 10^9 :(.
Does anyone explain why it works? it's my code... but idk why it works.... problem F 85046506
For the first time, I'm finally able to solve C problem in a contest XD
I like to read cf comments more than FB memes.
Seems like Codeforces Watcher application can help you with this time spending.
I can't find the editorial for this contest, Is it just me or everyone?
Editorial hasn't been published(for now)
I am a newbie. I solved 3 questions. Still, I got +82. Don't know how the rating works.
Rating changes depend on your rank,not how many questions solved.when the questions are tough,even solving even a few can drastically increase ratings.
Anyone tried to solve D using dp approach? I need some idea about it.
I think Kadane's algorithm is dynamic programming only (just a memory efficient version of it) .
Why they make A so lengthy?
It was not lengthy at all, it was hardly 4 line code.
I know, I did it, but I am afraid of long statements.
Short statements is everyone dream
When will the editorial be out ?
still no editorial...
Yet Another question similar to D
Why does editorials always take so much time in Educational Rounds?
I think it should be part of contest preparation so that the editorial is ready before the contest ends.
I think they forgot to publish the editorial ..it's so much annoying..
Where is the editorial for this round
Hola community, ~~~~~
I was developing a software and ran into error, help is highly appreciated .. please reply fast vector<vector<pair<int,int>>> Cluster; for(auto cluster : Cluster){ vector<pair<int,int>> left_data_logins, right_data_logins; for(auto login : cluster){ if(value<mean_of_all_values) left_data_logins.push_back(login); }}
~~~~~ executing the above peice of code is giving SIGSEV error, i do not know if data_types are not compatible . please help!!
Why did you change tests after the contest and I've got WA? That's unfair... Is not better to do strong tests?
This is called hacking. Tests didn't change but more tests were added before final testing phase.
Thanks.
In contest time ,any solution judge by few test case to avoid long queue..And After contest always judge that solution by more extra test case. It's the rule.Not unfair at all.
Are the problem setters waiting for the corona vaccine to post the editorials?
I received a notification that "Your solution 84984892 for the problem 1373A significantly coincides with solutions izhang05/84984892, diegorestrepo68/84988994". I did not share my code with anyone and I did not use any online IDEs such as ideone.com. Given that this is a simple problem that only requires a few lines of code, it's not surprising that there may be multiple submissions that are similar. There's a limited number of possible solutions and implementations for this problem.
I suggest you to use own template to avoid this type of coincides.
I didn't use any templates. This was my code:
include <bits/stdc++.h>
using namespace std;
int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { long long a, b, c; cin >> a >> b >> c; if (a < c) { cout << 1 << " "; } else { cout << -1 << " "; } if (c < b * a) { cout << b << "\n"; } else { cout << -1 << "\n"; } } return 0; }
There are only so many ways to express "a < c" and "c < b * a".
i see both two code..i understood you are not cheater..but system are not human being, they just check code matched or not..so suggest you to use own template..Then so much change happens always from other code.
why is the editorial released so late in educational rounds?
Because they are educational.
(jk)
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).