By PikMike, history, 5 weeks ago, translation, ,

Hello Codeforces!

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 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 Ne0n25 Mescheryakov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.

Good luck to all participants!

UPD: Our friends at Harbour.Space also have a message for you:

Hello Codeforces,

We are opening a new campus in Bangkok, Thailand!

We are delighted to introduce a strategic partnership between Harbour.Space University and the University of the Thai Chamber of Commerce – a collaborative effort powered by B.Grimm.

After 3 years of successfully disrupting education in Barcelona, with a unique educational model founded on active learning in entrepreneurship, technology, and design, as well as the most extraordinary academic and professional community on the planet to show for it, we are ready to bring the revolution to our new campus in Bangkok, Thailand.

Scholarships for our Bangkok campus are designed to completely eliminate the barrier between exceptional talents and sophisticated education: they cover the entire tuition fee as well as the cost of living expenses, and furthermore, they provide the student the valuable experience of both studying and working at Harbour.Space University.

Unique opportunities reserved for the most brilliant students from anywhere in the world, our scholarships are more than financial support – they are portals from your past to your future.

If you are graduating or have already completed a bachelor's degree, we are waiting for your applications for fully-funded Master's degree scholarships by the link below.

APPLY HERE→

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 hehezhou 7 235
2 pekempey 7 235
4 Barichek 7 241
5 ixy 7 247

467 successful hacks and 688 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A V--gLaSsH0ldEr593--V 0:01
B Dalgerok 0:04
C kmjp 0:12
E AkshajK 0:10
F AnotherRound 0:07
G danya.smelskiy 0:26

UPD: Editorial is out

• +258

 » 5 weeks ago, # |   +41 This may be the first contest for me after getting purple.Hope that I won't drop to blue. :DI hope that the problems will be nice and easy to understand.Wish all of you good luck && high rating!
•  » » 5 weeks ago, # ^ |   -26 orz
•  » » » 4 weeks ago, # ^ |   -12 Short statements please!!
•  » » 5 weeks ago, # ^ | ← Rev. 3 →   -36 deleted
•  » » » 5 weeks ago, # ^ | ← Rev. 2 →   -40 [Deleted]
•  » » » » 5 weeks ago, # ^ | ← Rev. 2 →   -40 deleted
•  » » » » » 5 weeks ago, # ^ | ← Rev. 2 →   +58 Please do not publish so many "orz"s on Codeforces. This is Codeforces, not Wechat or QQ or Instergram or Youtube.
•  » » » » » » 5 weeks ago, # ^ |   0 "Weixin" is "We-Chat" in English
•  » » » » » » 4 weeks ago, # ^ |   +18 What does orz means??
•  » » » » » » » 4 weeks ago, # ^ |   +4 It looks like kneeling.Show admiration for the other person.
•  » » » » » » 4 weeks ago, # ^ |   -47 Yeah, this is Codeforces, not Wechat or QQ or Instergram or Youtube. Here everyone orzes, not just Chinese people.
•  » » » » » » » 4 weeks ago, # ^ |   +42 Only kids, not everyone
•  » » 5 weeks ago, # ^ |   +28 Last round you got +220 rating,so I think this round you can have higher rating. May be you can become Master.
•  » » » 5 weeks ago, # ^ |   -6 It doesn't work that way.
•  » » » 5 weeks ago, # ^ |   +2 Thank you for your wishes~,and no matter how it works,I will try my best.Wish you will become a master too. :D
•  » » 5 weeks ago, # ^ |   -6 I am 1800 now, and I hope I can get +100 rating in near future.Best wishes to all of you!And if my rating is 1900, whether my name is purple or blue?
•  » » » 5 weeks ago, # ^ |   +6 purple
•  » » » » 5 weeks ago, # ^ |   0 I see, thank you!
•  » » » 5 weeks ago, # ^ |   +3 I am 1495 now,how can I reach 1800 rating like you now :v
•  » » » » 5 weeks ago, # ^ |   +14 I believe you can achieve it soon.
•  » » » » » 4 weeks ago, # ^ |   +1 thank u =))
 » 5 weeks ago, # | ← Rev. 3 →   -7 Educational #71 ^_^
 » 5 weeks ago, # |   +61 let's hope that it won't be like the last educational round
•  » » 4 weeks ago, # ^ |   0 amen!
 » 5 weeks ago, # |   -15 Hope that problems will be interesting and the problems will take some time to develop logic. Then we can have a nice contest also fewer submission and no queue.
 » 5 weeks ago, # |   -7 I hope taht the problems be easy to understand not like round 70 X)
 » 4 weeks ago, # |   -6 Can I change my color？
•  » » 4 weeks ago, # ^ |   +1 to green lol
•  » » » 4 weeks ago, # ^ |   -6 Simple trick: Do one wrong submission and quit.If you do this for next few contests, you will even reach grey.Good luck :)
•  » » » » 4 weeks ago, # ^ |   0 There is better method to solve a problem with lots of wrong submission, and make lots of unsuccessful hacks to decrease your point. This is more efficient. PS. My color will change to blue after few hour
•  » » » » » 4 weeks ago, # ^ |   0 But I meant my method is simple, ofc there are many other methods like yours.Have a nice day :)
•  » » 4 weeks ago, # ^ |   0 why somebody always dis me are everyone want‘t be better？ or what wrong with me
 » 4 weeks ago, # |   -35 Why the answer in the first test case of problem C is not 86 = 14 * 5 + 8 * 2?
•  » » 4 weeks ago, # ^ |   +3 you should ask question in the contest but not here
 » 4 weeks ago, # |   -30 How to make problem C?
 » 4 weeks ago, # |   +52 The problem set was real nice.
•  » » 4 weeks ago, # ^ |   +1 Your score changes so bumpy!What a bumpy grade change.
 » 4 weeks ago, # | ← Rev. 2 →   +20 Why so many tests??? Especially F???
 » 4 weeks ago, # |   +51 A much more friendly Educational Round. :)
 » 4 weeks ago, # |   0 What was testcase 5 on problem B? Been scratching head over all contest but couldn't debug it.
•  » » 4 weeks ago, # ^ | ← Rev. 3 →   +8 Your logic behind calculating the modulo of the number of ones is wrong. It is not necessary that the number of ones is divisible by four for a valid sequence of transformations to exist.Here's an example:1 1 1 11 1 1 11 1 1 01 1 0 0you can apply the operation at:1 11 33 12 2
•  » » » 4 weeks ago, # ^ |   0 Ohhk, i got it my algo was wrong. Thank you :)
•  » » » » 4 weeks ago, # ^ |   0 Welcome ^_^
 » 4 weeks ago, # |   +3 Did anyone solve C using DP ?my code got TLE 8, any help?
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   +3 I think you forgot the case height 2 to height 1 (or height 1 to height 2) when the second position is '0' or '1', these two cases are not the same.
•  » » » 4 weeks ago, # ^ |   0 then this should cause WA not TLE, right?
•  » » » 4 weeks ago, # ^ | ← Rev. 2 →   +8 Yes, but you used recursion so the complex is 2^n, you should store dp[indx][last] to avoid recalculate.
•  » » » » 4 weeks ago, # ^ |   0 hmmm, in this line ll &ret = dp[indx][last];  i already store the answer in the dp (by reference) !
•  » » » » » 4 weeks ago, # ^ |   +9 u stored that but u didn't use it when calling it again
•  » » » » » » 4 weeks ago, # ^ |   0 Oof! silly me
•  » » » » » » » 4 weeks ago, # ^ |   0 What do you mean by this line in your code: if (last == 0 && s[indx] == '1')// not valid return ret = 1e18; why this is an invalid case?
•  » » 4 weeks ago, # ^ |   0 You memset all array in every test , clear only size n
•  » » 4 weeks ago, # ^ |   0 I found the answer for Problem C (using DP) after read your code. Solution: 59330841
 » 4 weeks ago, # |   +5 What is the test Case 13 for C. I was trying DP. Btw I found E to be easier than B and C.
•  » » 4 weeks ago, # ^ |   +6 The height of the rightmost pillar must be 1.
•  » » » 4 weeks ago, # ^ |   +1 :(. I have to improve my problem reading capability, I took eternity only to understand the problem.
•  » » » » 4 weeks ago, # ^ |   0 Mine also man. But can anyone tell me please whats going on problem C. I am reading continuously 3-4 hours but still didnt understood what the problem actually asked. Can anyone please expain it easily. Thanks in advance :) Sorry for my poor english.
•  » » 4 weeks ago, # ^ |   +6 "Note that you must start and finish the pipeline on height 1 and, also, it's guaranteed that the first and last characters of the input string are equal to 0."
•  » » 4 weeks ago, # ^ |   +1 You could just brute force for B. Check out every possible square, in O(N^2) time. N < 50.For C, DP isn't actually necessary, although it took me a lot of time implementing.
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   0 can't we solve it using greedy? I tried it using greedy but got WA on test 13 and still don't know why. idea — first find all the continuous segments of zeroes with length > 1 and for each of them check the min of both possibilities and then just calculate the answer.entertained the first and last element case by combining them (they become a segment of 2 or greater elements).Edit: it should start and end at 1 (i didn't entertain it)
 » 4 weeks ago, # |   +4 It took an hour for me to implement C and by the time I realized contest was already finished :P
 » 4 weeks ago, # |   +21
 » 4 weeks ago, # |   +6 Is authors' solution on problem F has time complexity $\mathcal{O}(n \sqrt{n})$? If yes, why is limits on $n$ is so big?
•  » » 4 weeks ago, # ^ | ← Rev. 3 →   0 Maybe your solution performance will improve if you flip the dimensions?Also probably make K smaller, the cost of query 1 is much more expensive than query 2. Also remove the optimize pragma, I found most of the time Ofast actually slows things down a lot.
•  » » » 4 weeks ago, # ^ |   0 Does that matter? Both dimensions have size $\sqrt{n}$.
•  » » 4 weeks ago, # ^ |   +3 Because CF is too fast. As you can see, even $n$ is $500,000$, there are several participants run in just 1 sec.
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   0 My solution on G n sqrt n log n fit in 3 seconds with n = 4e5
•  » » » 4 weeks ago, # ^ |   0 I didn't see solutions to that problem from your account. Where is that submit?
•  » » » » 4 weeks ago, # ^ |   0
•  » » » » » 4 weeks ago, # ^ |   0 But this solution got hacked and it seems like it was because of TLE.
 » 4 weeks ago, # |   -10 Did someone submit HLD + SQRT decomposition (fact that there SQRT groups of queries grouped by length of string) solution in G?
 » 4 weeks ago, # |   +3 How to solve problem D?
•  » » 4 weeks ago, # ^ |   0 +1
•  » » 4 weeks ago, # ^ |   +14 Use including exclusion, I calculate the number of ways to sort each part and minus the number of ways to sort both parts. The answer initially is n!.
•  » » » 4 weeks ago, # ^ |   +3 Can you explain how to calculate the number of ways to sort the arrays? I thought the same thing but i wasn't able to implement it.
•  » » » » 4 weeks ago, # ^ |   0 You can read my code, it's easy to read and understand
•  » » » 4 weeks ago, # ^ |   +1 Could you explain the intuitive idea to compute the number of ways to sort both parts. Just want a hint ,i dont want the complete solution.Thanks in advance.
•  » » » » 4 weeks ago, # ^ |   0 Sort the list of tuples (sorting by first element, then second by default). Then check if the list is sorted by second elements. Ignoring duplicates, there will only be one (if any) valid sorting, so you need to count how to add in the duplicates.
•  » » » 4 weeks ago, # ^ | ← Rev. 3 →   0 missed something. but correct. thanks
 » 4 weeks ago, # | ← Rev. 2 →   -59 Probably, the most "un-educational" educational round I've ever seen.It's not a bad problemset, but I expect more DS and algorithm in an ed round.In addition, the only Data Structure task in the contest (G) is actually similar to Chinese NOI 2011阿狸的打字机. (Link to problem)
 » 4 weeks ago, # |   0 Can you tell me please how to solve E?
•  » » 4 weeks ago, # ^ |   +22 Let's say desired number is $X$. If you could query only one number, you would send 0 and get $X$ XOR 0 = $X$ as an answer. If you sent some degree of 2, you would get $X$ XOR $2^k$ = "$X$ with its k-th bit reversed". Generally, if you send an arbitrary number, you would get $X$ with some of its bits (the ones that are set to 1 in your number) reversed. The only problem is that you do not know which bits are reversed when you send 100 numbers.My idea was the following: use only odd bits in the first query and only even bits in the second query. So, the first query will contain 100 numbers with some of their odd bits set to 1, and the second query will contain 100 numbers with some of their even bits set to 1. Then you will get the following as answer:  X = 100010110 ANS1 = 101000111 // 1st, 5th and 7th bits were reversed; XOR happened with 1010001 ANS2 = 100011100 // 2nd and 4th bits were reversed; XOR happened with 1010 When you compare ANS1 and ANS2, you will see that they differ only in those places where bit reversal happened: ANS1 = 101000111 // 1st, 5th and 7th bits were reversed ANS2 = 100011100 // 2nd and 4th bits were reversed ^ ^^ ^^ That means that ANS1 XOR ANS2 (1011011) will give you the set of bits that were XOR-ed in both queries. Then you just need to check which two numbers among those 200 you sent form the same set of bits. In other words, find $x_i$ from 1st query and $y_i$ from 2nd query such as $x_i$ XOR $y_i$ = ANS1 XOR ANS2. Then you can find X as ANS1 XOR $x_i$ or ANS2 XOR $y_i$.
•  » » » 4 weeks ago, # ^ |   0 Thank you very much!
•  » » 4 weeks ago, # ^ |   +42 Let the input results be N and M and the answer be A. Then, we have two equations: A ^ X = N and A ^ Y = M, where X is in the first output set and Y is in the second output set. Taking the XOR-sum of these two equations gives A ^ X ^ A ^ Y = X ^ Y = N ^ M. Then, if we can find two sets of 100 numbers such that there are no two distinct pairs of integers, one in the first set and the other in the second set, with the same XOR, we're essentially done: find N ^ M, and then use that to find the unique X ^ Y such that X ^ Y = N ^ M.This is fairly easy--just take 100 integers that make use only of the first seven binary digits as the first set and 100 integers that only use the next seven binary digits as the second set. One simple construction is to use 1 through 100 as the first set and 1 * 128, 2 * 128, ..., 100 * 128 as the second set. From here, we can iterate over all pairs of these integers to find the appropriate X and Y. Afterwards, reconstructing the answer is easy--if A ^ X = N, then A = X ^ N, so once we know X we can simply print X ^ N.
•  » » » 4 weeks ago, # ^ |   0 Thank you too!
•  » » » 4 weeks ago, # ^ |   +5 We can also try to bruteforce for these two sets(although it is not guaranteed we will find them this way).I assumed that numbers from the first set are $0, 1, ..., 99$ and was greedily choosing $b_i$ as the least number, such that its xor with every $a_j$ doesn't equal to any of past pairwise xors. The biggest number in the second set happened to be $12672$.
•  » » » 4 weeks ago, # ^ |   0 Cool, this looks simpler than I imagined to myself :)
•  » » » 4 weeks ago, # ^ |   +32 We can even simplify that logic:If we took "100 integers that make use only of the first seven binary digits as the first set" then, after getting the answer, we will know the next 7 bits of X, since all integers in the first set have same 7 most significant digits.Analogically, asking the second set will lead us to knowing 7 least significant bits. Profit.
•  » » » » 4 weeks ago, # ^ |   0 I solved it in same way — got the idea for splitting the bits into two parts from this problem — https://csacademy.com/contest/archive/task/hamming-distances/statement/
•  » » » 4 weeks ago, # ^ |   0 Geothermal WOOOOOOOOOW XD your solution in other place, really soooooooooo amazing
 » 4 weeks ago, # |   0 In problem A, this solution print the answers in one line, while it is required to print them in seperate lines. Still, it received an AC verdit.Should this solution be considered AC or WA?
•  » » 4 weeks ago, # ^ |   +8 Where exactly in the problem statement is it written that you must print one integer per line? :)
•  » » » 4 weeks ago, # ^ |   0 Oh sorry my bad :)
 » 4 weeks ago, # |   +15 The distribution of the number of accepted submissions of each problem is like Div. 3!
 » 4 weeks ago, # |   +8 If you liked problem F, here’s a similar one for you. https://open.kattis.com/problems/modulodatastructures
•  » » 4 weeks ago, # ^ |   +4 Here's another. http://codeforces.com/gym/100739/problem/B
 » 4 weeks ago, # |   0 would someone explain why this submission got WA on test 4 , please :)
•  » » 4 weeks ago, # ^ |   0 Change every int to long long int (you can leave int i), and you will get AC.
 » 4 weeks ago, # | ← Rev. 2 →   0 Got AC in problem C with greedy, why is everyone using dp? https://codeforces.com/contest/1207/submission/59315532
 » 4 weeks ago, # |   0 for problem D I tried taking all possible ways to get the first half sorted basically taken the frequency of every number and multiplying those , and the same for the other half , now if the sorted state of the array is sorting the first half along side the other half (both half's are sorted ) then the answer is all the possible permutations — max( number of ways the first half could be sorted , number of ways the other half could be sorted ) otherwise its gonna be all the possible permutations — (number of ways for the first half + number of ways for the second half ) note that there is only one way for the array to be sorted( bad ) but we must calculate the number of times this happens consider the example 1 1 2 2 3 3 the only way it could be sorted is 1 1 2 2 3 3 but this could happen 8 times factorial( frequency(1) ) * fact( freq(2) ) * fact( freq(3) ); = fact(2)*fact(2)*fact(2) = 2*2*2 = 8 can someone prove this wrong please
•  » » 4 weeks ago, # ^ |   0 did u get anything !!!
•  » » » 4 weeks ago, # ^ |   0 nope still stuck
•  » » » » 4 weeks ago, # ^ |   0 i have also done the same thing and getting WA on 4.but that test case is too large to find out the mistake.
•  » » » » » 4 weeks ago, # ^ |   0 me 2 , I get a negative number so something must be wrong , I think it's because of the mod operation ( a — b )% c
•  » » » » » » 4 weeks ago, # ^ |   0 yah u can add do (a-b+c)%c to get positive but still your ans remains wrong
 » 4 weeks ago, # |   0 I don't know why my D wrong answer on pretest 13... who tell why? thank you very much 59302847
•  » » 4 weeks ago, # ^ | ← Rev. 4 →   0 sorry)
•  » » » 4 weeks ago, # ^ |   0 The answer should be 0 and not 1. Any permutation of that will give a bad sequence.
•  » » » » 4 weeks ago, # ^ |   0 what are you saying...?
•  » » » » 4 weeks ago, # ^ |   0 is there any example?
•  » » » » » 4 weeks ago, # ^ |   0 My comment was in response to Nutella3000's old comment. He has revised his comment now. I can't find any counter cases with your code.
•  » » » » » » 4 weeks ago, # ^ |   0 ok i know...thank you
 » 4 weeks ago, # |   +3 Is there any hack for a greedy solution for problem C ?Because, I see ppl talking about DP solutions, while I felt greedy should work. :)
•  » » 4 weeks ago, # ^ |   0 My greedy solution: https://codeforces.com/contest/1207/submission/59315532
•  » » 4 weeks ago, # ^ |   +12 Greedy seems correct to me. Basically, you only need to take care of separate segments that look like ...100001..., and you either select to cover it all at height 2, or choose to dive at least once to the height 1. But if you go to height 1, you already spend 2*a, and there is no reason to put any additional pillars on this segment. It is just that DP is a safe bet :)
•  » » » 4 weeks ago, # ^ |   0 Yeah, dp solution is just quick to arrive as soon as you know you can fit the statespace in memory and pass the time limit. And can promise correct answer.Where as greedy took time to prove and is still risky.
•  » » 4 weeks ago, # ^ |   0 My solution greedy: https://codeforces.com/contest/1207/submission/59310430 DP code faster than greedy. I think so..
 » 4 weeks ago, # |   -11 I think the problem D statement was not clear ... there is no thing refer the the permutation is of indexes not permutation of elements it self ( it different in handle the same permutations )
 » 4 weeks ago, # |   0 Help me with Problem B please.
•  » » 4 weeks ago, # ^ |   0 check this submission https://codeforces.com/contest/1207/submission/59283633
•  » » » 4 weeks ago, # ^ | ← Rev. 2 →   0 Got it. Thanks that helped. If you don't mind, Can you explain me Greedy approach for Problem C.
•  » » » » 4 weeks ago, # ^ |   0 for every index we check the position of the next 1 we iterate through the array and check if we should go up or go down and then calculate the cost we start at state down 0 and move up only if a[i] = 0 && a[i+1] = 1 this must happen always now if a[i] = a[i+1] you shouldn't change the state just calculate the cost and if a[i] = 1 && a[i+1] = 0 calculate the value i would lose if we go up , and if we go down and go according to the min
•  » » » 4 weeks ago, # ^ |   0 alot of contestant got hacked by doing brutefoce... do you know why?
 » 4 weeks ago, # |   +6 What is the hacking case for problem B ?
•  » » 4 weeks ago, # ^ |   +14 hacking test for my submission3 3 0 0 1 0 0 1 1 1 1 
•  » » » 4 weeks ago, # ^ |   +3 It should be -1 isn't? My solution does so.
•  » » » 4 weeks ago, # ^ |   0 so if we pick x=3,y=3, the 2x2 matrix will only change the value of A(x,y)?, i thought we cant do that :(
•  » » » » 4 weeks ago, # ^ |   +27 You can't pick (3, 3) according to the statement.... In other words, you choose two integers x and y such that 1≤x
•  » » » » 4 weeks ago, # ^ |   +4 No we can't do that. As problem statement says "you choose any submatrix of B having size 2×2". When you take x=3, y=3 then the 2x2 matrix will not be a submatrix of B.
•  » » » » 4 weeks ago, # ^ |   0 Looking at the expected output, they only output 1 1 as the sequence; they don't even address (3,3) at all.
 » 4 weeks ago, # |   0 is their is something better it cost me 7 wa 5 what is that test that fails my solution i tried all possible cases thanks in advance.my submission
•  » » 4 weeks ago, # ^ |   +3 Try this snippet: 5 50 0 0 0 1 1 0 0 0 0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0 The answer is not -1.
 » 4 weeks ago, # |   0 Can anyone explain me the logic of solution to question A?
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   +1 Brute Force!!!Try all possible sizes of hamburger and chicken burger and check if you have enough buns, beef patties, and chicken cutlets to make them both if you do save the result and at the end output the maximum.JUST CURIOUSDoes anyone have an O(1) solution excluding the number of queries?
•  » » » 4 weeks ago, # ^ | ← Rev. 2 →   +1 madlogic here is my accepted code submission it is o(1)
•  » » » » 4 weeks ago, # ^ |   0 Nice, what is the logic behind it?
•  » » » » » 4 weeks ago, # ^ |   0 ok could you first check the code and if you got nothing i will help sure.
•  » » » 4 weeks ago, # ^ |   +4 The O(1) solution is simple: It is always better to make a burger that costs more. So you make as many as you can of the more expensive burgers, and then if you can make more burgers that cost less, you make as many as you can.
•  » » » » 4 weeks ago, # ^ |   0 Yeah, that is what I was thinking from the first moment I saw the problem. Even tho, brute force was faster to implement(I think). But in that moment tha O(1) came into mind. :)
•  » » » 4 weeks ago, # ^ |   0 Mine is also O(1) https://codeforces.com/contest/1207/submission/59288650
 » 4 weeks ago, # | ← Rev. 2 →   0 in problem D,can someone explain me the sequence include one pair is non-descending or non-increasing ,thanks???
 » 4 weeks ago, # | ← Rev. 1995 →   -58 Nice contest!
•  » » 4 weeks ago, # ^ |   0 HOW? MAXSUM = MAX(yi)*q <= 1000*500000 < 1000000000 (it must be int) Your solution get WA only because you should get sum of all numbers from 1 to 500000 which have remainder y, but you sum all numbers from 1 to q which have remainder y
•  » » 4 weeks ago, # ^ |   +10 2000 revisions wut
•  » » 4 weeks ago, # ^ |   +27 For those who are curious. Comment You can't hide it by 2000 revisions.
 » 4 weeks ago, # |   0 Can G be solved without Aho corasick and segment tree ? Like using hashing and sqrt decomposotion ?
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   +28 You can use modified suffix array algorithm to build something like suffix array on the given strings.The modification you need in the suffix array is that on the $i$-th iteration you should compute the equivalence class for every vertex $v$ of the string tree'' (the class of the suffix of the $v$-th string from the input which has length $2^i$).UPD: Forgot to mention that you should consider reversed strings in this approach to build suffix array correctly.
•  » » » 4 weeks ago, # ^ |   0 Even if we build the modified suffix array, how are we calculating the answer for each query ? I have a solution but that is quite ugly.
•  » » » » 4 weeks ago, # ^ |   +20 With suffix array we can find all occurences of the string $t$ from the query in our strings in $O(|t| \log n)$. To do so, you may do two binary searches.Then you have to consider only the vertices that belong to the path from the root to the vertex we need. The easiest option that comes to my mind is to do DFS on the string tree and use Fenwick tree to maintain the vertices we need, but maybe there's something simpler.
•  » » 4 weeks ago, # ^ |   +11 Hey I solved it only with Aho corasick, Can you explain your approach with segment tree? Mine is solved ofline and having an array of frequencies for each string (like all the matches from the root to current node). So basically I do a dfs traversing the tree and process the current character of the current node, and then answer all queries. In order to update the array, I iterate over the fail links in the aho corasick. The code is very simple if you know Aho corasick. It works in N*sqrt(n). code
•  » » » 4 weeks ago, # ^ |   0 Can jumping through the failure link again and again timeout ? What happens if the query string is all aaa...aaa and so is the given string ?
•  » » » » 4 weeks ago, # ^ |   +8 The trick here is that there are only sqrt(n) different lenghts. So you cannot jump more than sqrt(n) for each node in the aho corasick (notice that actually I'm not using the direct fail link but the output fail link.
•  » » » » » 4 weeks ago, # ^ |   +5 ** notice that actually I'm not using the direct fail link but the output fail link. ** Now I get it. I didn't have this observation. My solution is almost the same. Instead of jumping through the failure link, I use a data structure that can add a value to some node and query the sum in a subtree. This can be done using euler tour of the tree and segment tree.
•  » » » » » » 4 weeks ago, # ^ |   0 Just to clarify, you use the data structure over aho corasick tree?
•  » » » » » » » 4 weeks ago, # ^ |   0 yes, on the failure link tree.
•  » » 4 weeks ago, # ^ |   +8 I solved it with centroid decomposition.We only need two string algorithms. Denote $n = |STR|, m = |PAT|$: O(n log n) preprocessing, O(m log n) counting of appearances of pattern in string O(n) counting of appearances of pattern in string I did the first by binary searching suffix array, and the second is just KMP.Given these two, we can solve the problem with centroid decomposition. First read all queries and place them into the nodes in the tree where they occur. Find the centroid of the entire tree. Preprocess the string from the root to the centroid. Then DFS all queries in the subtree of the centroid, and add to their answer the number of the pattern's occurences in the preprocessed string (with algorithm 1), and its occurences overlapping with the end of the string but not contained in it (with algorithm 2). Note that we only have to process a string with length 2m in algorithm 2.After processing the centroid, clip its subtree away from the original tree and recursively solve its subtrees. Repeat until the original tree is empty.This correctly answers the queries by dividing the query string into multiple strings $S = S_{1} S_{2} \dots S_{k}$, and calculating its appearances inside each individual $S_{1}, \dots, S_{k}$ (with algorithm 1) plus its appearances not inside any individual $S_{i}$ with algorithm 2.Total time complexity is $O((n + m) \log^{2} n)$ where $m$ is the total length of the query strings, since due to the centroid decomposition we do the preprocessing of algorithm 1 on every character at most $\log n$ times, and we do the matchings with algorithms 1 and 2 for every pattern at most $\log n$ times. Note that if a suffix automaton was used instead of binary searching a suffix array, we could do algorithm 1 in $O(n)$ and $O(m)$ time, bringing the whole algorithm to $O((n + m) \log n)$.Code: 59351316. My submission during the contest TLE'd due to doing $O(n \log^{2} n)$ suffix array construction.
•  » » » 4 weeks ago, # ^ |   +10 I solved with heavy-chain decomposition. Please see my comment at the bottom.
 » 4 weeks ago, # |   +15 The penalty of taking long long is too high in F, anyone agree with me?
•  » » 4 weeks ago, # ^ |   +1 Can't agree with that.Model solution with ints replaced by long longs works in something like 2.2s.
•  » » » 4 weeks ago, # ^ | ← Rev. 3 →   +3 Mine works in 3.993 :( Any ideas for improvement?Link
•  » » » » 4 weeks ago, # ^ |   +7 Okay, it seems I was wrong.I replaced only the variables required to store the answers and the result on each query with long longs. It seems that creating a new long long in each for-loop and changing it can be really heavy.I am sorry for putting the constraints too high.
•  » » » » » 4 weeks ago, # ^ |   0 Thank you checking it! :D
•  » » » » 4 weeks ago, # ^ | ← Rev. 2 →   0 One if statement can be taken outside the loop, down 0.1 sec only though. https://codeforces.com/contest/1207/submission/59323107
•  » » » » 4 weeks ago, # ^ | ← Rev. 2 →   +34 You should probably know, that the modulo operation is much heavy than simple addition, so decreasing the number of taking modulo is almost always good.In this task you can decrease number of modulo operations by decreasing the "sqrt-constant". For example, changing $700 \to 400$ leads to two times speedup, so the solution with int64t works in only $2$ seconds.
•  » » » » » 4 weeks ago, # ^ |   +6 Wow!Didn't know that big a difference was there.Thanks!
•  » » 4 weeks ago, # ^ |   +1 My solution with long long works in 2s (59309544)However, just because of the adrenaline of the contest, I couldn't notice that long long wasn't needed.
 » 4 weeks ago, # |   0 So sad. I thought minimize answer for problem B. too hurry :(( i spent 30 minutes for it
 » 4 weeks ago, # |   +9 How to solve F?
•  » » 4 weeks ago, # ^ |   +12 For large x, you can easily accumulate all values in a (There are about 500.000 / x indices with remainder y).For small x, this is not suitable. But for a small x, you can maintain a 2D-Table (i,j) := Sum of all values in array slots with index % j == i. Updating this table for a single query takes j steps.Now use the sweet spot K = sqrt(n) to decide if x is small (about 700 for n = 500.000, but depending on the constant factors of both sides this value can be shifted 'slightly' between at least 400 and 1000.)Update: - the array in O(1) - the 2D-Table in O(sqrt(n)) is about 700 Query: - Large x (x > K = 700) in O(n / x) is about 500.000 / 700 =~ 700 - Small x : query the table in O(1)For n queries you get a total of O(n sqrt(n)).
 » 4 weeks ago, # |   0 I can't understand why overflow (task C) 59307028 (may be I am wrong and it is not overflow)There is no hard limitsThird Edu round in a row when I change algo to BigInt (previous five minutes after contest)
 » 4 weeks ago, # |   +7 I still do not understand the implementations of D. The solution is, (more or less obvious) allPermutations - permutationsSortedByA - permutationsSortedByB + permutationsSortedByAandB So far, so simple. The numbers are calculated using factorials. But, how do we get the number of permutations sorted by a and b? I dont get the idea, even after reading the working codes.Somebody explain this?
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   +1 deleted (I am not right)
•  » » 4 weeks ago, # ^ | ← Rev. 3 →   0 allPermutations = n!permutationsSortedByA = multiplication of count of first value in pairpermutationsSortedByB = multiplication of count of second value in pairpermutationsSortedByAandB = multiplication of count of each unique pair
•  » » » 4 weeks ago, # ^ |   0 What about like folowing 4 pairs: 2 1 3 2 3 3 4 4 There are two perms sorted by a, one by b, and one by both. How do I find the number of both if there are no duplicate pairs?
•  » » » » 4 weeks ago, # ^ |   +3 Check if sorting by first, second will also get sorted then it will be 1 else it will be 0.
•  » » 4 weeks ago, # ^ |   0 Sort the array by first number, ties broken by second number. Then check if a[i].fi <= a[i+1].fi & a[i].se <= a[i+1].se. If so, then count occurence of each pair and arrange then in fact(cnt) ways.
•  » » 4 weeks ago, # ^ |   0 My idea that sortedByA : if all A is equal than answer n! because each permutation is sortedByA, now multiplicate factorials of number of equal numbers by A: 1,1,1,2,2,3,3,3,3 -> 3!*2!*4! Now numbers of permutations SortedByA, SortedByB, SortedByAandB can calculated in same way. (1,1),(1,2),(1,3),(2,2),(2,2),(2,2),(2,3): A(3!*4!), B(1!*4!*2!), A_B(1!*1!*1!*3!*1!)
•  » » » 4 weeks ago, # ^ |   0 What happens when there are no permutations that are sorted by A and B?The first test case is an example of this: 3 1 1 2 2 3 1 According to your idea:SortedByA = 1! * 1! * 1! = 1SortedByB = 1! * 2! = 2SortedByAandB = 1! * 1! * 1! = 1And the result is 6 - 1 - 2 + 1 = 4But the actual result should be 3.
•  » » » » 4 weeks ago, # ^ |   0 You need to check whether sorted by A and then by B is sorted by B
 » 4 weeks ago, # | ← Rev. 2 →   0 Problem C , i used the greedy approach : first if the string input doesn t contain any 1 the answer is _ (a+b)*n +b_ elsei search for the first index i1 such that s[i1]=0 and s[i1+1]=1 i search for the first index i2 such that s[i2]=0 and s[i2-1]=1 this way we are sure that segements[0,i1-1] and [i2+1,n-1] are on level one so initialy i consider that [i1,i2] is on level 2 so the initial cost is ( (((i2-i1)*(2*b)))+ b*(n+1-i2+i1) + n*a + 2*a ) it s clear ( i assumed) that continous segements of 1 or 10 should be on level 2 let s call them type 1 so inside segement [i1,i2] we just need to consider those that aren t type 1 do we replace them by level 1 or change them to level 2 comparaison between 2*a and the nunber of pillars in that interval d * b we then decrement cost by db and add 2a if it s optimal to do so my submission stops on test 11 i don t know why any suggestions ? https://codeforces.com/contest/1207/submission/59321454
 » 4 weeks ago, # | ← Rev. 2 →   +1 Any explanation on why the following solution for E does not work would be appreciated.Make a query with the integer set S = {1, 2, 3..., 99}. Let the result obtained from the judge be result_S. Similarly, make a query with the integer set T = {100, 101, 102..., 199}. Let the corresponding result be result_T. Now, result_S = x XOR i, where i belongs to S. Also, result_T = x XOR j, where j belongs to T. Taking an XOR of result_S and result_T yields i XOR j. Brute forcing over all possible values of x and i should be sufficient to determine x_actual, I think.
•  » » 4 weeks ago, # ^ | ← Rev. 3 →   0 You should choose 2 possible sets of 100 numbers such that there is unique pair (i,j) which gives that i xor j value to guarantee that your answer is correct.In your case (i,j) may not be unique(For example in your sets consider two cases, case1:i=3 j=127 and case2: i=2 j=126, both give same xor value which is 124).
•  » » » 4 weeks ago, # ^ |   0 Wouldn't i XOR x and j XOR x be sufficient checks?
•  » » » » 4 weeks ago, # ^ |   0 They would be sufficient checks if you choose sets S and T such that xor of numbers in every pair (i,j) where i is in S and j is T is unique. Otherwise there would be a possibility that two different numbers satisfy the conditions as stated by you. So if we choose S={1,2,3,...,100} and T={1*128,2*128,....,100*128} it would be guaranteed that for every (i,j) i xor j gives a unique number(since last 7 bits of every number in T is 0 and first 7 bits of every number in S is 0).Then you can solve the problem as you have stated.
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   0 first of all, your first query has 99 numbers, not 100. But the i^j of your sets are not unique, for example 97 ^ 101 == 98^102.
 » 4 weeks ago, # |   +13 Editorial please.
 » 4 weeks ago, # |   +6 Problem F is just the reverse version of this problem:https://open.kattis.com/problems/modulodatastructures
 » 4 weeks ago, # |   0 How to solve problem G?
•  » » 4 weeks ago, # ^ |   0 DFS on trie and also use a pointer on Aho Corasick tree.
 » 4 weeks ago, # | ← Rev. 2 →   +7 I feel sorrow at missing this contest. Problem A really convinced me.It 's interesing. My solution: 59330841
 » 4 weeks ago, # |   +6 Won't there be any system testing (on hacks), because it's showing final standings?
•  » » 4 weeks ago, # ^ |   +6 Ignore pls, system testing started. :P
 » 4 weeks ago, # |   -7 Ever pondering of entertainment-al rounds in addition to education-al rounds? Let's watch our newest entertainment-al content: https://youtu.be/D3wC1hgWcZA. Feel free to like, share, subscribe, upvote and feedback. Thanks a lot.
•  » » 4 weeks ago, # ^ |   +3 Funny stuff
 » 4 weeks ago, # |   -6 Is it rated?
 » 4 weeks ago, # |   +17 Is it rated? Why I have no change in rating?qwq
 » 4 weeks ago, # |   0 How to solve C by dp?
•  » » 4 weeks ago, # ^ |   0 This is my code solve by dp. https://codeforces.com/contest/1207/submission/59296434
 » 4 weeks ago, # |   0 i have participated in the contest i got a mail that my code has been copied. I dont know the guys mentioned.I think it happened by coincidence can you add my score.
 » 4 weeks ago, # |   0 Is Problem G solvable with Suffix Automaton ?
•  » » 4 weeks ago, # ^ |   +21 An online solution to problem G :We build the suffix automaton for the trie which is given, and then we build a segment tree for every node (endpos set) . For a query, we do the heavy-chain decomposition for the trie, and then we query the segment tree sum. Total time complexity is $\mathrm O(n\log^2n)$ .This method use so much memory that it will get MLE on test 21 (https://codeforces.com/contest/1207/submission/59296517), but you can get AC with replace the array with std::map.Sorry for my poor English.
•  » » » 4 weeks ago, # ^ |   0 i'm curious where people learn this kind of stuff,do you have any suggestion where to start learning data structure and the implementation like that?
 » 4 weeks ago, # | ← Rev. 3 →   +12 After I saw the announcement, I added if(n==1)cout<<1<
 » 4 weeks ago, # | ← Rev. 2 →   0 Can someone help me with 59286702. I have got wrong answer on case #87. while I am getting correct answer on my local machine. Any help will be appreciated. I think there is some issue with 14th line int a[n][m]={0}; I checked custom invocation with G++11, it works fine. In G++14 it gives wrong answer. Please help.
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   +7 The problem comes from this line:int a[n][m] = {0};`I'm not sure how it works, but it just wouldn't initialize all elements to 0 properly.
•  » » » 4 weeks ago, # ^ |   +3 Yeah, will search for it. Thanks a lot.
•  » » » » 4 weeks ago, # ^ | ← Rev. 3 →   +10 When did you edit your comment thoughI just made it look like a weird conversation xD
•  » » » 4 weeks ago, # ^ |   +6 yes you're correct.Though it works perfectly fine when done on single dimensional array.Still memset is a bit safer choice.
 » 4 weeks ago, # |   0 Auto comment: topic has been updated by PikMike (previous revision, new revision, compare).
 » 4 weeks ago, # |   +9 Can you add top hackers PikMike
•  » » 4 weeks ago, # ^ |   +5 Sorry, I found out it'd been broken after the previous round and haven't fixed it yet.
 » 4 weeks ago, # |   0 Is there is any better way to solve F other than obvious q sqrt(n)
•  » » 4 weeks ago, # ^ |   0 sorry, could you elaborate me about problem F? i dont the second query, especially "set of all integers from 1 to 500000 which have remainder y modulo x", thanks in advance
 » 4 weeks ago, # |   0 Does not educational round show top hackers anymore?
 » 4 weeks ago, # |   +14 Editorials please
 » 4 weeks ago, # |   +10 When will be the tutorial?
 » 4 weeks ago, # |   0 Wanted help with problem C dp solution. I have the following: MY DIV2-C Solution. I added 1) comment line in the code by a hunch... and it gives AC with it... What I dont understand is how this line works and gives AC? Thanks for the help in advance.
 » 4 weeks ago, # |   0 Auto comment: topic has been updated by PikMike (previous revision, new revision, compare).