November Cook - Off Discussion

Why no editorials till now for November Cook-off @vijju123 @admin ?

1 Like

what is wron with this code?
this code is giving wrong answer.
problem is CodeChef: Practical coding for everyone
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
int t;
cin>>t;
while(tā€“)
{
int n;
cin>>n;
int a[n],h[n];
for(int i =0 ;i<n;i++)
cin>>a[i]>>h[i];

	sort(a,a+n);
	int diff[n-2];
	for(int i = 1;i<=n-2;i++)
		diff[i-1] = a[i+1] - a[i-1];
	sort(diff,diff+n-2);
	//for(int i =0 ;i<n-2;i++)
		//cout<<diff[n-3-i]<<"  "<<index[n-3-i]<<endl;
	sort(h,h+n);
	int area = 0;
	for(int i = 0;i<n-2;i++)
		area += h[n-1-i]*diff[n-3-i];
	if(a[1]-a[0]>=a[n-1]-a[n-2])
		area += (a[1]-a[0])*(h[1])+(a[n-1]-a[n-2])*(h[0]);
	else
		area += (a[n-1]-a[n-2])*(h[1])+(a[1]-a[0])*(h[0]);
	cout<<area<<endl;
} 

}

Editorialist is working on them. Thats all I can update.

1 Like

As far as we know editorials are supposed to be prepared before the contests. :slightly_smiling_face:

can you explain me the reason why this needed
else
{
if(arr[i][j]!=0)
ret++
}

Remove the last if else condition.
Add those terms in diff. array,i.e.,(a[1]-a[0]) and(a[n-1]-a[n-2]).
Now diff contains n elements.
Sort and multipy.
NOTE-I did the same mistake during contest. :sweat_smile:

You. Have not defined n while declaring a[n]

Oh! I get it now thanks for the help : )

can you send your solution for ROBOTS using segment tree

1 Like

Ig I have stored 3 values per node: x shift caused due to range pf queries [Lā€¦R], y shift caused due to range [Lā€¦R] and angle shift caused due to range [Lā€¦R]. Build like this:
Say you have a parent with left and right pointers l and r. Then you can calculate length of shift caused by R, and the angle of this shift is sum of the angle of left + angle of right. Now we can resolve this length into x and y components, and add them to the x and y shifts of left. This gives x and y shifts for the parent. And sum of angular shifts gives angle.
Now, for query, I assume you know how to search a range in the segtree: walk down, which is the same as resolving the interval into at most \log N intervals that exist in the segtree. Note that due to the way in which the recursions are called, the ā€œleftmost and bottommostā€ interval is calculated first, and so on. This means each round of querying can add to the current angle the angle due to this subinterval; this angle can now be used as a ā€˜baseā€™ for the next subinterval. So, somewhat like a standard segtree query but slightly different.

1 Like

For the SIGNTURE problem, though the problem statement does not call out specifically that dr and dc should be choosen in such a way that all the black cells have to be considered from B, how can a signature be same if some of the black cells are not considered from B. For test case 4, how can the signatures be same with no errors. If we select dr and dc such a way that some of the black cells in B move out of index range, they should be counted as part of the flip. Otherwise it is like matching signature only to part of what is signed in B and ignoring the rest of black cells from B. May be the problem statement is not looking for that, but it does not make sense to say the signatures are same.

This video editorial might be useful for understanding the concept behind ROBOTS problem of novemberā€™19 cook off : [Tutorial] Codechef Nov'19 Cook Off - ROBOTS - YouTube

1 Like

Loved your explanation bro :slight_smile: