### YouKn0wWho's blog

By YouKn0wWho, 14 months ago,

The problem names are based on my favorite characters out there. Yes, 1554E - You are my most favorite character UwU.

I have tried to make the editorials as interactive as possible. Enjoy.

Code(C++)
Code(Python)
Code(C++)
Code(Python)
Code(C++)
Code(Python)
Code(C++)
Code(Python)

If you are wondering(as you always do ｡^‿^｡) about the checker:

Checker
Code(C++)

• +328

 » 14 months ago, # |   +24 Nice contest :)
•  » » 14 months ago, # ^ |   +8 I laughed so hard when saw that B's statements were updated and the only update was replacement of 2 with a 1 at the end ;))
 » 14 months ago, # |   -23 A < C < D < B < E
•  » » 14 months ago, # ^ |   +42 A < B < C < D < E :|
•  » » » 14 months ago, # ^ |   -17 A
•  » » » 14 months ago, # ^ |   0 E>D>C>B>A
•  » » 14 months ago, # ^ |   +8 A
•  » » 14 months ago, # ^ |   0 A < D < C < B < E
 » 14 months ago, # |   +14 Such thinkforces B
•  » » 14 months ago, # ^ |   +48 It was a Bit difficult.
 » 14 months ago, # |   +62 Kudos from India man. I really liked your problems. Looking forward to more Bangladeshi rounds.
 » 14 months ago, # |   +66 Nice contest, solving every problem costs a lot of thinking and observation!
 » 14 months ago, # |   +26 Like these problems, but don't like the order of the problems.
 » 14 months ago, # |   +23 It appears a lot of people misread E (I thought the order of operations mattered, and the total count would be n!). Did none of the testers get this confusion? I feel like different sequences should have been in bold.
 » 14 months ago, # | ← Rev. 2 →   0 .
 » 14 months ago, # |   +123 Thanks for the nice problems and the quick editorial!
 » 14 months ago, # |   +10 The contest was a BIT difficult
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 pun intended?
•  » » » 14 months ago, # ^ |   +3 I was referring to problems B and C being about bit operations
•  » » 14 months ago, # ^ |   +7 binary indexed tree
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 op
 » 14 months ago, # | ← Rev. 2 →   +7 Observation forcesNo doubt problems were very good.
 » 14 months ago, # |   -26 Problems were very cool this contest!
 » 14 months ago, # |   +39 The gap between D and E is a bit large.
•  » » 14 months ago, # ^ |   +11 what about A and B
•  » » » 14 months ago, # ^ |   0 Rather not say.
 » 14 months ago, # |   0 Such a wonderful contest. Thank you so much.
 » 14 months ago, # |   0 Thanks for the round and the quite interactive (with the 'Think's especially lol) editorial :)
 » 14 months ago, # | ← Rev. 2 →   -17 BIT-forces
 » 14 months ago, # | ← Rev. 2 →   +1 Nice contest, I'm fool.
 » 14 months ago, # |   +5 Read the solution for B and wonder where is my brain ::.
 » 14 months ago, # |   +160
•  » » 14 months ago, # ^ |   +13 harry potter cries in WA, LogicLessNess and FST's
 » 14 months ago, # |   +3 Really liked the problems. Thanks!
 » 14 months ago, # | ← Rev. 3 →   +3 Very Nice Contest! SpoilerI paused and thought so much to run out of time :P!
 » 14 months ago, # |   +12 I cannot believe this solution passed system test 124170859 on problem D.
•  » » 14 months ago, # ^ |   +8 Similar Solution: 124179999I don't think, it can be hacked, although I don't have a proof of upper-bound on no. of characters used is less than 27. (Worst case calculations give upperbound as 3*log3(n))
•  » » » 14 months ago, # ^ |   +18 I hacked both
•  » » » » 14 months ago, # ^ |   +8 Wow, You hacked it. Thank God, you were not in my room.
 » 14 months ago, # | ← Rev. 2 →   +3 Fast Editorial！ It's a great contest，I love it.I thought the contest would exercise my mind, but E was too difficult for me ...... :(
 » 14 months ago, # | ← Rev. 2 →   +11 Loved the problemset. But D was easier than both B and C. My solution: 124163494i.m.o., the problem ordering should've been: A — D — B — C — E
 » 14 months ago, # | ← Rev. 2 →   +25 My solution to B is not dependent on k. We have all the value of array less than or equal to n. With this can what can iterate x from 1 to ceil(log2(n)) and assume x= (Ai|Aj). For each x we will find top 2 index with greatest value such the Ai is a sub mask of x.124158918
•  » » 14 months ago, # ^ |   0 How do we know if x exists as OR of ai , aj? And you're not checking every sub-masks?Could you please explain?
•  » » » » 14 months ago, # ^ |   +5 Thanks a lot, that helped.
 » 14 months ago, # |   0 Loved the tutorial. Well explained <3
 » 14 months ago, # |   0 Can't understand how binary search will apply for problem cHelp apricated
•  » » 14 months ago, # ^ |   0 Why do you need binary search for C??
•  » » » 14 months ago, # ^ |   0 I have seen some solution with binary searchjust curious to know but unable to understand how binary search property makes sense
•  » » 14 months ago, # ^ |   +6 I did it using Binary search. So just try to understand the monotonic behaviour.Let Count(n,m, mid) is the function, that can give you the count of numbers that are less than or equal to mid from set of [n^0, n^1, n^2 ... n^m]; if(count(n,m, mid)==mid+1) it simply means our mex can't be less than or equal to mid+1.Now the only thing is how to build count() optimally. so it's a kinda digit dp problem. for more insights. u can visit my solution. https://codeforces.com/contest/1554/submission/124189939
 » 14 months ago, # |   0 Can anyone please explain B in some easy way??
•  » » 14 months ago, # ^ |   +9 Well, my solution is different from the one in the editorial (and I don’t really think it’s simple), but here it is:If you fix the Ai | Aj part (let’s call it x from now on), you have to find 2 biggest indices i and j such that Ai | Aj = x, and then the solution is i * j / (k * x). Notice that 0 <= x <= 2 * n because Ai <= n. So, you can go through all x’s, and for every x, find the 2 biggest indices such that the numbers (bitmasks) on those indices are subsets of x (you can just go through all the subsets, check if they appear in the array and modify the max indices accordingly). But, the complexity of that is about n^2 if you’re not careful with implementation, so you have to use an optimization from this blog (look at the Suboptimal solution part, that optimization reduces the time complexity to 3^(log2(n))). And, I know I’m terrible at explaining things, so I suggest you to take a look at my code.Also, did anyone else have a similar approach? All the codes I’ve seen have an approach like the one in the editorial.
•  » » » 14 months ago, # ^ |   -18 I also did it with SOS DP, ofcourse submitted after the contest so as to not drop rating even more becoz couldn't do A. :(
•  » » » 14 months ago, # ^ |   0 Yes, I solved it using SOS DP in O(NlogN) but still got TLE in system testing. And the same code was accepted in CPP 11 after the contest. :(https://codeforces.com/blog/entry/93321?#comment-822763
•  » » » 14 months ago, # ^ |   +6 can u explain that we can be sure if x would present as Or of ai, aj. That is not any two subsets of x will give x on Bitwise Or.
•  » » » » 14 months ago, # ^ |   0 Yeah, that's true, but if we go through all possible x's, we'll definitely find the optimal solution, because, if some x is not present as an Or of Ai and Aj, then it's definitely not the best one (for some two numbers, their Or is the smallest number which contains them both as subsets, so all bigger numbers can be ignored). So, those x's won't affect the final solution.
 » 14 months ago, # |   +6 Any meaning to the problem names?
 » 14 months ago, # |   0 Thank you for the great contest.
 » 14 months ago, # |   0 for B I only checked all pairs for last K + 2 elements, instead of last 2K elements and still didn't FST. thanks
•  » » 14 months ago, # ^ |   0 Yeah, we can do it too. But we don't need to be precise, all we want is a good upper limit and AC.
 » 14 months ago, # | ← Rev. 2 →   +7 meme spoiler
 » 14 months ago, # |   -11 Hello I'm new to codeforces and also am a beginner I wrote this code for cherry problem but only pretests(2) are passed can someone explain me the reason? #include #define D 20 using namespace std; typedef long long int ll; int main() { ll T; cin>>T; while(T--) { ll n; cin>>n; ll a[n]; for(ll i=0;i>a[i]; ll mx=INT_MIN; for(ll i=1;i
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 In the contest time, only two test cases will be judged and after the contest, other test cases will be judged that's why you can see pretests(2) passed.
•  » » » 14 months ago, # ^ |   0 ok thanks bro
•  » » » » 14 months ago, # ^ |   +5 provide code in spoiler so it takes lesser space. code#include #define D 20 using namespace std; typedef long long int ll; int main() { ll T; cin>>T; while(T--) { ll n; cin>>n; ll a[n]; for(ll i=0;i>a[i]; ll mx=INT_MIN; for(ll i=1;i
•  » » 14 months ago, # ^ |   +10 Its better to leave now, than later.
 » 14 months ago, # |   +9 Pause_and_thinkforcesI had a hunch even before the contest that D was going to be relatively easy (didn't expect it to be this easy though). Only if I had believed in my instinct! Excellent (and a bit unusual) problemset.
 » 14 months ago, # |   0 Why for the minimum value we are taking pair (n — 1 , n) in problem B ?
 » 14 months ago, # |   +1 B can be easily done with sum over submask SOS Dpsee my sol
•  » » 7 months ago, # ^ |   0 Hi, I have recently learned this technique. Could you please explain your solution? That would be great help.Thanks
 » 14 months ago, # | ← Rev. 2 →   +1 Hey, can someone prove why this approach doesn't get TLEd? I'm not able to figure out.Iterate on all the numbers in the array. Let's denote a number $a[i]$ special if there is no number $a[j]$ such that $j\gt i$ and $a[j]$ is a submask of $a[i]$. When reach and index $i$ in the array and $a[i]$ is special, we run a brute force for $j\lt i$. But we terminate the brute force loop when we find a number $a[j]$ such that $a[j]$ is a submask of $a[i]$ (but we do calculate $f(i,j)$ for this $j$). Solution.Or if someone could hack this solution :3.
 » 14 months ago, # |   +9 It is one of the best editorial because when i read every line i can connect with the thought process of the author and it is also beginner friendly to understand the concept. Thank You YouKn0wWho.
 » 14 months ago, # |   0 Best contest I've ever participated. Problem statement was so clear and look like easy pessy but too much tricky.I wish I will solve at least two problem in the next contest in future by this author YouKn0wWho
 » 14 months ago, # | ← Rev. 2 →   0 My solution to Problem D which requires O(log(n)) different characters, which, unfortunately, does not enter(Suppose we have a matching string s. Then the string s + x + s + y + s is also suitable, where x and y are symbols that have not been encountered before. After all, each substring in s occurs 3 * the past number, and a substring containing symbols x or y occurs 1 time. Also from s you can make a string from |s| + 1 characters just by adding x to the end. Thus, you can make an algorithm similar to fast exponentiation: Let gen (n) return a good string of n characters.if n % 3 == 2 gen(n) = t + x + t + y + t, t = gen(n / 3) else gen(n) = gen(n — 1) + xIt can be seen that every 3 steps n will decrease at least 3 times, but this will require 4 new symbols. Therefore, you will need log_3(n) * 4 = 44 charactersP.S. I don't know English well and all the text was translated by google translate
•  » » 14 months ago, # ^ |   +4 I wanted to elaborate on Your idea. Actually, I managed to pass the tests using recursive approach during contest 124173130. As You mentioned it would be convenient to think of the problem recursively. We want to make three copies (just two will not do) of the same string and then and then separate them, by some characters that not be use later in recursion. Each of those recursive string should also maintain task requirements. It is easy to see that if some substring of final solution is maintained entirely inside of one of these substrings then there are three copies of it.But we also have to be careful when it comes to substrings that are not entirely obtained in one of recursive areas. We aim for our separators to make them unique (or also have three copies).There three recursive cases. Let's $N$ be length of recursive call, and $A$ be the lowest character we are still able to use. Also lets name by $B$ second lowest character. We will show that it suffices only to use two characters for separation and then $2 \cdot \log_3{N} \le 26$ (which will allow us not to run out of letters)First case is $N \% 3 = 2$. This case is easy. If we mark recursive string of length $(N-2)/3$ by $R$, then we can create solution as follows:$S = R + A + R + B + R$ Second case is a bit more tricky. We have $N\%3=0$. We are still able to create separators, but they will be lightly longer (also length of $R$ will now be $(N-6)/3$).$S = R + ABAA + R + BB + R$Last case was the most tricky one ($N\%3=1$). I used the following construction.$S = R + BA + R + B + R + B$ Now we added something after the last recursive part, but it was necessary if we want to have total length of separators equal to 4 (7 is impossible, because one of the letters would be used even number of times, and 10 is quite long and I was not able to find any two separators that would solve this problem, and also we are not careful may run out of digits for base cases).The last thing is just to look at base cases of the recursion, but we can then use consecutive letters that are left (and there is at least 6 of them).
 » 14 months ago, # | ← Rev. 2 →   -7 I was so upset because of my bad contest day but the first line melted my heart -
 » 14 months ago, # |   0 This is one of the rarest times, where I am loving the editorial so much. It's like not directly jumping to the solution but building up to it and working on the thought process.
 » 14 months ago, # |   0 As for me it isn't adequate to have at contest problems with rating: 800-1700-1800-1800-!2600!Also I think, that order should be like A-D-B-C-E, or smth similarBut I really like each task separately, thnk u!
 » 14 months ago, # |   +17 E can be solved in $O(n \log^2 n)$ time if the product $\prod_{i=1}^{k} (a_i + b_i x)$ can be calculated in $O(k \log k)$ time.Basically, if we let $f(k)$ be the ways to construct $a$ such that gcd is $k$, then then the mobius transform of $f$ can be calculated using dp (and fast polynomial products to calculate the dp values). After that, we can take the inversion.I submitted the simple dnc code to calculate the product, which adds another log, and it passed.Anyway, I thought the easter egg in E's naming was You = u = $\mu$. Seems like the intended one is different :P
 » 14 months ago, # |   0 If $a_i \leq n$ and $a_j \leq n$, then $(a_i|a_j) \leq 2n$. Can someone, give me an example when $(a_i|a_j)$ is equal to $2n$.
•  » » 14 months ago, # ^ |   +5 It can be shown that this inequality is strict.Multypling by 2 is bit shift to the left by one, adding zero, so if most significant bit of $n$ is $i$-th bit, for $2n$ it is $i + 1$-th bit, but if $x \leqslant n$, $x$ can't have $i + 1$-th bit.But there's an example where $x \leqslant n, y \leqslant n$ and $x \mid y = (2n - 1)$.Consider $n = 2^k$, $x = 2^k$, $y = 2^k - 1$. $x \mid y$ is equal $2^{k + 1} - 1 = 2n - 1$
•  » » » 14 months ago, # ^ | ← Rev. 2 →   0 Yes, but quoting the editorial of B "since $0≤a_i≤n$, the maximum possible of value any $ai|aj$ is $≤2n$." $a_i|a_j = 2n$ is not possible. So shouldn't the symbol be $<$ instead of $\leq$ , in the last part ?
•  » » » » 14 months ago, # ^ |   0 consider $2n=00...001....$, where first 1-bit is k-th bit.now let's look at $n$. $k$-th bit will be set to zero, because dividing by 2 is equal to right-shifting by one.one of $a_i$ or $a_j$ must have k-th bit set to 1 (because $2n$ has). but that means than one of them are greater than n, because $2^k > 2^{k-1} + 2^{k-2} + ...$. this is impossible, so $a_i|a_j$ cant be equal to 2n.you are right
 » 14 months ago, # | ← Rev. 4 →   0 Has anyone tried to solve B using SOS DP and got TLE in system testing, in C++ 17?In the editorial it is mentioned that O(N*K) is allowed, so O(NlogN) shouldn't give TLE I guess, I mean K can be as large as 100 and logN cannot be more than 20. What's more traumatic? The same code was accepted in C++ 11 after the contest. That too in 530 ms. Difference of few ms is fine but 470 ms is too much, if this is the case then there should be different time limits for C++17 and C++11, even 1.2 sec would have worked. :(It would be great if someone can explain the reason behind this difference in time, and also if anyone can justify why O(N*K) works but O(NlogN) gives TLE. (Except advising for compiler optimizations, if it was so necessary then it should be mentioned in the announcements or in the problem statement, or at least a pretest should be there which fails without these optimizations. All I want to say is if O(NlogN) fails without these optimizations then O(N*K) shouldn't be accepted too. <;_;> )Here are the submission links:
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 I see this too many time ; sometimes it work when I change compiler but anther times if you change the structer you may get AC for example the arry is more fast than vector but for memset it with value may vectorv(n,0);is more fast than ll a[n]; memset(a,0,n);anyway you should talk with problemseter or post a blog
•  » » 14 months ago, # ^ |   0 Can you tell why changing the order of for loop is giving wrong answer? like this — rep(mask,0,N) rep(i,0,lg)
 » 14 months ago, # |   0 Can someone explain why k * (ai | aj) is O(100 n)? Wouldn't it still be n^2 because to compute (ai|aj) you need to cycle through every j for each i still
•  » » 14 months ago, # ^ |   0 I also had this confusion when I read it. It's not about time complexities, I don't know why they used $O$ notation. It's just talking about the order of the values. $i \cdot j$ could potentially go up to $n \cdot (n-1)$, while $k \cdot (a_i | a_j)$ can only go up to $100 \cdot (2n-1)$, which shows that $i \cdot j$ will be way bigger than $k \cdot (a_i | a_j)$ because of the constraint on $k$.
 » 14 months ago, # | ← Rev. 4 →   0 deleted
 » 14 months ago, # |   0 Sombody plz explain C. I could not understand even after watching streams/reading editorial.
 » 14 months ago, # |   0 sad it was a bitmask contest !! ^_^
 » 14 months ago, # | ← Rev. 2 →   0 i love 3e5
 » 14 months ago, # |   0 Great prombles! ^ ^
 » 14 months ago, # | ← Rev. 3 →   0 I don't know how my solution for B is working. Can you please help me to understand why my solution worked or in which test case it will give wrong answer. https://codeforces.com/contest/1554/submission/124175957
•  » » 14 months ago, # ^ |   0 Your are taking a window of {i to i+k} and finding the ans,TC is N*K
•  » » 14 months ago, # ^ |   0 You had to start from the end of the array, but it's ok if you start from the front.
•  » » » 14 months ago, # ^ |   0 But don't you think for the (n-2*k)th element they are calculating upto nth element.But in my solution i just checked upto (n-k)th element.
•  » » » » 14 months ago, # ^ |   0 mrclr did the same. Any idea why it works ?
•  » » » » » 14 months ago, # ^ |   0 I got the idea why it worked.Actually for an element the function could give maximum value for just next k elements not more than that.lets take an example:consider two cases, - ith & (i+k+1)th element: i*(i+k+1)-k*(some OR) (i+1)th*(i+k+1)th element: (i+1)*(i+k+1)-k*(some OR) clearly, (i+1)*(i+k+1) > i*(i+k+1)or (i+1)*(i+1) + (i+1)*k > i*(i+k+1)or i*i+ 2*i + 1 + i*k + k > i*i + i*k +ior i + 1 + k > 0So, for each element we will achieve, our maximized expression by just checking next k elements not more than that.I hope this will clear, why this worked.
 » 14 months ago, # |   0 Nice contest. Looking forward to more Bangladeshi rounds.
 » 14 months ago, # |   +5 The problems are well-prepared, but I really wonder why the D is a constructive problem without any other algorithms. In my opinion, this one should be used as B(so I think swapping B and D is a good choice).Although I know no one will vote for my comment, but I still want to say the suggestions as the writer may hold a round again in the near future.
 » 14 months ago, # | ← Rev. 3 →   0 interesting E ...... (but too difficult TAT）
 » 14 months ago, # | ← Rev. 2 →   0 Very short and nice statements. But when i see "mikasa", i expected some back story about author and this girl :)
•  » » 14 months ago, # ^ | ← Rev. 2 →   +5 MY_GAME_HAS_COME Did you called me?
 » 14 months ago, # |   0 In problem A, according to the editorial, if the array is 3 1 4, then the best of adjacent products(3*1 and 1*4) would be less than the actual answer 12. (I am completely new to this field. So pointing out where I went wrong would be really helpful)
•  » » 14 months ago, # ^ |   0 No. Actually ans will be max(3*1,1*4) why? Because in problem Statement say you should take arrary Between range[l,R]. So you are taking the hole array [0,2] so ans will be max(arr[l:r])*min(arr[l:r])
•  » » 14 months ago, # ^ |   0 If you consider the subarray{3,1,4} the max is 4 but the min is 1. so there product is 4,not 12 according to the problem statement.
 » 14 months ago, # | ← Rev. 3 →   0 i think the B is wonderful !!
•  » » 14 months ago, # ^ |   +1 nb
 » 14 months ago, # | ← Rev. 3 →   +1 In problem B, Code(C++), for the case n=6,k=1,a={0,0,0,0,100,100}, it returns -70. Isn't it exactly 12? but i forgot that a<=n. Sorry.
 » 14 months ago, # |   +1 why we shoule do this (if (m >> k & 1) ans |= 1 << k, n |= 1 << k;)operation at Problem C?
 » 14 months ago, # |   +71 Editorial for ABCD be like
 » 14 months ago, # |   +9 I think the solution of D is so wonderful , because I have a complex and strange solution which I have to proof it doesn't exceed 26 distinct character.
•  » » 14 months ago, # ^ |   0 Yeah, D is brilliant and might be easier than B and C, but I liked all the problems!
 » 14 months ago, # |   0 Editorials are really good and problems were good.
 » 14 months ago, # |   0 YouKn0wWhoThere is a typo in the editorial for C:If $n_i = p_i$ then we can set $k_i = 0$ as $n_i \oplus 0 = n_i <= p_i$.At the very end it should be $n_i >= p_i$.
•  » » 14 months ago, # ^ |   +1 thanks, updated.
 » 14 months ago, # |   0 problem B: Cobb , are you mean domnick cobb?
•  » » 14 months ago, # ^ |   0 Yes
 » 14 months ago, # |   0 Can someone have a look at my code for problem B? The runtime should also be O(n-k), but it timed out on test case 2. It really doesn't make sense... The intuition is that f(i,j)>f(n,n-1) is only possible when i,j >= sqrt(f(n,n-1)), which is similar to what is given in the tutorialThanks!!! #include using namespace std; int64_t task(vector &nums, int k) { int n = nums.size(); int64_t ans = n * (n - 1) - k * (nums[n - 1] | nums[n - 2]); int least_i = 0; if (ans > 0) { least_i = sqrtl(ans) - 1; } for (int i = least_i; i < n; i++) { for (int j = i + 1; j < n; j++) { ans = max(ans, (int64_t)(i + 1) * (j + 1) - (int64_t)k * (nums[i] | nums[j])); } } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector nums(n); for (int i = 0; i < n; i++) { cin >> nums[i]; } cout << task(nums, k) << '\n'; } } 
•  » » 14 months ago, # ^ |   0 int64_t ans = n * (n - 1) - k * (nums[n - 1] | nums[n - 2]);You're running into an overflow here. Even though ans is a 64-bit int, n is 32-bit, and when computing n * (n - 1) the value is stored temporarily in a 32-bit int which causes an overflow.Try typecasting any values to 64-bit integers when you run the risk of overflows, like so - int64_t ans = (int64_t)n * (n - 1) - (int64_t)k * (nums[n - 1] | nums[n - 2]);Also, you should ideally either link to your code, or enclose your code in spoiler tagsYou can use spoiler tags by typing < spoiler summary="Whatever" > -your-text- < /spoiler > (without the spaces between angled brackets and tags).
 » 14 months ago, # |   0 I think the time complexity of problem B should be O(n + k^2) instead of O(k^2). Please correct me if I am wrong
•  » » 14 months ago, # ^ |   0 Yes if you consider the time to input the array maybe.
 » 14 months ago, # |   0 Bit manipulation : I am bout to end this man's whole carrer.
 » 14 months ago, # |   0 Is there an approximate value of $σ_0$ represented by Big O notation less than $O(\sqrt{n})$?
•  » » 14 months ago, # ^ |   0 $\mathcal{O}{(\sqrt[3]{n})}$
•  » » » 14 months ago, # ^ |   0 It is not proven fact(maybe it is wrong), but for all numbers less than $10^{12}$ it is barely true. But you shouldn't use this in asymptotics.
 » 14 months ago, # |   0 i was too close to B
 » 14 months ago, # |   0 B should have been a little easier or A should have been a little more difficult!
 » 14 months ago, # | ← Rev. 2 →   0 Hello, (in problem B) could someone explain why my this submission didn't pass while this similar solution does. Any effort will be appreciated.Update: There was an integer overflow and it got accepted after fixing it. Accepted solution after fixing overflow. (Thanks)
 » 14 months ago, # |   0 An excellent contest which improve my understanding of the BIT problem, but the only pity is that I didn't attempt to have a look at the D I should have solved ,'casue I failed to solve the B and C.
 » 14 months ago, # |   0 i still not able to understand B(1554B — Cobb) Can anyone please explain B in some easier way
 » 14 months ago, # |   0 Ok so I overkilled B. But I have a very different solution for B. I used SOS dp for B, where the constraints on k does not matter at all. Just store for each mask the two highest indexes of its all submasks which can be easily calculated using SOS dp. Then just choose the maximum value among all masks.
•  » » 14 months ago, # ^ |   0 Code please.
 » 14 months ago, # |   0 I can't understand the calculation formula of Hk of problem E. Can someone explain it?
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 Problem E — hk calculation :fk = number of sequences divisble by k => this will include all sequences that are also divisble by 2k, 3k, 4k, 5k and so on;So, to get the number of sequences where the gcd is k, you can subtract sequences where gcd is greater than k and which were counted in fkSo h(k) = f(k) — h(2k) — h(3k) — h(4k) ......h(ik) ---- until ik becomes > n;h(k) needs to be calculated from higher to lower values ofc.Hope this helps you
•  » » » 14 months ago, # ^ |   0 Your explaination is very helpful. Thank you.
 » 14 months ago, # |   0 Well, my solution for B, is for every 1 <= j <= n, search every i in max(1, j-k) <= i < j, and try to use f(i, j) to update the answer. I know it isn't a correct solution, but I passed the system test...
 » 14 months ago, # | ← Rev. 3 →   +77 About Problem E,there is a similar solution with better Time Complexity. Noticed that for any $k>1$,a sequence $a$ such that each $a_i$ is divisible by $k$,it can be proved that there will be at most one condition. Then we can only check $x|n-1$ and $x$ is prime.And when we check whether a sequence $a$ such that each $a_i$ is divisible by $x$ can be build,we could find the exact gcd number at the same time.It runs much faster than the code of Editorial. The exact time complexity should be $\mathcal O(n\omega(n-1))$ while $\omega(x)$ is the number of prime number that can divide $x$.I think it is no more than $\mathcal O(n \log \log n)$This is my code.
•  » » 14 months ago, # ^ |   0 When $n - 1$ is a primorial, $\omega(n - 1) \sim \frac{\log n}{\log \log n}$.
 » 14 months ago, # |   0 D is too overrated imao, but I'm glad that I read ALL PROBLEMS and quickly solved D. Wonderful contest!
 » 14 months ago, # |   0 Great editorial !!
 » 14 months ago, # |   0 Just Awesome
 » 14 months ago, # |   0 excuse me ,what does the problem E the last step h_k = f_k — \xi h_ik mean
 » 14 months ago, # |   0 Thanks for the great tutorial
 » 14 months ago, # |   0 Try to solve problem D if we consider subsequence instead of substring! It is an interesting problem.
 » 14 months ago, # |   0 Can someone explain problem E why two dfs with different roots can't form two different A sequences?
 » 14 months ago, # |   0 Such a beautifully written Editorial.
 » 14 months ago, # |   0 Looking back at B. The question does not seem too hard. The brute force is very easy to write but I never did think that we should just start from the last 100 elements.So in the end it's just brute force + 1 extra line of code to ensure we only check 100 elements. https://codeforces.com/contest/1554/submission/124263914
 » 14 months ago, # |   0 can anyone tell why i am getting tle here in D void solve() { ll n; cin>>n; ll i,k; string ans=""; if(n%2==0) { if(n==2) { cout<<"ab"<
•  » » 14 months ago, # ^ | ← Rev. 3 →   0 Time complexity of string addition operator is generally linear in the resulting string length. https://www.cplusplus.com/reference/string/string/operator+/So if you have these lines of code: ans = ""; int k = n-1/2; for(i=0;i<=k;i++) { ans=ans+"a"; } That block of code is actually O(n^2)
 » 14 months ago, # |   0 Well-written editorial!
 » 14 months ago, # |   0 Simple explanation of Problem A — Cherry
 » 14 months ago, # |   0 Thi is My approach For Problem Cwe know the xor properties 0 xor 0 = 1 xor 1 = 0 1 xor 0 = 0 xor 1 = 1 so in this ques we have concluded the condition n^MEX>=(m+1)we have to find MEX(as small as possible) so we will move from 31 st bit to 0th if we found ith bit of n and ith bit of (m+1) is same then will make ith bit of MEX is 0(keeping in mind that we r making MEX as small as possible)and if ith bit MEX is 0 and (m+1)'s ith bit is 1 then we will make ith of bit of MEX is 1 (if we take zero it becomes smaller than m+1) and finally if ith bit MEX is 1 and (m+1)'s ith bit is 0 then we can say thay MEX is already greater then will add zeroes in further position !**MY CODE : **124203362
•  » » 14 months ago, # ^ |   0 Thank you
•  » » 14 months ago, # ^ |   0 why don't we start from 0-th bit instead of 30-th bit,since we want to find smallest k. starting from 0-th bit we can proceed as->for i-th bit from right we add 1<
•  » » » 14 months ago, # ^ |   0 Beacuse n^mex >= m+1, so starting from zero might not result in this condition
 » 14 months ago, # |   0 The Python code for B in this editorial (YOUR OWN CODE) is giving TLE on test case 10. https://codeforces.com/contest/1554/submission/124273841
•  » » 14 months ago, # ^ |   0 This difference language should not be there..... if the algorithm implemented is same.
 » 14 months ago, # |   0 How in 2nd statement of problem B maximum possible of value any ai|aj is ≤2nas ai<=n so ai=aj=n;n|n==nbut how n|n==2n ??
•  » » 14 months ago, # ^ |   0 Consider n= 8 and n-1= 7. It will not be 2*n. It can be 2*n-1
 » 14 months ago, # | ← Rev. 2 →   0 Can anyone explain the logic behind problem E observation 2 ?? Why will there be only 1 or no sequence for k>1??
•  » » 14 months ago, # ^ |   +1 In observation 1 they describe an algorithm starting with: "Let's construct a sequence $a$ such that each $a_i$ is divisible by $k$."The idea is that by looking at the algorithm's steps, everything is essentially fixed. There's no place in the algorithm where you can choose from a variety of options. You can either complete the algorithm or you can't. If you can complete the algorithm for some k, then f(k) is 1. And if you can't, f(k) is 0.I would recommend you to take a couple of sample trees and trying out the algorithm by hand for constructing the sequence $a$ for a fixed $k$.
•  » » » 14 months ago, # ^ |   0 Yeah I understood it later on. Thanks for replying
 » 14 months ago, # |   0 i have understood the problem C but can't code it. Any links to tutorial of bitmask. inorder to approach such prob.
 » 14 months ago, # | ← Rev. 2 →   0 E can be solved in $O(n \log \omega(n - 1))$ where $\omega(x)$ is the number of distinct prime divisors of $x$. There is a conclusion that $\omega(x) = O(\frac{\log x}{\log \log x})$, so the complexity can be written as $O(n \log \log n)$.Code
 » 14 months ago, # | ← Rev. 2 →   0 Using Spoilerios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);gave me 11 times wrong answer in 1554A - Cherry .Can anyone tell me the reason behind this?
•  » » 14 months ago, # ^ |   0 Assalamualaikum Brother, You can remove it and run the program.
•  » » » 14 months ago, # ^ |   0 Wlaikumuslam brother.Yes,after removing it i got AC.I just wanted to know the reason so that in future i can handle this issue .
 » 14 months ago, # |   0 Can someone explain the 2nd observation in the Editorial of last question?? " f(k) for k>1 is either 0 or 1."
•  » » 14 months ago, # ^ |   +1 In observation 1 they describe an algorithm starting with: "Let's construct a sequence $a$ such that each $a_i$ is divisible by $k$."The idea is that by looking at the algorithm's steps, everything is essentially fixed. There's no place in the algorithm where you can choose from a variety of options. You can either complete the algorithm or you can't. If you can complete the algorithm for some $k$, then $f(k)$ is 1. And if you can't, $f(k)$ is 0.I would recommend you to take a couple of sample trees and trying out the algorithm by hand for constructing the sequence $a$ for a fixed $k$.
 » 14 months ago, # |   0 I really like the editorials. Would love to see more such editorials for upcoming contests!
 » 14 months ago, # | ← Rev. 2 →   0 Can somebody explain why in problem E the formula of $h_k$ is $h_k = f_k - \sum\limits_{i=2}^{\left\lfloor\frac{n}{k}\right\rfloor} h_{i\cdot k}$, but not for example $h_k = f_k - (h_{2k} + h_{3k} + h_{5k} - h_{6k} + \ldots)$ (like the inclusion-exclusion formula)?UPD: Ok, I understood. That's because $h_k$ is the number of sequences that have gcd equal to $k$ (not gcd divisible by $k$).
 » 14 months ago, # |   0 Really Great Editorial for B. Thank you, Sir.
 » 14 months ago, # |   +3 Problem E is very nice! Masterpiece of small observations!
 » 14 months ago, # |   0 Hi, may I ask a question? Are there someone could explain the function of the words "n|=1<
 » 14 months ago, # |   +8 Awesome from problems to the turorial
 » 14 months ago, # |   0 Not sure if this is too obvious or has already been covered, but you don't really need dp. For each $k \gt 1$ you simply need to figure out if the tree can be split into stars with number of edges divisible by $k$. Instead of doing dp yourself, you can show by induction that this problem is equivalent to the following check. For each vertex, consider the sizes of its subtrees. If some are divisible by $k$, ignore them. For the rest, if there is one which is $\gt 1$ mod $k$, it is not possible. Otherwise count those which are 1 mod $k$, and their number should be divisible by $k$. This way you need to do only one dfs in the beginning to calculate subtree sizes. It seems more efficient overall...
 » 14 months ago, # |   0 the B is very nice，so beautiful problem！
 » 14 months ago, # |   0 The editorial is literally lucid
 » 13 months ago, # | ← Rev. 2 →   0 In problem B, It's when an−1|an is maximum. And, since 0≤ai≤n, the maximum possible of value any ai|aj is ≤2n I don't understand how?
 » 5 weeks ago, # |   0 What is the Binary Search solution for Problem C?