### 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  Comments (30)
 » Thank you!
 » Top 3 reason for depression1)breakup2)Substance Abuse2)WA in div2 C
 » Can you somehow solve F using centroid decomposition?
 » 11 months ago, # | ← Rev. 6 →   My Solution for the problem 1749D — Counting Arrays. (Python)SimpleCommented One
 » 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?
•  » » Take a look at Ticket 16326 from CF Stress for a counter example.
 » Great problems !
 » 11 months ago, # | ← Rev. 4 →   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 :(
•  » » 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)
•  » » » You mentioned multiples, now I can see why. Thanks very much!
 » Can someone tell me why this code for problem E is always wrong?I have debuged it for 3 hours TAT
•  » » Take a look at Ticket 16349 from CF Stress for a counter example.
•  » » » OH!THANKS!
 » Nice round
 » 11 months ago, # | ← Rev. 3 →   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 →   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.
 » 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 →   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 .
 » 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.
•  » » 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 →   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!
 » 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
 » 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 →   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'; } 
 » 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 →   "You have to calculate the number of ambiguous arrays $a$ such that the length of $a$ is from $1$ to $n$"