### awoo's blog

By awoo, history, 11 months ago, translation,

1749A - Cowardly Rooks

Idea: BledDest

Tutorial
Solution 1 (awoo)
Solution 2 (awoo)

1749B - Death's Blessing

Idea: BledDest

Tutorial

1749C - Number Game

Idea: BledDest

Tutorial
Solution (Neon)

1749D - Counting Arrays

Idea: BledDest

Tutorial
Solution (BledDest)

1749E - Cactus Wall

Idea: BledDest

Tutorial
Solution (Neon)

1749F - Distance to the Path

Tutorial
• +51

 » 11 months ago, # |   +4 Thank you!
 » 11 months ago, # |   +3 Top 3 reason for depression1)breakup2)Substance Abuse2)WA in div2 C
 » 11 months ago, # |   +5 Can you somehow solve F using centroid decomposition?
 » 11 months ago, # | ← Rev. 6 →   0 My Solution for the problem 1749D — Counting Arrays. (Python)SimpleCommented One
 » 11 months ago, # |   0 I was trying to solve problem E using BFS + backpointer table for tracing steps. I have been debugging for an hour, but can't figure out why my solution is not optimal — is there a bug somewhere? Can someone pls help?
•  » » 11 months ago, # ^ |   -10 Take a look at Ticket 16326 from CF Stress for a counter example.
 » 11 months ago, # |   0 Great problems !
 » 11 months ago, # | ← Rev. 4 →   0 In D, I understand that if the i-th element is not "bad"(it can be removed only if it is at position 1), it's factors must contain all primes from 1 to i.My question is: Why the number of good(not bad) elements is $\dfrac{m}{p_1p_2...p_k}$, where $p_k$ is mentioned in the editorial. Could somebody enlighten me why it is obvious :(
•  » » 11 months ago, # ^ |   0 For position i if you call an element not bad if it can only be removed at the first position, then the element must be divisible by all the prime numbers present in [1,i]. Let's say there are k prime numbers in [1,i] : p1, p2, p3...pk.Now, what is the smallest valid not bad element for the position i could be?It would be: L.C.M(p1,p2,...pk) = p1.p2.p3....pkWhat are the other valid not bad elements possible for the position i? It would the Multiples of L.C.M(p1,p2,...pk) = p1.p2.p3....pkHow many valid not bad elements possible for the position i in [1,m]m/L.C.M(p1,p2...pk)
•  » » » 11 months ago, # ^ |   0 You mentioned multiples, now I can see why. Thanks very much!
 » 11 months ago, # |   0 Can someone tell me why this code for problem E is always wrong?I have debuged it for 3 hours TAT
•  » » 11 months ago, # ^ |   0 Take a look at Ticket 16349 from CF Stress for a counter example.
•  » » » 11 months ago, # ^ |   0 OH!THANKS!
 » 11 months ago, # |   0 Nice round
 » 11 months ago, # | ← Rev. 3 →   0 Can anyone explain why the problem 1749E — Cactus Wall the path carved out by 0-1 DFS would always satisfy cacti cannot grow on cells adjacent to each other by side as we are not storing the cacti in the current path(only checking the initial cacti)?
•  » » 11 months ago, # ^ | ← Rev. 2 →   +4 Note that we do BFS traversal in an order that satisfy the initial constraints as well as we maintain the constraints by traversing diagonally. It suffices to check this, since only one of the path will be our answer (which will obviously satisfy the constraints as it has been constructed that way).TLDR : Since we only traverse diagonally to construct the path, the constraint is maintained for all paths (individually). This is necessary and sufficient.
 » 11 months ago, # |   0 The key observation of problem E is very interesting. I'm wondering if we can generalize this problem.Say you're given a map consisting of '.', '#', 'A' and 'B'. You need to grow cactus so that one cannot go from an 'A' cell to a 'B' cell. In this case how can we find the starting and the ending point of the shortest path?For example for the following map: .#.#. ..#.. .AAA. ..A.. ...BB .BBB. one must grow cactus like this: .#.#. ..#.. #AAA# .#A#. ..#BB .BBB. We can't just start from an arbitrary cell in the first column and ends at another arbitrary cell in the last column. There seems to be more restrictions.
 » 11 months ago, # | ← Rev. 2 →   0 For problem C. Number Game Can someone explain why this solution with int is getting a TLE but same solution with long got accepted as n<=100 and a<=n .
 » 11 months ago, # |   0 In C, Obviously, it is more profitable for Bob to "prohibit" the smallest element of the arrayNot to me. What about the case when Bob, using this tactics, takes the same integer multiple times? What if during her turn, Alice couldn't have taken all of them anyways? So that Bob wasted some moves and could rather take some other elements that Alice already took? Could you show the proof that such situation never happens? It really puzzled me during the contest and still does. Any help is appreciated.
•  » » 11 months ago, # ^ |   +1 Not sure of your example. But i can try to explain the first line.Let's suppose there are some elements and each time Alice can remove element <= k-i+1 and bob can add the same amount to any element after Alice's turn. So if you see k-i+1 is decreasing and after Alice chance, if bob is going to add any k-i+1 to any element it will surely go beyond the scope of Alice next chance no matter how small or big number bob added it on(take any example and verify it). So bob will always try to take the smallest number as it will decrease Alice's chance to select element with k-i+1 condition in next turn. whereas if bob had selected any other number there is possibility Alice might use smallest in next turn. You can think of this problem as Alice remove one element and then Bob is also removing one element by increasing it byeond the Alice's scope.
•  » » » 11 months ago, # ^ | ← Rev. 2 →   0 whereas if bob had selected any other number there is possibility Alice might use smallest in next turn.This is what I was looking for! Mystery solved, thanks!
 » 11 months ago, # |   0 I had taken the contest which was attempted by over 10k+ people , out of which my code coincidently matched with one of the persons wherein I was the one who had submitted before. It can be a complete coincidence as I had not given my code to anyone nor do I know that person by any means. Also , no one keeps any evidences as one does not know this error is gonna come . I generally write my contest code very differently but I could not do it this time as I started an hour late. The question has an easy logic and it van be same for many people that does not mean it is a case of plag . It is just that the same approach struck to us and we coded it Please look into it and reflect back my ratings as these things can happen once in a many time . Writing this in response to :"Attention! Your solution 177196148 for the problem 1749C significantly coincides with solutions tsvk/177196148, introvert_coder1/177204459. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://codeforces.com/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked."
•  » » 11 months ago, # ^ |   0 Also please open your eyes and see that I have used dequeue and he has used multiset and although our solution is slightly similar , it is not the same. And if you think that out of 10000+ people even 2 of them can't think of and code "similar" solutions , man what kind of system is it . It's a request man , please look into it and do not decrease my ratings.
•  » » 11 months ago, # ^ |   0 And talking about the multiset part in my code , that code was sent to me by my roommate to test during the contest to test as he was getting some error in that and you can clearly see that it is a comment not a code. I just debugged it and sent it back to him and commented it out. I do not know where the hell he got the code from but the approach that I have used to solve the problem is entirely different of what has been found in the plag check . Please look into it and do not take any actions on my account . Review our code , their is absolutely no match in the logics that we have used to solve the questions.
 » 11 months ago, # |   0 I can't prove the following lemma used in Problem E There exists no path from top row to bottom row only if there is a zigzag path consisting of $#$ from a cell in the leftmost column to a cell in the rightmost column. It is very intuitive to see it by drawing some pictures, but I just can't get around proving it formally. I tried induction on $n•m$, greedy proof strategies etc. But nothing seems to work. Any help? BledDest
 » 11 months ago, # |   0 For C: Number game, I had a solution that is O(nlogn), although I understand the constraints didn't require it. the idea was binary search for k.I devised a function "doesKWork" that takes inputs as the k to check and also an array where a[i] stores the number of elements lesser than or equal to i present in the original array. bool doesKWork(vector &lEq,int k) { int j = 0; for (int i = 1; i <= k; i++) { if(lEq[i] >= k+i-1) { continue; } else { return false; } } return true; } for k to be a valid number such that Alice wins in optimal play by bob, this must be the condition satisfied. each lEq[i] >= k+i-1. then its just simple binary search for k. //binary search on k //lesserThanOrEqualTo is a vector calculated before, check submission for details int l = 1, r = n; int ans = 1; bool setAns = false; while(l <= r) { int mid = (l+r)/2; if(doesKWork(lesserThanOrEqualTo,mid)) { //then we check the ahead segment l = mid+1; continue; } else { //then we check the segment before mid r = mid-1; continue; } } cout << l-1 << endl; You can check my submission for reference 177187641
 » 11 months ago, # | ← Rev. 2 →   0 Hi :)I can't figure out why my O(n^2 log^2(n)) solution for problem C gets TLE. I have a function, to check if its possible to win. I think it runs O(k log(n)) (please correct me if I am wrong) // O(k log^2(n)) bool is_possible(multiset& A, int k){ multiset was_removed; multiset was_added; for(int max_v = k; max_v >= 1; max_v--){ { if(A.size() == 0){ return false; } // what is the maximum value less than or equal to k? auto it = A.upper_bound(max_v); // O(log^2(n)) finds first element strictly greater than k; if(it == A.begin()) { // there is no value less than or equal to k for(int b : was_removed){ A.insert(b); } for(int c : was_added){ auto it = A.find(c); A.erase(it); } return false; } it--; // iterator to maximum value <= k was_removed.insert(*it); A.erase(it); } { if(A.size() == 0){ continue; } // add to the minimum auto it = A.begin(); int v = *it; A.erase(it); was_removed.insert(v); A.insert(v+max_v); was_added.insert(v+max_v); } } for(int b : was_removed){ A.insert(b); } for(int c : was_added){ auto it = A.find(c); A.erase(it); } return true; } If I try to search through all k's, I get TLE void solve() { int n; cin >> n; multiset A; for(int i = 0; i < n; i++){ int a; cin >> a; A.insert(a); } int max_k = 0; // O(n^2 log(n)) for(int k = 0; k <= n; k++){ // O(k log(n)) if(is_possible(A, k)){ max_k = max(max_k, k); } } cout << max_k << '\n'; } I did binary search and got AC. But I'm still curious why does the previous solution not run fast enough. void solve2() { int n; cin >> n; multiset A; for(int i = 0; i < n; i++){ int a; cin >> a; A.insert(a); } // binary search the maximum k (0 <= k <= n), such that is_possible(A, k) is true int lo = 0; int hi = n; while(lo < hi){ int mid = (lo + hi + 1) / 2; if(is_possible(A, mid)){ lo = mid; } else { hi = mid - 1; } } cout << lo << '\n'; } 
 » 4 months ago, # |   0 In problem D, why isn't the total number of arrays just $m^n$ ? Why should we take $m^1 + m^2 + ...+m^n$ ?
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 "You have to calculate the number of ambiguous arrays $a$ such that the length of $a$ is from $1$ to $n$"
 » 2 months ago, # |   0 For Problem C Why does Bob has to always choose min element ?Isnt it more profitable to choose an minimum element,such that after bob adds the score, the minimum becomes safe element ? Suppose if it doesnt become safe, alice can simply negate the move by deleting the unsafe element in next round.There by Bob wasting his move ?