### chokudai's blog

By chokudai, history, 4 months ago,

We will hold AtCoder Beginner Contest 173.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

• +75

 » 4 months ago, # |   -13 Participate, we must.
 » 4 months ago, # |   -8 Hope that C is not the killer this time :p
•  » » 4 months ago, # ^ |   -6 you jinxed it (at least for me) :(
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 this is third time in a row that,I'm able to solve A,B,D but not C ):
•  » » » » 4 months ago, # ^ |   0 My Solutioncan anyone please check my solution and correct me?????
•  » » » » 4 months ago, # ^ |   0 same bro :(
•  » » » » 4 months ago, # ^ |   0 i used backtracking.
•  » » » » » 5 weeks ago, # ^ |   0 really bro
 » 4 months ago, # |   0 Starts in 15 mins :)
 » 4 months ago, # |   +21 See you all on the scoreboard!
•  » » 4 months ago, # ^ |   +36 Video editorial and screencast are being uploaded to my youtube channel now. There are lots of nice solutions described in the comments here (and the atcoder editorial is usually quite good), but if you would like to see stuff explained more visually, feel free to look out for that :)
•  » » » 4 months ago, # ^ |   +3 cant find atcoder 173 in ur channel... is it in the process of being uploaded as of now?
•  » » » » 4 months ago, # ^ |   +22 Yeah it is being processed by Youtube right now. I hate to say this because it sounds so cliche, but there is a bell icon you can click if you subscribe if you want to get an email when YouTube decides to finish processing it.
•  » » » » » 4 months ago, # ^ |   +17 subscribed !! upload more and more tricks, tutorials and solutions of cf and atcoder rounds i guess u r the only cp channel in youtube with the clearest english accent!keep up the good work
•  » » » » 4 months ago, # ^ |   +19 Looks like Youtube is finally done! Here’s it is :)The video quality will improve as it processes. Usually it is only 360p or something for a bit, even though it is recorded in 1080p.
•  » » » » » 3 months ago, # ^ |   +18 orz that F solution was so damn cool!!
 » 4 months ago, # |   -8 not able to solve C again!!!
 » 4 months ago, # |   0 How to solve D?
•  » » 4 months ago, # ^ |   0 always try inserting new comer into two maximum existing values! Submission
•  » » » 4 months ago, # ^ |   0 That was a good idea.Should have thought of that.
•  » » 4 months ago, # ^ | ← Rev. 2 →   +2 Greedy, keep track of which element contribute to the answer and how many times, like the 1st one contribute only 1 time to the answer, rest of the numbers does it twice. So just take the (sum of largest n / 2 element — 1st largest).
•  » » 4 months ago, # ^ |   0 I tried this approach ll n,i,sum=0; string s; cin>>n; vector a(n); for(i=0;i>a[i]; } if(n==1){ cout<<"0"<=(n-1)) break; ans+=a[i]; ct++; if(ct>=(n-1)) break; ans+=a[i]; ct++; } cout<
•  » » 4 months ago, # ^ |   +2 I maintained a priority queue, if anyone is interested I can explain the solution , because I think people have posted better solutions.
•  » » 4 months ago, # ^ | ← Rev. 6 →   0 Mine was a O(nlogn) solution by sorting the given friendliness of each player in decreasing order. And Taking into account the cases: First element will contribute exactly one time to the answer. All the other elements will contribute exactly 2 times. So just take sum of them in the order mentioned till you reach exactly n-1 numbers.
•  » » » 4 months ago, # ^ |   0 I also did using same approach but My Solution is failing some test case. Can you please point out the error and link your solution.
•  » » » » 4 months ago, # ^ |   0 Your code is not considering the case that other elements will contribute twice. Try to change your approach.
•  » » » » » 4 months ago, # ^ | ← Rev. 2 →   0 Please link your solution and how every element will contribute twice??
•  » » » » » » 4 months ago, # ^ | ← Rev. 2 →   0 Yeah Sure! CODE
 » 4 months ago, # |   0 What the hell with me . can solve D but not c ..everytime stuck on c..
•  » » 4 months ago, # ^ | ← Rev. 2 →   +5 Consider all 2^h subsets of rows and 2^h subsets of cols and then try every pair of subsets that is brute force for all 2^h*2^w subsets
•  » » » 4 months ago, # ^ |   0 what is "Meet in the Middle"?
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   0 Meet in the middle is a standard technique to divide the problem into two halfs and brute force over all the possible subsets of the problem. SOme problems on Meet in the middle: if you want to practice. Meet in the middle practice problems
•  » » » » » 4 months ago, # ^ |   +1 Thank you so much. I heard this technique for the first time.
•  » » » » » » 4 months ago, # ^ |   +34 This is not at all meet in the middle, but just basic brute-force. Meet in the middle would be something like: iterate through all subsets of rows, all subsets of columns and somehow combine result from them in time complexity closer to $O(2^W + 2^H)$ then $O(2^{WH})$
•  » » » » » » » 4 months ago, # ^ |   0 Ya you are right , I have to edit it as when I was writing my mind was out of my body, sorry if it disturbed someone.
•  » » » » » » » 4 months ago, # ^ |   0 What if the constraints were somewhat bigger. What would be the efficient approach then?
•  » » » » » » » » 4 months ago, # ^ |   +3 My first thought would be: iterate through all $2^H$ subsets of rows, for each column find number of black cells at intersevtions of given column and one of chosen rows, then use some basic dp to count subsets of those numbers adding up to $K$. Total complexity is $O(2^HWK)$
•  » » » » » » » » » 4 months ago, # ^ | ← Rev. 2 →   0 Quite a nice idea. Thanks!
•  » » » 4 months ago, # ^ |   +7 I am sorry but where's the Meet in the Middle part in C, it's just plain brute force.
•  » » » » 4 months ago, # ^ |   0 Ya While writing it I was thinking of some other thing! Sorry !
•  » » » » 4 months ago, # ^ |   0 Yeah, exactly, LOL. This is a simple bruteforce solution.
•  » » » » » 4 months ago, # ^ |   0 But try extending the problem to H<=20 and W<=20, I think then we have to go for that? or may be some other heuristic.
•  » » » » » » 4 months ago, # ^ |   0 how can be solved using Meet in the middle ?
•  » » 4 months ago, # ^ |   0 Same here Solved D but not C
•  » » 4 months ago, # ^ |   0 C is just BruteForces My submission
•  » » » 4 months ago, # ^ |   0 Can you please explain??
•  » » » » 4 months ago, # ^ |   0 Iterate over all subsets of rows. Now for each subset of rows, iterate over all subsets of columns. Iterating over the subsets can be easily done by  for (i = 0; i < 1<
•  » » 4 months ago, # ^ |   0 since it was only 6. I did the Bruuuuuuuute force. Generated all sized subsets then ran a loop for every row and every column and for each combination checked whether it's valid or not. My Submission-C
•  » » » 4 months ago, # ^ |   +1 It's better to be general, rather than doing all combination do all subset. To find all subsets just use integer from 0 to 2^n — 1.Btw felt the need to tell this because your code was a bit lengthy.
 » 4 months ago, # |   +5 What's the approach for F ?
•  » » 4 months ago, # ^ |   +9 You can consider the nodes and edges independently if you count nodes as +1, and edges as -1
•  » » » 4 months ago, # ^ |   +8 Uhmm, can you elaborate a bit ? Thanks!
•  » » » » 4 months ago, # ^ |   +45 If you have a forest, the total number of components is nNodes — nEdges.You can easily count the number of ranges a node is part of with combinatorics, and same for an edge (it is just nLeftRangeEndpoints * nRightRangeEndpoints). So you can count this contribution of each node and each edge as if it were the only thing in the graph.
•  » » » » » 4 months ago, # ^ |   +16 Oh wow, quite elegant a solution!
•  » » » » » 3 months ago, # ^ |   0 Can you tell me whats wrong with this submission?? https://atcoder.jp/contests/abc173/submissions/15045823
•  » » » » » » 3 months ago, # ^ |   0 When N = 1, your code gives 0 as output instead of 1.
•  » » 4 months ago, # ^ |   +13 It is similar to this question of codeforces
•  » » » 4 months ago, # ^ |   +11 In fact it is exactly this question asked.
•  » » » » 4 months ago, # ^ |   +14 Not exactly, the tree in codeforces question is linear. But we can convert a[i — 1] , a[i] logic to parent, child logic and it works same.
•  » » » » » 4 months ago, # ^ |   +11 Yes, you are right.
 » 4 months ago, # | ← Rev. 4 →   +52 Brief Editorial : AJust print $\left \lceil n/1000 \right \rceil * 1000-n$ BYou can use a "map" . CJust try all the states.in $O(2^{(H+W)}*W*H)$ DFirst you can easily find that all the player arrive in a fixed order,that is "Decreasing Order".But how to prove ,it is also very easy.Because if i-th player arrive earlier than j-th player,and ai (k-i+1)-th * (k-i+2)-th positive integers the present result is bigger than the last one.Otherwise end the loop.Because the product of the negative integers is decreasing , but the product of the positive one is increasing. FSuppose ui
•  » » 4 months ago, # ^ |   +3
•  » » 4 months ago, # ^ |   +11 F nice formular, but not understandable for those who did not solve it.
•  » » » 4 months ago, # ^ |   0 Sorry I will update it later ,I have something to do now.
•  » » » » 4 months ago, # ^ |   0 Use this until then https://codeforces.com/blog/entry/79733?#comment-656818
•  » » 4 months ago, # ^ |   0 Problem D:I have implemented it in the exact way that you mentioned, but it just happened to fail at only 2 test cases, can you help me in finding out the bug in my submission ?
•  » » » 4 months ago, # ^ |   0 Than consider how many times the biggest one is added to result?Yes,**exactly once**.Because when you let the second the one arrive,the first one is added to the result.
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   0 I added the biggest element exactly once!
•  » » » » » 4 months ago, # ^ |   0 You can compare yours with mine.
•  » » » » » 4 months ago, # ^ |   0 OK, got it, thanks!
•  » » » 4 months ago, # ^ |   0 if n = 1 then answer will be 0 not a.front().
•  » » » » 4 months ago, # ^ |   0 Is N ever less than 2?
•  » » 4 months ago, # ^ |   0 can you explain F?
•  » » » 4 months ago, # ^ |   +5 The idea is to count the edges, somehow... Because the count determines the number of components.
•  » » 4 months ago, # ^ | ← Rev. 3 →   0 In solution F: My understanding: X= contribution of all the nodes in total summation Y=Contribution of each edge in the total summation ans=X-Y Kindly explain your recurrence(I understood Y ,kindly explain X)?
•  » » » 3 months ago, # ^ |   0 Can you tell me what's wrong with my submission?? https://atcoder.jp/contests/abc173/submissions/15045823
•  » » » » 3 months ago, # ^ |   0 check your code when N=1.
 » 4 months ago, # |   +7
•  » » 4 months ago, # ^ |   0 Isn't this unfair, giving a question which is already available online, I mean the exact same question, most of the participants who googled something similar to find hints might have ended up copying the exact same code without any efforts of their own.
•  » » » 4 months ago, # ^ |   0 The code provided doesn't have the mod 1e9+7 part, and that's a little bit tricky for negative numbers.
•  » » » 4 months ago, # ^ |   0 In the last 2 contest I have seen happening this for C and now E.
 » 4 months ago, # |   0 How to solve E and F? Thanks in advance:)
•  » » 4 months ago, # ^ |   +18 E: case out n==k, and when everything is negative.Otherwise, you can repeatedly remove the smallest two nonegatives and replace them with the largest two negatives as long the product of the two negatives is bigger.F: You can consider nodes and edges independently. Each node contributes +1 to the answer, each edge -1. You just need to count the number of ranges each node and each edge is part of.
•  » » » 4 months ago, # ^ | ← Rev. 5 →   +6 In E why after sorting both positive and negative numbers then repeatedly removing pair from the end which has maximum value(product) and if k is odd and there are only 2 positive numbers left then only removing pairwise from negative numbers didn't work?For odd K when i first removed the largest positive number separately and solve the rest for even k worked, why?
•  » » » » 3 months ago, # ^ | ← Rev. 2 →   +5 Consider this testcase: 5 3 -2 -1 1 1 3 The first method will select 3 and 1 since 3 x 1 > (-2) x (-1). Then it has to select 1, the only positive number left. However, 3 * 1 * 1 < 3 * (-2) * (-1)That problem can be remedied by ensuring that whenever two numbers are selected together at either end, another two numbers will be selected at either end unless no more element will be selected. It is easy to show that strategy cannot be wrong. That is why the second method works, because for even K, the maximum product, if it is greater than 0, must come from even number of positive numbers and even number of negative numbers.
•  » » » 4 months ago, # ^ |   0 Your solution for E is just brilliant. Thank you
•  » » 4 months ago, # ^ |   +3 For F for every segment think that every element is disconnected, and their contribution to answer is the length of segments. Now for each edge see in how many segments it can occur and subtract that number from answer.
 » 4 months ago, # |   +3 Another Series :)Multiplication 1Multiplication 2Multiplication 3Multiplication 4
 » 4 months ago, # |   0 Ok! can anybody tell me how to solve C? :)
•  » » 4 months ago, # ^ |   0 brute force, check all possibilities
•  » » 4 months ago, # ^ |   0 just look up all possible way to select rows and columns either by bitmasking or dynamic programming and check number of blacks for each combination
•  » » 4 months ago, # ^ |   +8 Brute forceCheck for all possible subsets, if we exclude these then if the number of black cells is k or not.Max number of rows = 6Max number of subsets of rows = 64Max number of columns = 6Max number of subsets of columns = 64Total number of subsets = subsets of rows * subsets of columnsMax total number of subsets = 64 * 64Complexity to check each subset = O(nm)Total complexity = O(2^n * 2^m * n * m)
•  » » » 4 months ago, # ^ |   0 Thanks man!
•  » » 4 months ago, # ^ | ← Rev. 2 →   +4 You can just brute force all the possible choices and for each choice count the number of remaning black squares. Check my submission for details: https://atcoder.jp/contests/abc173/submissions/15012234
 » 4 months ago, # |   +5 E was on codechef as MMPROD.
 » 4 months ago, # |   +13 Wow, E took me forever (and a lot of WA and lots of messy casework). Wondering if anyone has a cleaner solution.
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 I was too getting wrong ans on 1 test case . Then I checked the modular operation I was doing and found the error in it
•  » » 4 months ago, # ^ |   0 I think it is less code if we separate the numbers into three groups, counting also the 0.https://atcoder.jp/contests/abc173/submissions/15010921
•  » » » 4 months ago, # ^ |   +1 My solution with comments
•  » » 4 months ago, # ^ |   +29 I think mine is much cleaner. The idea is that you case out n==k and cases in which all numbers are negative.Otherwise, you can start with the positive numbers, and replace two positive numbers with two negative number repeatedly.That code is just:  int nPos=Math.min(pos.length, k); int nNeg=k-nPos; if (nNeg%2==1) { nNeg++; nPos--; } while (nNeg+2<=nNegs && nPos>=2 && pos[nPos-1]*(long)pos[nPos-2] < negs[nNeg]*(long)negs[nNeg+1]) { nPos-=2; nNeg+=2; } print(mul(posCS[nPos], negCS[nNeg])); 
•  » » » 4 months ago, # ^ |   0 Nice solution!
•  » » » 4 months ago, # ^ |   0 Ah, that is a lot nicer. Thanks! I'll try implementing it later.
•  » » » » 3 months ago, # ^ |   +10 btw congrats anand finally made it to red!!
•  » » » » » 3 months ago, # ^ |   +3 Thank you!
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 I was also approaching the problem in the similar manner. I was checking the two largest negatives not taken with two largest positives and whichever product is greater I was taking those two elements.But I got confused when the case when we will have to take odd number of negatives.So how to handle the product in such a case(i.e how to take the modulo in that case) or there won't be any case like that?UPD:Got it there was just a small mistake in implementation.I was printing the wrong value:(.
•  » » 4 months ago, # ^ |   0 https://www.geeksforgeeks.org/maximum-product-subsequence-size-k/Here is good implementation
•  » » 7 weeks ago, # ^ |   0 E also makes me frustrated. :'(
 » 4 months ago, # |   +1 Defeated by Mod ;____;
•  » » 4 months ago, # ^ |   0 Same
 » 4 months ago, # |   0 can we see others submission? if yes then how?
•  » » 4 months ago, # ^ |   0 click on Results, then All Submissions
•  » » 4 months ago, # ^ |   0 If you want to see submission of a perticular person then, go to standing hover over the username and click on the searching symbol (magnifying lens). You can also do that by writing the username in all submissions. But I like the first one this way I can see the fastest submissions.
 » 4 months ago, # |   0 Can somebody guide me to an article(or anything for that matter) which has good theory on bitmasking? Couldn't solve C this time! (easy to read)Code for A, B, D, E @ https://atcoder.jp/contests/abc173/submissions/me
•  » » 4 months ago, # ^ |   0 https://atcoder.jp/contests/abc173/submissions/14996063I can explain you if you need help for C
•  » » » 4 months ago, # ^ |   0 Thanks, that'd be great!
 » 4 months ago, # |   0 For D, getting WA on 9 test case , please help, what's wrong in my code. https://atcoder.jp/contests/abc173/submissions/15012383
 » 4 months ago, # |   +3 For Problem EFirstSecondFirst code is not working for 2 testcases so i added one if for k==n that is second code and Second code is not working for 3 testcases. I can't understand how it is possible can anyone help me?
•  » » 4 months ago, # ^ |   +5 because your if(k==n) part is wrong
•  » » » 4 months ago, # ^ |   +3 How Can you explain i can't get it still?
•  » » » » 4 months ago, # ^ |   +5 Why are you doing mul=-mul? You are anyway multiplying the actual numbers.
•  » » » » » 4 months ago, # ^ |   +3 thanks got it.
 » 4 months ago, # |   0 I tried E by sorting all the numbers. If all the numbers in the array are positive the max product of k numbers is last k numbers. otherwise, we need to find the maximum of the first k numbers and the last k numbers and print the maximum. What is wrong with this logic.
•  » » 4 months ago, # ^ |   0 Consider this testcase: 5 4 2 1 0 -1 -2 The product of first k numbers and the product of last k numbers are 0, but the correct answer is 4.
•  » » » 4 months ago, # ^ |   0 Yes, got it. Thanks
•  » » 4 months ago, # ^ |   0 Suppose the array is- -4 -3 -2 -1 0 1 3 4 and k = 4 Product of first k numbers = 24 Product of last k numbers = 0 Your Answer = 24 Actual Answer = (-4)(-3)(3)(4) = 144
•  » » » 4 months ago, # ^ |   0 Answer should be(-3*-2*-1*1)-6%1e9+7=1000000001 no?
•  » » » » 4 months ago, # ^ |   0 i got it, thanks though
•  » » 4 months ago, # ^ |   +1 It can be solved with a simple brute force approach. Notice that h,w <=6, so just iterate over all possibilities and check.
 » 4 months ago, # |   0 I didn't even understand the problem statement of C.. xD
 » 4 months ago, # | ← Rev. 2 →   +8 Anyone's comparing summation of log2()s failing for E?? can anyone explain how to overcome it??
 » 4 months ago, # |   0 What is wrong in this : Try to take even number of negative numbers starting from descending order and multiply with even numbers left , again in descending order.If the above is not possible, then check if a zero exists.If a zero exists, ans is zero else answer has to be negative.SO, try to take odd number of negative numbers in ascending order and choose remaining numbers as even, again in ascending order ?https://atcoder.jp/contests/abc173/submissions/15018728
•  » » 4 months ago, # ^ |   +11 A%mod > B%mod does not imply A >B
•  » » » 4 months ago, # ^ |   +2 I know, I haven't used that.Apparently,the mistake is overflowing of the product.Thanks anyway.
 » 4 months ago, # |   0 Can someone kindly explain the E problem https://atcoder.jp/contests/abc173/tasks/abc173_eHere is a link to my solution and also give a test case where it fails. https://atcoder.jp/contests/abc173/submissions/15013047
 » 4 months ago, # |   0 Anybody used gfg's code for problem E?? If yes,please share your sol, i want to see my mistake!
•  » » 4 months ago, # ^ |   0 The Python code had an incorrect range for CASE II. Also, to avoid TLE, the mod had to be applied throughout.
•  » » 4 months ago, # ^ |   0 Yes, but got 26 AC and 11 WA. Maybe has some issue with modulo
 » 4 months ago, # |   0 Can anyone explain how to approach C ?
 » 4 months ago, # |   0 May somebody help me debug my code? Getting WA on one testcase. https://atcoder.jp/contests/abc173/submissions/15021212
•  » » 3 months ago, # ^ |   0 You can view all of Atcoder's testcases here
 » 4 months ago, # |   0 My Solutioncan anyone please check my solution and correct me?????
 » 4 months ago, # |   0 can anyone explain the approach of Problem C , I was able to solve A, B, D but not C. https://atcoder.jp/users/aniketakgec/history/share/abc173
•  » » 4 months ago, # ^ |   0 It is brute force .you can store count of no of black cell in rows and columns in an array . And then simply brute over all the possibilities of selecting row and column (i used bitmasking for it) . And can use above array to count number of black cell in each case ,if it is k , do ans++;
•  » » 4 months ago, # ^ |   0 Notice that the constraints for this problem are noticeably little, so all you need to do is to consider all possible combinations of rows and columns. Then, check how many of them have k remaining black cells.My Submission for this problem
•  » » 4 months ago, # ^ |   0 Simple brute force, try all possible combinations of rows and columns that are to be painted and simply count the no of black cells left in O(h*w) for a particular combination, total time complexity — O(2^h * 2^w * h * w)
 » 4 months ago, # |   0 Someone please help , why my logic is wrong in task D: In D , i observed a pattern , suppose if we sort array , then : Best optimal way to gain points is : 0 , a[n], a[n-1],a[n-1],a[n-2],a[n-2],a[n-3],a[n-3],etc... (k times)  But i got WA . Codevoid solve() { ll n; cin>>n; ll a[n+3]; ll ans=0; for(ll i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+n+1); ans=a[n]; ll i=0; ll p = n-1; ll f=0; while(i>t; while(t--) { solve(); } } 
•  » » 4 months ago, # ^ |   0 For n=1 your code gives the result a[n] but it's 0.
•  » » » 4 months ago, # ^ | ← Rev. 3 →   0 In problem constraints n>=2 , btw i got my mistake , i forgot to put f=0 inside f==2 condition , Can't believe , i wasted 40+ minutes to find my bug , but was not able to observe it while in contest .
•  » » » 4 months ago, # ^ |   0 Question says N >= 2
•  » » » 3 months ago, # ^ |   0 in constrains 2 ≤ N ≤ 2×10^5
 » 4 months ago, # |   0 It was a nice contest. Thanks for sharing the link.
 » 4 months ago, # | ← Rev. 2 →   0 What is wrong with this code of E- Solution#include #define mod 1000000007 #define ll long long int using namespace std; ll maxProductSubarrayOfSizeK(ll A[], ll n, ll k) { sort(A, A + n); ll product = 1; if (A[n - 1] == 0 && (k & 1)) return 0; if (A[n - 1] <= 0 && (k & 1)) { for (ll i = n - 1; i >= n - k; i--) product =((product%mod)*(A[i]%mod))%mod; return product%mod; } ll i = 0; ll j = n - 1; if (k & 1) { product =((product%mod)*(A[j]%mod)); j--; k--; } k >>= 1; for (ll itr = 0; itr < k; itr++) { ll left_product = ((A[i]%mod) * (A[i + 1]%mod))%mod; ll right_product = ((A[j]%mod)*(A[j - 1]%mod))%mod; if (left_product > right_product) { product = ((product%mod)*(left_product%mod))%mod; i += 2; } else { product =((product%mod)*(right_product%mod))%mod; j -= 2; } } // Finally return product return (product%mod); } int main() { ll t=1; //cin>>t; while(t--){ ll n,k; cin>>n>>k; ll arr[n]; ll i; for(i=0;i>arr[i]; } ll z=maxProductSubarrayOfSizeK(arr,n,k); cout<<(z%mod+mod)%mod<
•  » » 4 months ago, # ^ | ← Rev. 2 →   +3 Not sure if this is all but that block outputs negative numbers, the mod calculaton is not correct:  if (A[n - 1] <= 0 && (k & 1)) { for (ll i = n - 1; i >= n - k; i--) product =((product%mod)*(A[i]%mod))%mod; return product%mod; } 
•  » » 4 months ago, # ^ |   0 this code is from g4g
 » 4 months ago, # |   +14 Initially, problem C had the constraint H, W <= 13 and needed DFS and pre-calculation :(
•  » » 4 months ago, # ^ |   0 Well, today's C was easy i.e. just briteforce. But was definitely much harder than regular ABC's
•  » » 4 months ago, # ^ |   +1 How to do if H,W <=13, Can someone please explain the approach a little bit. I solved for the low constraints using bitmasking.
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 can c be solved using recursion if yes can you please explain it? I am trying to solve it using recursion for hours but it's not working.
•  » » 4 months ago, # ^ |   0 Here is my DFS solution (O(2^{H + W} + H * W * 2^H)): https://atcoder.jp/contests/abc173/submissions/15031206Actually, the DFS part of the code can speed-up by using dynamic programming (like the knapsack problem) and solve the problem in O(H * W^2 * 2^H).
•  » » » 4 months ago, # ^ |   +1 Link is broken, could you correct it? I am very interested in reading it.
•  » » » » 4 months ago, # ^ |   +3 Sorry, It’s now available.
 » 4 months ago, # | ← Rev. 2 →   +23 In problem E-Multiplication 4 I was checking whether they have this kind of test case 5 4 1 2 3 -1 0 in their test set or not.so, I removed one condition in my code and got AC instead of WA.Output produced by AC code is 1000000001 ( -6 % (10^9 + 7) ) you can see here. Where the correct answer is 0.
 » 4 months ago, # |   0 OMG I misread problem E as maximum of all possible k length subsequences (a1*a2*a3*....ak)%(1e9+7). How to solve this task?
 » 4 months ago, # |   +4 Got WA in B due to writing capital 'X' instead of small 'x'
 » 4 months ago, # |   0 My submission for E is giving WA for 5 tests. Actually I tried only limited cases:First I sort array of absolute value of numbers descending order If first k have even number of negatives, we got our answer Otherwise we remove smallest negative and search for a positive among remaining n-k elements. If found positive, then this is an estimate. Another estimate is dont take one non negative among first k elements and search for a negative in remaining n-k elements. If negative is found then this is another estimate. If none of 2, 3 occurred then we know our answer must be negative so we chose last k elements as estimate. Otherwise we chose biggger of 2, 3. Is this wrong? While writing this comment I realised that I havent checked which one of 2, 3 yields greater value. ;p submission link
 » 4 months ago, # |   0 I had a problem with E, most of the test cases passed but I don't know why I was not able to have AC on E. can anyone help me ? here is my the link to my code https://atcoder.jp/contests/abc173/submissions/15005580
•  » » 4 months ago, # ^ |   0 It is wrong logic. Among other things you totally ignore that there can be 0 in a[].
•  » » » 4 months ago, # ^ |   0 Thanks for the reply. I tried the geeks for geeks solution which included the case when there is a 0 in a[] but still got WA verdict. here is my code https://atcoder.jp/contests/abc173/submissions/15012483 Can you have a look at it? Thanks!
 » 4 months ago, # |   +8 English editorial may be helpful for all coders.
 » 4 months ago, # |   0 Can someone tell me why this solution is failing on certain cases.
•  » » 4 months ago, # ^ |   0 It is wrong logic. Consider the third and fourth being added to the circle.The third contributes min(a[0], a[1]), and the fourth, too. Because the fourth is placed on "the other side" of the second, which is between second and first, too.
•  » » » 4 months ago, # ^ |   0 How third and fourth will contribute min(a[0],a[1])?? In the given example third is contributing min(arr[1],arr[4]) and fourth min(arr[3],arr[2])
•  » » » » 4 months ago, # ^ |   0 After third a[0], a[2], a[1], after fourth a[3], a[0], a[2], a[1]a[2] and a[3] where both placed between a[0] and a[1]. Its a circle.
 » 4 months ago, # |   0 I have submitted several times and still getting WA on three specific cases. https://atcoder.jp/contests/abc173/submissions/15025193Is anyone stuck in the same cases to give me hand, because I have really no idea what is wrong. My main logic is to get the max K numbers and apply a replacement when the parity of negatives is an odd number.Thank you !
 » 4 months ago, # |   0 In Atcoder the correct order must be A, B, D, C. Thrice in a row I was not able to solve C. Can anyone help pls. :(
 » 4 months ago, # |   0 ll solve(){ ll n; cin>>n; if(n==1) return 0; multiset> ms; for(int i=0;i>a; ms.insert(a); ms.insert(a); } int sum=0; int count=0; for(auto x: ms){ if(count>0) sum+=x; //deb(sum); count++; if(count==n) break; } return sum; } why this code is giving WA for D
 » 4 months ago, # |   0 please explain solution of C in easy language..
•  » » 4 months ago, # ^ |   0 Basically we have to pick a subset of rows and a subset of columnsThen count the number of # character in those selected rows and columns say cnt if the (total # in matrix)-(cnt) equals k then increment the answerDo this for all combination of subsets of rows and columns i.e. 2^(W) * 2^(H) combinations
•  » » » 4 months ago, # ^ |   0 Can there be cases where we have to choose 3 rows or 4 rows to get the desired number of black colors??I mean is there any restriction on how many rows or columns we can choose in a single time to get the desired number of black colors??
•  » » » » 4 months ago, # ^ |   0 No there is absolutely no restriction that way.
•  » » » » » 3 months ago, # ^ |   0 Thank You......and sorry for the very late reply
•  » » » 4 months ago, # ^ |   0 oh now i understand what is going on.. thanks bro
•  » » 4 months ago, # ^ |   0 Since the constraints are small, we can use brute force. Notice that there are h rows and w columns. If we represent each row and each column by a bit, then we can use a bitmask of the form (1<
 » 4 months ago, # | ← Rev. 3 →   0 In D question, why can't the max element be added more than once? For example, consider the case :52 2 3 3 3Won't the max element be added more than once here??UPD: I understood. Ignore this comment.
 » 4 months ago, # | ← Rev. 5 →   0 My code passes all the tests except one. I can't figure out any mistake. Please help. Link to my submission Edit: I got my mistake. Here is my new submission
 » 4 months ago, # |   0 What is wrong with this approach for E? I covered the other cases such as only negatives and k=n. So when both positives and negatives are there, we take biggest elements by absolute value in our answer and count the number of negatives. If number of negatives is even, this is our answer. Otherwise, I am trading the least positive value in my taken numbers with biggest negative value among left out numbers or trading least negative value with the biggest positive value among left out numbers, whichever is better. Any counter test case for this ?
•  » » 4 months ago, # ^ |   0 Please help me its failing on 2 testcases. Submission
 » 4 months ago, # |   0 Can anyone help me understand why this code fails for a few testcases https://atcoder.jp/contests/abc173/submissions/15031526i inserted the element as pair where first = absolute value and second value = 0 if positive else 1 and sorted the elements using abs value.In case of all negative elements i picked first k elements.Otherwise i picked the last k elements and noted the number of negative values(say nneg) and also kept track of the first negative value i picked(say firstneg).ifnneg is even then i print the product else in the first n-k elements i first look for maximum positive element and failing to do so i pick the least negative value and multiply it by product and multiply it by inverse of the firstneg.
•  » » 4 months ago, # ^ | ← Rev. 3 →   0 vkm23061998, your code fails for this TC. Maybe, this helps.Input:8 61000000000 1000000000 -1000000000 -1000000000 -999999999 999999998 -999999997 999999996Correct Answer:192080(By taking the first 4 numbers and -999999999 and -999999997)Your Output:237699(By taking the first 4 numbers and 999999998 and 999999996)
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 Also, I have done in a similar way, as yours. My code is passing all the testcases. You may like to view it : Link to my submission
 » 4 months ago, # |   0 Can anyone provide proof for the problem D.
•  » » 4 months ago, # ^ |   0 Same here. the proof in editorial is not sufficient imho.
•  » » 4 months ago, # ^ |   0 Here is my proof not depends on people arrived in the decreasing order. Consider all the n-1 comfort we can get. I will prove: If there are k numbers >= x, others < x, then among all comfort we can get, there are at most 2*k-1 comfort >= x.We note these k person as nice person, and the position between 2 nice person as nice position. also we note comfort >= x as nice comfort. 1. There are at most k-1 nice comfort we can get when these k nice person arrive(first nice person can not get nice comfort). 2. when a nice person arrive, nice position will increase at most one, when a not so nice person get a nice comfort, he must decrease a nice position. so not so nice persons can get k nice comfort at most.so we can get at most 1 comfort >= a[0], 3 comfort >= a[1], and so on...
•  » » » 3 months ago, # ^ |   0 Brother i got you. Thanks
•  » » 3 months ago, # ^ |   0 Think greedily Since we have to maximize the total comfort, so we'll try to get the maximum comfort possible every time. Maximum comfort using some i friends=Maximum comfort using some i-1 friends + maximum comfort from any remaining friend. By exchange arguments,step 2 will end up in maximum total comfort.
 » 4 months ago, # |   0 can any one explain me why this wrong in case of problem E ans=((ans*a)%mod+mod)%mod but this gives me AC ans=((ans+mod)%mod*(a+mod)%mod)%mod WA:https://atcoder.jp/contests/abc173/submissions/15038118 AC:https://atcoder.jp/contests/abc173/submissions/15038907
 » 4 months ago, # |   +6 For E, what is the case 'after_contest_01.txt'? My code is getting 500 as it passes all the tests from the contest but fails on this one.Note: It's also not in the TestCase Dropbox.
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 I don't know if it will solve your problem but my code was failing for the same case only. Check this case. Input : 7 5 35 25 5 -25 -25 -25 -25 Output : 13671875
•  » » 3 months ago, # ^ |   +8 I guess, maybe you've made pairs of positive/negative numbers and multiplied them. And if K is odd, then you multiply another positive number to the answer. I tried this as well and it got a WA on the case 'after_contest_01.txt'. You can multiply the only (not paired) positive number first if K is odd. It did solve my problem, hope it'll be helpful to you too.BTW, you can check the code since my English isn't good:
 » 4 months ago, # |   0 Can anyone check my submission for problem E : https://atcoder.jp/contests/abc173/submissions/15041696 it fails on just single case.Not able to figure out.
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 Test: random_mz01.txtThe Output is 0. Expected is 649491334prod=prod * a[i]%MOD * a[i+1]%MOD;`Won't this overflow?
•  » » » 4 months ago, # ^ |   0 ok... I was returning a 0 if the max element in array is 0 immaterial of k(even or odd).That was the problem.Thanks for the test case.It works now :)
•  » » » 3 months ago, # ^ |   0 random_mz01.txt? Are the OJ inputs freely available somehow? I don't see them linked anywhere from AtCoder.jp…
•  » » » » 3 months ago, # ^ |   0 Yeah they are: AtCoder Post
•  » » » » » 3 months ago, # ^ |   0 Yup, thank you!
•  » » » » 3 months ago, # ^ |   0 Ha! Found it. https://atcoder.jp/posts/21 :)
 » 4 months ago, # | ← Rev. 2 →   0 Please help in question E, why does this give WA????
 » 4 months ago, # |   0 Can someone look at this approach for C? Link to the post
 » 4 months ago, # |   0 What's wrong with my E submission? Submission
 » 4 months ago, # |   0 What wrong in my submission in E ,it's failing on 6 test cases https://atcoder.jp/contests/abc173/submissions/15042752 ?
•  » » 3 months ago, # ^ |   +10 arpit_pro, vkm23061998, your code fails for this TC.Input:8 61000000000 1000000000 -1000000000 -1000000000 -999999999 999999998 -999999997 999999996Correct Answer:192080(By taking the first 4 numbers and -999999999 and -999999997)Your Output:237699(By taking the first 4 numbers and 999999998 and 999999996)Hope, this helps.
 » 3 months ago, # |   0 Can anyone give a proper explanation of problem of C ? I didn't get the editorial.
 » 3 months ago, # |   +18 Someone knows What's in "after_contest_01.txt"? （Problem E）
•  » » 3 months ago, # ^ |   +8 I don't know if it will solve your problem but my code was failing for the same case only. Check this case. Input : 7 5 35 25 5 -25 -25 -25 -25 Output : 13671875
•  » » » 3 months ago, # ^ |   +18 thanks,bro~
•  » » 3 months ago, # ^ |   0 Nuclear launch codes
 » 3 months ago, # |   +20 For some (like me) who still couldn't figure out Fg(l,r): be graph of vertices[l,r]e(l,r): count of edges in g(l,r)f(l,r): count of connected components in g(l,r)f(l,r) = count of vertices in g(l,r) — count of edges in g(l,r)$\displaystyle\sum\limits_{l=1}^n \displaystyle\sum\limits_{r=l}^n f(l,r) = \displaystyle\sum\limits_{l=1}^N \displaystyle\sum\limits_{r=l}^n ((r-l+1) - e(l,r))$ $=\displaystyle\sum\limits_{l=1}^n \displaystyle\sum\limits_{r=l}^n (r-l+1) - \displaystyle\sum\limits_{l=1}^n \displaystyle\sum\limits_{r=l}^n e(l,r)$First part is easy O(n). For second part Let c(u,v) be number of ranges edge(u,v) contribute to$c(u_i,v_i) = u_i*(n-v_i+1)$Hence, $\displaystyle\sum\limits_{l=1}^n \displaystyle\sum\limits_{r=l}^n e(l,r) = \displaystyle\sum\limits_{i=1}^{n-1} c(u_i,v_i)$PS: My first attempt at an explanation. I think there should be line-spacing option.