Codeforces Round #787 (Div. 3)
source link: https://codeforces.com/blog/entry/102481?f0a28=1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hello! Codeforces Round #787 (Div. 3) will start at Thursday, May 5, 2022 at 14:35UTC. You will be offered 6-7 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have a rating of 1600 or higher, can register for the round unofficially.
The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, solutions will be judged on preliminary tests during the round, and after the round, it will be a 12-hour phase of open hacks.
You will be given 6-7 problems and 2 hours and 15 minutes to solve them.
Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.
Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:
take part in at least five rated rounds (and solve at least one problem in each of them), do not have a point of 1900 or higher in the rating. Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.
Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of our work. Problems have been created and written by ITMO University teams: MikeMirzayanov, MisterGu, myav, Gol_D, Aris, SixtyWithoutExam, me Vladosiya.
Also many thanks to avevad, yorky, UncleSema, vsinitsynav, GoracioNewport, Tvorozh0k, any_nickname, I.AM.THE.WILL and Jostic11 for testing the contest and valuable feedback.
Good luck!
2 days ago, # | Best of luck, everyone! |
Hope the pretests are stronger in this one. |
-
Can you explain what happens if pretests are weak? I'm new in Codeforces and exploring the rules.
2 days ago, # | Good luck to every one! |
Well, the "Remember" hasn't been written by link yet :) UPD: Thanks, it is updated. |
Hoping that everyone does great and everyone gets a positive delta in this contest. All the best everyone!!!!!! |
Any fool can write code that a computer can understand. Good programmers write code that humans can understand. |
2 days ago, # | Hope I reach candidate master after this round!**** |
Excited for my 2nd contest |
2 days ago, # | never give any contest for increasing your rating. Just give it to learn something new, and rating will definitely increase sometime! |
2 days ago, # | Hoping to reach Pupil! Marinush |
2 days ago, # | Experiencing two consecutive Div 3 rounds for the very first time ❤️ |
2 days ago, # | I have a question, before the contest div 3 before rated, i had been a specialist, and i register at this contest, so they said that i will be rated, but after the contest div 3 before rated, i am a expert, and they( codeforces) said that i was trusted participant in contest (dont have asterisk before name in register in this contest ), so I will be rated or unrated? Thank you. |
2 days ago, # | I hope the contest be good like the latest one yesterday |
2 days ago, # | Good luck and have fun guys! |
2 days ago, # | As a tester, I wish all the beginners good luck! |
2 days ago, # | Hope I reach Radiant this round |
37 hours ago, # | Hello MikeMirzayanov,BledDest,vovuh,adedalic.System I find out some plagiarism activity in Codeforces Round #786 (Div. 3). Please check out submissions of problem 1674B - Dictionary,submissions are 155621247 and 155678427 They both have same function with same variable but just comment down it and wrote it again with some variable change. Please look out at it. Proofs given below and also you can check submissions... |
37 hours ago, # | Old But Gold |
33 hours ago, # | good luck by the way has anyone Upgradeed to win11 |
26 hours ago, # | I am excited about this round to be easy as the last Div 3 round. ♥ |
17 hours ago, # | what is difficulty distribution for problms |
16 hours ago, # | Hope everyone gets a good rank. |
7 hours ago, # | hoping to solve till/after D. solved only till C in previous Div3, could solve D, coz of spelling mistake |
6 hours ago, # | Excited to be slapped with some awesome concepts and learnings. Thankyou guys already for helping me in my path to specialist. |
6 hours ago, # | Excited to enjoy this round on my birthday! :) |
4 hours ago, # | That was an amazing contest! Thanks for the awesome problems! |
4 hours ago, # | good problems. Confused in E for half an hour. F and G are good educational problems. |
4 hours ago, # | Was thinking on problem B for more than 40 mins and after a bunch of unsuccessful attempts using math it comes to be solvable bruteforcely :) A hilarious thing to make it so and i guess i have to remember sometimes that it is just div3 (even tho i'm 1100 still). |
-
how did you solve it it's giving me TLE and I don't know why
-
its infinite loop because you don't break when the element equals to 0 and keep divide by 2
-
try this 3 2 2 2
-
working gives 3
-
oh sorry i didn't try it in my ide but try this 3 3 0 0 0 first line is number of test cases + there is another bug in your code the loop should start from n — 2 not from n — 1 since you don't need to do anything for the last element edit : just realis you use 1 based index ignore the last line
-
this gives -1 as well and I'm putting numbers on index 1 to n on the input loop so the last element is n and i'm using n -1
-
no way bro i tried your last submission and its goes in infinite loop with the above input i really don't know how its works in your side but i would advice you trying codeforces custom innovaction you didn't handle the case when you need to reduce the number and its already 0 as the case in the above if you still have a problem i can discuss it with u on talks edit : to be clear this is the submission i am talking about https://codeforces.com/contest/1675/submission/155987477
-
i feel i am stupid i could show that easily by running it in ideone here the link: https://ideone.com/MEZYNY as i said before you need to handle when you can't divide anymore
-
-
-
-
-
-
-
4 hours ago, # | I really enjoyed solving G. Great problems, very educational |
4 hours ago, # | i'm trying to understand task c in 1hr still not able to understand what they trying to say (maybe my english is weak) |
Did anyone solve F in Python? Keep getting TLE with python and MLE with pypy. For future reference, here is a solution that is accepted in both python 3 and pypy 3 (surprisingly, about 2x slower in pypy): https://codeforces.com/contest/1675/submission/156014304 |
3 hours ago, # | G is O(N*M^3) with very small constant factor? |
-
My solution was O(nm2)O(nm2)
-
I use dp[total number][last number] as status. How to improve?
-
Convert the array aa into array bb where aiai is the frequency of ii. Then, the dp state should be (current_index, number of sections, length of section ending in the current_index). Submission (sorry for the bad explanation, hope you can understand from my code)
-
Let p[i][x][y]p[i][x][y] be the minimum of dp[i][x][1]dp[i][x][1] to dp[i][x][y]dp[i][x][y], and papa be the prefix sum of aa.
Then dp[i][x][y]=p[i−1][x−y][y]+abs(pa[i]−y)dp[i][x][y]=p[i−1][x−y][y]+abs(pa[i]−y).
Note that yy is not greater than n/in/i when enumerating, so the final time complexity is O(nmlog(m))O(nmlog(m)).
Here is my code: 156012337
-
I guess I implicitly used the n/i condition so it is reduced to O(NM^2logM) at least.
-
-
-
3 hours ago, # | My approach for F: Vlad and Unfinished Business We need to travel from srcsrc to targettarget. Root the tree at srcsrc. The path from srcsrc to targettarget is now a vertical path. Call a node infected if we need to compulsorily visit it during our journey. Initially, the only infected nodes are srcsrc, targettarget, and the given kk vertices. Notice that if a node is infected, its parent would also be infected (since we cannot visit it without visiting its parent). Hence, we can propagate infection up the tree via a simple DFS. To compute the answer, notice that any edge between 2 infected nodes would have to be traveled exactly twice. (One while going from parent to children, and the other while coming back). Hence, the answer is
However, we do not need to travel back to srcsrc from targettarget. Therefore, we need to subtract the depth of targettarget from our answer. |
There is a bug. My solution to A was accepted, but it's missing in the standings. UPD: fixed, thanks |
3 hours ago, # | I had a hard time understanding problem D |
3 hours ago, # | how to solve G |
-
a common idea in problems where you increase a[i]a[i] at the cost of a[i+1]a[i+1] or a[i−1]a[i−1] is to consider prefix sums/suffix sums.
in this problem, consider the prefix sum array pref[]pref[]. Each move of type a[i+1]a[i+1] to a[i]a[i] increases pref[i]pref[i] by 11, and leaves all other values unchanged. Similarly, a[i]a[i] to a[i+1]a[i+1] decreases pref[i]pref[i] by 11 and leaves everything else unchanged.
Converse is also true: every increase/decrease of pref[i]pref[i] corresponds to some move in the original array. [for i<ni<n , since pref[n]pref[n] remains same].
So problem is transformed to one operation which increments or decrements an index of the prefix array. Then you get the necessary and sufficient condition
CC: a[i]≥a[i+1]⟺pref[i]≥2∗pref[i−1]−pref[i−2]a[i]≥a[i+1]⟺pref[i]≥2∗pref[i−1]−pref[i−2].
Then you can define dp[j][j1][j2]dp[j][j1][j2] to be the minimal cost to convert pref[1...j]pref[1...j] so that pref[j]==j1pref[j]==j1 and pref[j−1]==j2pref[j−1]==j2, then you can figure out the states using condition CC.
-
you will go into dead loop when both numbers are 0
-
https://codeforces.com/contest/1675/submission/156012745
modified your code to get accepted. it was stuck in a loop when both numbers are 0 since dividing 0 will also yield 0 it goes on forever
3 hours ago, # | problem c is really hard and it can solved by logic principles only!! |
3 hours ago, # | Can someone please explain how to solve E ? Only thing I figured out was in total at most 26 moves every char in string can be converted to 'a'. So, k>26 will always yields aaa...a which is the smallest lexicographical string ( Correct me if I am wrong ) |
-
your observation is correct. You just have to go from s(0) to s(n-1) in order and converting characters to lowest possible conversion at that point, you just have to maintain an array of size 26 to check how many characters you have already converted
you can check one of the way in my solution :
-
Can you please explain the main logic. I mean the lowest possible conversion at that point means what ? Third part I understood that like if suppose 7th char was 's' and we did the calculation for it's conversion then if we get 20th or any further char again 's' then we will simply ignore that since 's' calculation is already done
-
suppose n = 5, k = 4, string = cgdfb,
c -> a
g -> e (thats the best conversion for this stage)
d -> d(there is no conversion possible as k is used up)
f -> e
b -> a
thats what i meant if k was 6 you could convert g -> c -> a
-
-
3 hours ago, # | Idk how the heck C has 7000 solves . Believe me D and E are a lot easier than C. |
-
cheaters?
-
I don't think so, maybe we are missing out on something easy observation.
-
I solved A-E, and short 10 minutes to submit F. This contest is harder than previous div3, but judging from the number of AC submission, I'm sure there are a tons of cheaters.
-
I don't think the contest was tough,
Problem A : Implementation
Problem B : Start from back
Problem C: prefix should not have any '0' and suffix should not have any '1'
Problem D: Basic dfs
Problem E: Just do whatever is written, decrease current character as much as you can Problem F: I have seen these types of problems many times, fix the root and then every required edge will be visited twice except between the path from x to y (So, basically again a normal dfs with some basic dp involved)
Problem G: It involved a nice DP, but it's fine, the last problem can be on the tougher side.
Problems were of the same level as of a normal Div3 contest.
-
-
-
Problem D implementation was difficult. But the idea was simple.
Problem C implementation was super easy. But getting the idea was very tough.
-
Can you explain your idea for problem D. I was getting TLE
-
Steps:
- Find the Leaf nodes
Hint- Create a map to store the parent nodes of each of these leaf nodes.
- For each of these leaf nodes, put it's parents in the map
- Starting from the leaf node, navigate till the parent (using DFS), and store the list of integers
- Make sure that you don't add already visited values (as it is mentioned that
each vertex belongs to exactly one path
)
Loop through all these items in this map, and print the parent nodes in reverse order. We are reversing this because, it is mentioned that
paths always lead down
.
My Submission — 155988440
There could be some other simpler solution. If anyone else can comment on this thread, on how this can be improved, that would be great.
-
determine the root vertex first. it's easy, because it's the only one vertex with a[i] = i. then run dfs from the root and start writing the path to an array, and we end the path if and only if we came to the leaf node (there is no way to continue it). So, we return current path to the main function and do same thing again unless all vertices are visited. sorry for my poor english :P
Here is the implementation
-
-
3 hours ago, # | My idea for F — Find the path from x to y. Let the path array be composed of nodes u1, u2, u3 ... ul, where u1 = x and ul = y. Then for every u, do a BFS considering u as the root, and store the distances in a array dis. Then the answer is length of path + 2*(sum of all distances of mentioned k nodes). But it got WA on test 2. Am I missing something? |
3 hours ago, # | jiangly's code is so concise! |
can anyone please explain |
-
I am not sure if I can explain better than the problem description.
We have to make the given string lexicographically minimum, by performing the given operation
maximum k times
.Operation: Choose any character in the String, and replace all of it by the previous character.
For example, replace all 'c' with 'b' or replace all 'a' with 'z'.
For String
cba
withk=2
, we can perform 2 operations as below.cba -> bba -> aaa
Note: Checking the test case below might be considered as a HINT.
3rd Test Case steps
3 hours ago, # | Thank you for the contest! I especially liked problem C for the setting and problem F for key insight. |
-
Can you please explain to me the test cases for C, I couldn't even understand how the test cases are working! May be I am getting something seriously wrong on this problem, for test case -> ? ? 0 ? ? how the answer is 3? Should it not be 5?
-
first and second one maybe the theif third one as well but the fourth and fifth can't be since the painting was already missed when the third one reported if he tell the truth and if its wasn't missed that means third one is the theif and also fourth and fifth one can't be the theif sorry for my bad english
-
? ? 0 ? ?
- We only have information from the third person
- Either someone stole the painting before they entered the room (0), or they are the thief (and are lying).
- Therefore the thief must be one the first 3 people
-
If friend 3 was the thief and lying, the painting was definitely taken then so it would not be there for 4 or 5. If friend 3 was honest, the painting was taken by friend 1 or 2 (it had already been taken) so it was definitely taken before 4 or 5 came.
-
Apart from the existing comments, let me try to explain how I interpreted this problem
C
for Testcase? ? 0 ? ?
. May be it helps someone.If 1st person is thief :
- persons
2,4,5
can't remember — so, no issues - person
3
didn't see the picture — which is true - VALID
- persons
If 2nd person is thief :
- persons
4,5
can't remember — so, no issues - person
3
didn't see the picture — which is true - VALID
- persons
If 3rd person is thief :
- person
1,2,4,5
can't remember — so, no issues - VALID
- person
If 4th person is thief :
- person
1,2,5
can't remember — so, no issues - person
3
didn't see the picture — which becomes a false statement - which makes that 4th person is not the thief. So, INVALID.
- person
If 5th person is thief :
- person
1,2,4
can't remember — so, no issues - person
3
didn't see the picture — which becomes a false statement - which makes that
5th
person is not the thief. So, INVALID.
- person
-
-
will you please share the approach to the problem F
-
My approach is as follows.
Consider a rooted tree with root in xx. Let important vertices be the ones that we will have to visit. First, mark the input vertices as important, and also the vertex yy. Now, a vertex is important if it is marked or at least one of its children is important. This characteristic can be found recursively with a single DFS.
So, we got a subtree TT of the original tree: we have to visit every vertex of TT, and don't have to go anywhere else. Now, think what would we do if we had to return to xx in the end. Naturally, we would traverse each of the edges of TT exactly twice: once going from the root and the second time going back.
Remember now that we don't have to return to xx, just end up at yy. Naturally, we will consider a path that ends up moving from yy to xx, and then omit that last part. The number of steps is therefore twice the number of edges in TT minus the distance from xx to yy.
To me, the beauty of the problem is that some parts above can be omitted, leading to more and more tedious (but still quite working) solutions. So, the participant has a choice to either start implementing what they have, or ponder more to maybe cut out quite a bit of work. If a solution needed all of the above to pass at all, that beauty would have been lost.
-
Can anybody explain why so many RE on test case 7 in problem D with Python? My submission: https://codeforces.com/contest/1675/submission/155950425 |
-
Probably running out of stack due to recursion? Test 7 appears to be a single path with every node on it.
-
I thought so too, but here is my submission with increased recursion limit, but got the same. https://codeforces.com/contest/1675/submission/155959621
-
That just stops python giving a recursion limit error, you can still run out of memory and crash.
-
"you can still run out of memory and crash"
That yields a "Memory Limit Exceeded" (e.g.): https://codeforces.com/contest/1675/submission/155991461
Which is different from the "Runtime Error" in the submission shared by khanter_
-
This works: https://codeforces.com/contest/1675/submission/156020448
I added a generator function called bootstrap. This takes a recursion and processes it as a stack instead. It's extremely useful in python for large N recursion problems. I use C++ now but when I used python I always used bootstrap for recursion and strongly advise you to do the same.
-
-
-
-
108 minutes ago, # | when will be the editorial available? |
I see some people cant get the logic of C so probably my approach will be useful: first of all i loop through the whole string and count a total number of occurrences of '0' and '1' in a string (separately for each). Then i start a second loop and in that loop i also count a number of occurrences of '0' and '1' till i-th element. The first thing we need to see that only the last '1' can be a thief (because for any earlier '1' the will be a '1' later, which confirms that a painting cant be stolen earlier). The same goes for '0', but only the first '0' can be a thief (because for any further '0' there will be a '0' earlier, which says that a painting has already been seen to be stolen before). Now we move to '?'. Here we had to see that '?' can be a thief only if all '0' are on the right side from '?' and all '1' are on the left side of '?'. The logic is pretty straight-forward: if there is a '0' on the left then the painting was already confirmed to be stolen (which cant happen because its being stolen on '?' only). The same we can see for '1': if there is a one '1' on the right then a painting will be confirmed to be seen (which cant happen because the painting has already been stolen on '?'). You can find my code here: 155985751. I hope I could help somebody out by doing this, have a great one and see you all tomorrow! |
60 minutes ago, # | In Problem C , if before 0 any ? occurs why he/she won't be considered as Theif ?? |
-
Before
0
, if any?
occurs, he/she will be considered as Thief.Anything after
0
is only not considered as thief.Answer for
???????000
is8
. (Only last 2 person can't be considered a thief)I have tried to explain that in this comment — here.
-
If you speak about '?' considering a thief you have to keep in mind what you have on both sides too. There might be some '1' in between or '0' before '?' that break the logic
-
Recommend
-
12
A. Replacing Elements 题意:一个数组,可以用两个不同的元素替换掉另外一个元素,不限次数。问,能否使得数组中所有元素都不大于 d 。 思路:显然,如果所有元素都不大于d,那就执行0次。成立。如果有元素大于d,那就得替换掉,显然选择...
-
12
题目链接:https://codeforces.com/contest/1475 A.Odd Divisor 数论 题目大意为判断n是否有奇数因子。 考虑唯一分解定理,n的所有质因子中只有2为偶数,除...
-
18
:比赛连接 emm,消极了,消极了。这场可以 a k ak ak的,看到...
-
9
Codeforces Round #734 (Div. 3) 题解已认证的官方帐号Hello大家好,今天给大家带来的是
-
8
August 11, 2021 ...
-
16
Upd: fixed author's solution links.Sorry for the slow Editorial, I am new using Polygon.Special thanks to TechNite for his help.About one hour before...
-
5
Educational Codeforces Round 115 (Rated for Div. 2) Educational Codeforces Round 115 (Rated for Div. 2) Finished ...
-
18
Codeforces Round #748 (Div. 3) Problems ...
-
8
Codeforces Round #747 (Div. 2) Codeforces Round #747 (Div. 2) Finished ...
-
11
Codeforces Round #746 (Div. 2) Codeforces Round #746 (Div. 2) Finished ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK