By Radewoosh, history, 2 years ago,
Tutorial of Hello 2019

• +127

 » 2 years ago, # |   0 thanks for the tutorial!How to split sequence into |LIS| decreasing sequence in E?
•  » » 2 years ago, # ^ |   +41 We'll use the "standard" LIS algorithm with binary searching: sweep through the array, and maintain an array of dp[l] = min(A[i] s.t. there's an increasing sequence of length l ending at A[i]).When we see a new value A[k], we binary search and find the maximum length l such that dp[l] < A[k]; then we know there's an increasing sequence of length l+1 ending at A[k]. Also, l is maximal, so dp[l+1] > A[k], so we should update dp[l+1] = A[k].Now, note that the sequence over time of values of dp[l] is decreasing. Thus, these are precisely a partition of the permutation into |LIS| decreasing subsequences, so we can store a vector for each dp[l], and get the subsequences.
•  » » » 2 years ago, # ^ |   -6 But why is its running time
•  » » » » 2 years ago, # ^ |   0 The running time of the LIS algorithm is only , but we have to run it times because we're slowly removing one LIS at a time.
•  » » » » » 2 years ago, # ^ |   0 thanks
 » 2 years ago, # |   +12 where does the Youtube tutorial go? :/
 » 2 years ago, # |   +15 For 1097D why is the result multiplicative?
•  » » 2 years ago, # ^ |   +44 If you calculate the expected value for a given n with k = 1 (one step), you see that the answer is simply σ1(n) / σ0(n), where σ1(n) denotes the sum of divisors of n and σ0(n) the number of divisors.It's well known that σ1 and σ0 are multiplicative functions (and easy to prove indeed). So, it's easy to see from there using induction that the function is multiplicative.
•  » » 2 years ago, # ^ | ← Rev. 2 →   0 I wasn't sure when I was in the contest, so I used DFS to search all the divisors of n, the complexity is correct.
•  » » 2 years ago, # ^ |   +5 E[f(X)g(Y)] = E[f(X)]×E[g(Y)], if X and Y are independent. Here exponents of each prime divisor of N are independent of each other, and E(.) denotes the expectation value.
 » 2 years ago, # |   0 can anyone help me with problem B
•  » » 2 years ago, # ^ | ← Rev. 2 →   0 Since the constrains are small, u can apply brute force, a simple approach is that for every given angle u can consider rotating it either clockwise(+) or anti-clockwise(-). Do it for all the angles in the array and keep summing them, if in one of the ways u get a final sum(after one complete traversal of array) which is divisible by 360, then output 'yes' other wise if non of the ways satisfy the condition sum%360==0 then output 'no'. There are total 2^15 ways(maximum) of obtaining the final sum. Refer to my solution for more clarity. https://codeforces.com/contest/1097/submission/47914337
•  » » » 2 years ago, # ^ |   0 Thank you
•  » » » 9 months ago, # ^ |   0 Yes, we can approach all the possible combinations using bit masking
 » 2 years ago, # |   0 How to calculate dp(k,j) in problem D.
•  » » 2 years ago, # ^ | ← Rev. 2 →   0 sum ( dp(k -1,j + i) * (1 / (j + i + 1)) ), i goes from 0 to (p -j). Not sure though
•  » » 2 years ago, # ^ |   0
 » 2 years ago, # |   +16 In my opinion, posting fast such editorials without tutorials of some task is muuuch betterIt gives time for problemsetter to write missing ones clearly and others an oportunity to read available parts and try to understand them
 » 2 years ago, # | ← Rev. 2 →   0 in problem c " The task is to connect some of them into ordered pairs so that each bracket sequence occurs in at most one pair and the concatenation of the bracket sequences in each pair is a correct bracket sequence". Can someone explain me the solution of c in context of the bold statement above.if we want each bracket sequence occur in at most one pair then how is the editorial solution is correct. for ex if sequences given are : "((,)),)())" then solution according to the editorial will be 1 but there will be one sequence left with no pair which violates the condition in the bold statement.Can someone clarify my doubt
•  » » 2 years ago, # ^ |   0 At most one means zero or one.
•  » » » 23 months ago, # ^ |   0 Can you please explain for problem C , how to get pair (a,b) in a single loop, as hinted in the tutorial ?[ where a and b are the minimal non-negative integers such that after adding a opening parentheses "(" to the left of the string and b closing parentheses ")" to the right of the string it becomes a correct bracket sequence.]
•  » » » » 7 weeks ago, # ^ |   0
 » 2 years ago, # |   0 For 1097B, how to solve it if N is bigger?
•  » » 2 years ago, # ^ |   +1 like this:47957456it is O(nk) and can be O(nk / 32) if you use bitset
•  » » » 8 months ago, # ^ | ← Rev. 3 →   0 I will be glad if you make me understand these according to editorial: shanxizeng Aman_98 blitzitouti) why should I chose 2^n-1 instead of 2^nii) If i-th bit is 0 so we should do it clockwise rotation for i-th, why?
•  » » » » 8 months ago, # ^ |   0 In general, this is a technique for brute forcing and looking at all possible outcomes. Since, every angle has 2 options (either CW or ACW), we have at most $2^N$ possibilities. We can represent all possible outcomes in terms of binary representation of all numbers from $0$(all 0s) to $2^N-1$(all 1s). So, we can check a total of $2^N$ possibilities and see if we get the desired result. Basically bit 0 represents one choice and bit 1 represents the leftover choice. There is no hard and fast rule, you can assign any direction to any bit. Either way it's fine.
•  » » » 7 months ago, # ^ |   0 shanxizeng Can you explain This Solution — 47957456 of yours for the problem 1097B - Petr and a Combination Lock.I Have dried run it thoroughly but i am not able to understand the idea behind it.
•  » » » » 6 months ago, # ^ |   0 Firstly,you can define h[i][j] as something that if you can get a j after rotate i time.If it's true,the value is 1,or it's 0.And you can simply get that h[i][j]=h[i-1][(j-a[i])%360] or h[i-1][(j+a[i])%360].This is a simple DP.And then,you can define g[j]=h[i][j],f[j]=h[i-1][j].The method of calculating is similar as below.When all of the g[j] were done,you can copy g to f,and use f to calculate h[i+1].At last,you can get h[n][0].
•  » » 2 years ago, # ^ |   +10
•  » » 2 years ago, # ^ |   0 If you understand, please tell me the solution
 » 2 years ago, # |   -7 How to solve G?I came up with an idea that we can calculate the number of ways to choose k edge(s) from n-1 total edges, and for each way we calculate the number of the set of vertices which satisfies the condition(for every edge we chosen, there is at least one vertex(in the set) in both sides of the edge).And that is the answer. Maybe can use DP on tree to solve it.Because f(S)^k <--> choose k edge(s), that's equivalent.Am I right?sry for my poor English, wish you can understand me...
•  » » 2 years ago, # ^ | ← Rev. 2 →   +7 My idea is similar but not same with yours.First we can use Stirling number to split power into several falling factorial，e.gf(S)^k=sum{i=1...k}S(k,i)f(S)_(i)，where x_(i)=x(x-1)...(x-i+1)=C(x,i)i!then we should compute sum C(f(S),i), for every 1<=i<=k.this is equivalent to choose i egdes and sum the number of sets valid(that means f(X) includes these edges).then we can DP with dp(i,j) means choose j edges in i's subtree, and each egde chosen has at least one node of its subtree in the vertex set. and then the answer is dp(1,i) minus unvalid ways, the latter is only possible when (j-1) edges are all in the other's subtree(and no vertex outside this subtree is in the set). you can enumerate the "highest" edge, and the ways of this can be easily gotten use dp values.
 » 2 years ago, # |   +31 I think problem C somehow matches to 990C - Bracket Sequences Concatenation Problem of previous codeforces contest ....
•  » » 2 years ago, # ^ |   +7 Same feeling...
 » 2 years ago, # |   +12 Could someone mind explaining to me why this solution for problem E doesn't work?My approach is the same as described in editorial, except that I remove from list the maximum between LIS and LDS.
•  » » 2 years ago, # ^ | ← Rev. 2 →   +8 Unfortunately, that's just not efficient enough. That solution gives you sequences, but you need around .The key to the solution is that, if the LIS isn't long enough, we take the entire set of decreasing subsequences, not just the longest decreasing subsequence. Note that in general, repeatedly removing the longest/last decreasing subsequence doesn't give you the minimum cover: consider 3 0 4 2 1: you might want to take 3 2 1, but the only minimal cover is 3 0 and 4 2 1.
•  » » » 2 years ago, # ^ |   0 Hmmm I'm still not fully sure I understand since at every single step I take the max between LIS and LDS, then shouldn't that mean that at least one of LDS or LIS should have size bigger K, for the case mentioned my code would work since if it takes 321 as LDS, then it would find 04 as LIS on the next step.
•  » » » » 2 years ago, # ^ |   +8 I don't have a case on hand which breaks it. Unfortunately, it's not true that either the LDS or the LIS has size at least K: see the sequence 3 6 9 2 5 8 1 4 7: both the LIS and LDS have size 3, but K = 4.
•  » » » » » 2 years ago, # ^ |   0 But in that case 3 is fine, because its length is 9, not 10 and 6 is doable in 3
•  » » » » » » 2 years ago, # ^ |   +15 For N = 9, you need to solve it using 3 sequences. N = 6 only guarantees 3 additional sequences, so 9 — 3 = 6 isn't good enough.If you want a larger case, the corresponding sequence for N = 25 has a similar issue: you can only remove 5 vertices from 5 10 15 20 25 4 9 14 19 24 3 8 13 18 23 2 7 12 17 22 1 6 11 16 21
•  » » » » » » » 2 years ago, # ^ |   0 My bad
•  » » » » » 2 years ago, # ^ |   0 So I get what you mean which is that in the worst case you will find that LIS and LDS are both sqrt(N), so its possible that there is some sequence where by taking sqrt(N) every time instead of sqrt(2*N) it will require more iterations :SIt just seems very hard to find such case...I tried to find a test which breaks my solution so I ran a program which tested all 9! permutations for N=9 in my code and all of them passed with K<=3, so if there is a case that breaks it it's at least N=13...Also, do you have any idea on how you would demonstrate that the complexity of my proposed solution is 2*sqrt(N)? I did a this very simple code, and it plots approx 2*sqrt(N), but I don't know how to demonstrate it formally: function f(N) { // 10=> 4, 100=>16, 10000=>193, 1000000=>1990 var ret=0; while(N) { N-=Math.ceil(Math.sqrt(N)); ret++; } return ret; } After adding the condition if len
•  » » » » » » 2 years ago, # ^ |   +8 My submission failed on test 9, which had permutations of size ~25. Maybe try permutations like that?
 » 2 years ago, # |   0 Hey I need some explanation for problem D, how to calculate the DP states, otherwise the solution is understandable.
•  » » 2 years ago, # ^ |   +4
•  » » » 2 years ago, # ^ |   +8 Thank you very much.
 » 2 years ago, # |   +3 Can anyone explain in problem F Inclusion-exclusion. I don't understand the moment, that (i / x) is square-free.
•  » » 2 years ago, # ^ | ← Rev. 2 →   +18 Inclusion-exclusion for the problem above explained: https://codeforces.com/blog/entry/51755?#comment-356983 the formula using mobius is in the editorial (it's the same thing)
•  » » » 2 years ago, # ^ | ← Rev. 2 →   +3 I solved it :)Thnanks!
 » 2 years ago, # | ← Rev. 3 →   -49 Er
 » 2 years ago, # |   0 can anyone explain how to calculate dp[k][j]? I find it hard because dont we have to calculate gcd between dp[k][j] and p^j??
•  » » 2 years ago, # ^ | ← Rev. 3 →   +18 ,because any t can be 0 ~ t with equal probability after an operation. You can notice that , so you can calculate it in O(α k).
 » 2 years ago, # |   +13 May be this is my personal problem, but the value of k was misleading for me, if it was 106 imo it will be better. For this value of k I wrote dp solution without knowledge of multiplicative function and it was very close to tl (about 3s on maxtest). When I wasted a lot of time I finally wrote correct solution, but this is D on div1+div2, so such trap is not good.
•  » » 2 years ago, # ^ |   0 Actually I was a little afraid of having TLE even with correct solution. It was O(k log^2 n) with multiplications and modules. When I checked how long it takes on maxtest (2^something) it turned out it is quick, but it's not like k could have been increased significantly ... unless you would like to require binary exponentiation of matrices ;)
•  » » » 2 years ago, # ^ | ← Rev. 4 →   0 Hm, actually complexity equals , not
•  » » » » 2 years ago, # ^ |   0 Ah yes, you're right. I mean, my code has log^2, but it is trivial to improve that, but I didn't realize since it was sufficient.
•  » » » » » 2 years ago, # ^ |   0 I think if you calculate with it's , if you calculate with it's , isn't it?
 » 2 years ago, # |   0 In problem D, can someone please explain the recurrence of the DP.
•  » » 2 years ago, # ^ |   0
 » 2 years ago, # |   +2 Anyone knows of any other problem similar to problem D?
 » 2 years ago, # |   0 in C ..how can we find out the values of a and b in single loop...thanks in advance
 » 2 years ago, # | ← Rev. 4 →   0 Anyone help me please with problem DLet f(n, k) — the math expectation of result on blackboard after k steps So, obviouslyf(n, 1) = (1 / s) * (sum(d_j))f(n, k) = (1 / s) * (sum(f(d_j, k — 1)))d_j — number through divisors sets — divisors number of nwhy this approach is wrong? also don't understand why function from solution is multiplicative
 » 2 years ago, # |   0 In problem F, I dont understand why operation 3 is bitiwse AND ?
•  » » 2 years ago, # ^ |   0 If you have A[i] and B[i] multiples of i, there will be A[i] * B[i] multiples of i after taking gcd of all pairs. Also, multiplication mod 2 is &.
•  » » » 2 years ago, # ^ |   0 Thx!
 » 2 years ago, # |   +7 Please link this editorial to contest.
 » 2 years ago, # |   0 For the third Question, how did you handle the condition of " maximum number of pairs".
 » 2 years ago, # |   +16 Hint for G?
•  » » 2 years ago, # ^ | ← Rev. 2 →   +23 It's something about Stirling Numbers of the second kind. Where S(k,i) is the Stirling Number. And ... It become a DP problem. My code:https://codeforces.com/contest/1097/submission/48029930
 » 2 years ago, # |   +53 I wrote a tutorial of problem G. https://codeforces.com/blog/entry/64367
 » 2 years ago, # |   0 The first editorial is formatted so much better than the second. Thank you for both, though! :D
 » 2 years ago, # | ← Rev. 2 →   0 For problem E, how to guarantee this partition which calculates the smallest k(Ah...I make a mistake, just forget the problem above
 » 2 years ago, # |   0 hey where can i find solution to these problems so that i can improve my implementaion skills? plzz help.
 » 2 years ago, # |   0 Perhaps irrelevant, but is there a sequence on OEIS for the term f(n) in problem E?
 » 2 years ago, # | ← Rev. 2 →   0 why in problem C, about brackets, answer is 2, but not 3? 7 )()) ) (( (( ( ) ) 
•  » » 2 years ago, # ^ |   0 How would you pair up the strings? I can guarantee that you only find 2 pairs, therefore the answer is 2.
•  » » » 2 years ago, # ^ |   0 like this one 3 (( )()) 1 5 ( ) 2 4 (( ) ) 6 7 
•  » » » » 2 years ago, # ^ |   +12 "The task is to connect some of them into ordered pairs so that each bracket sequence occurs in at most one pair and the concatenation of the bracket sequences in each pair is a correct bracket sequence."You are not allowed to combine 3 strings. So 4 6 7 is not valid.
•  » » » 2 years ago, # ^ | ← Rev. 2 →   +8 sorry, I think I got it, there it says pairs, then 3rd option is not validThanks for reply.
 » 2 years ago, # |   +32 soon™
 » 2 years ago, # |   0 Why are the editorials not linked with questions nowadays?
 » 2 years ago, # | ← Rev. 3 →   +28 Seriously, what is the record for the latest tutorial for some problem? We're close to three weeks now.
•  » » 2 years ago, # ^ | ← Rev. 3 →   +29 Let me guess, Radewoosh is still enjoying the New Year, so he hasn't uploaded the editorial yet
 » 23 months ago, # | ← Rev. 2 →   0 In F,"instead of storing the parity of numbers equal to x, store the parity of numbers divisible by x." Is it divisible by X or divisors of X??
 » 9 months ago, # |   0 How can we solve this problem using Dynamic Programing, there is dp tag given to this problem. I am a beginner so could someone help me with this ....
•  » » 7 months ago, # ^ |   0 which problem bro?
•  » » » 7 months ago, # ^ |   0 Problem B
•  » » » » 6 months ago, # ^ |   0 i also dont under the problem B
•  » » 9 days ago, # ^ | ← Rev. 2 →   0 Clockwise means $+a_i$ and counterclockwise means $-a_i$. And you need to find a subset of clockwise moves $A_{cw}$ and counter-clock-wise moves $A_{ccw}$. To open the lock, it must satisfy $\sum_{a\in A_{cw}}a-\sum_{a\in A_{ccw}}a=360*k$ for an integer value of $k$. Rewrite the above formulation, you have $2\sum_{a\in A_{cw}}a-S=360*k$ where $S=a_1+...+a_n$. So generating subset sums of $2a_i$ (it is a classic DP problem) and check if any of them satisfies the above condition, or $2\sum_{a\in A_{cw}}a=S$ (mod 360).
 » 4 months ago, # |   0 Could anyone please tell the intuition behind using bitmasks in problem B? Also any hint for DP solution?