ZCO 2016 discussion

@aalok_sathe and @alphastar: Say a= {1, 2, 3, 7, 8}, b= {1, 5, 6, 7, 8} and k=2. Swapping a[n-1] and b[0] gives the same skewness as swapping b[n-1] and a[0]. Which one do you choose? If you swap a[n-1] with b[0] you can get an arrangement with skewness 12 after the next swap. If you swap b[n-1] with a[0] the minimum skewness you can get after another swap is 14. How do you break the ties efficiently?

Here’s what I did for Bookshelves (got AC in contest; expecting 200 overall): Note that the largest book must contribute to the skewness. Our objective is to minimize the other book which contributes. To do this, we must bring the larger books to one of the arrays so that the maximum book of the other array is as small as possible. Let’s try the first case: we try to bring the large books to array a. Suppose there are p instances of the largest book in the second array. We need to bring these p instances to the first array. If we have enough amount of swaps and space available, we do this and do the same thing with the second largest book and so on. (Note that you must also take care that the total number of elements in the first array cannot exceed n.) Then do the same thing for the second array and print whichever solution is optimal. This can be implemented nicely with maps in O(n log n).

1 Like

i was able to get the bamboo stick one’s first subtask with brute force. it ran in o(n^3).

I got Bookshelves subtask 1 with brute force. Didn’t get subtask 2 of Bookshelves. For Bamboo Art, I sorted the input in increasing order, and then something like this:

max = 1;

for (i = 0; i < n-max; i++)
{
for (j = i+1; j < n; j++)
{
diff = l[j] - l[i];
for (k = l[j]+diff; binarysearch(l, n, k) != -1; k += diff)
temp++;
if (temp > max)max= temp;
}
}

l is the array containing the heights, n is the total no of sticks.

I got accepted on both of Bamboo Art. But I think it may fail when more input is provided.

Hey guys. Can you tell what all questions were there, please?

@AnonymousBunny Awesome :smiley: Did you use the same logic I did for problem 2?

I gave the ZCO in Delhi, and can confirm the experience was poor. Interestingly, I got 100 on Bamboo art even on a O(N^3) solution. The test cases were really weak today, I don’t expect to get 100 on actual testing.

Ideas for Bamboo Art

Sort the input array A[]

DP[i][j] = Max Length Arithmetic Progression ending at index i with second last element as index j

Observe that fixing the last element and second last element gives us the common difference D = A[i] - A[j] of the AP.

Also, observe that all elements in A[] are distinct! We can use this to our advantage to speed up the DP.

Let L[i] = Index of occurrence of the number i in the sorted array A[]

Now, the recurrence is as follows:

DP[i][j] = DP[j][L[A[j]-D]] + 1 , where D = A[i] - A[j]

Ans = max( DP[i][j] ) for all i,j where i > j

The complexity of this solution would be O(n^2)

9 Likes

@nishanthta: I used the same dp as animesh_f’s post above. My code is O(n^2 log n) because of the map, not really sure if it’s going to pass the second subtask (people are saying the pretests are weak…).

@AnonymousBunny I dont think that would be a factor, if it is so, I think you can contact the coordinator emplaining him that the logic was correct. IMO, data structure wont matter, not sure though.
Btw, why did you use map ?

Btw, it was given that the best solution will be submitted and used. For Bamboo Art, first I used int for everything, and got accepted. But later, I converted everything to long long int, and again submitted and got accepted. So which one will be used? What if the int one fails because of the input (the height was from 1 to 10^5)?

@aneesh2312 int to long long in this problem does not really matter. I had used a integer dp array of dimensions 2500’10^5. It passed the pretests and I got AC, does anyone know if this will be a problem in the system testing?

The experience at Delhi was indeed terrible. I have emailed the coordinator about the issues faced and hopefully they can do something about it.
I think I ended up scoring 130 because although my code passed the pre test-cases, they were supposedly very weak, and my solution would probably time out on decent test cases. By the way, somebody told me that problem 1 could be solved using a priority queue. Can anyone who solved it that way describe the solution, please?

Were the tests on the local server really “weak”? If that’s the case, it isn’t really fair.

And what’s the expected cut-off? Will it really be 100? If so, I guess my first and last try for IOI ends here :frowning:

I got an O(N^2 log N) solution for problem 2 (using DP and binary searching). It was taking a maximum of 0.95 seconds on the computer provided at the center but at my home it is running in 0.18 seconds. Does anyone how fast the official grading server(s) is?

how did you guys got to know your marks??
also i want to know that i compiled and run my program for many test cases and it worked alright but during submission of code system took more time to check the code and finally it showed that it doesn’t pass all the test cases. does it mean that i m not going to get any marks for that program???

@hackpert I solved it using Priority Queues.

The idea is that you must have realized that the optimal split is such that the smallest N/2 numbers are in one list and the largest N/2 numbers in the other.

So there were two cases, you could either keep swapping the min in A with the max in B, or vice versa (upto K times). Now It was necessary to get the min of A (and max of B) after swap operations, so I used a Priority Queue. This approach is O(NlogN).

In 2nd question my solution was n*10^5 and then an n^2 dp so there are chances that it can fail on larger test inputs.Also i want to know whether K can be equal to N in 1st question as N distinct swaps would mean just interchanging the 2 arrays?

@pratyush1019: Stealing another INOI seat from a worthy candidate, your girlfriend also must have scored 200 then… right?

3 Likes

Can anybody tell what was the book shelf problem about ? If you remember the statement…

Here is my code for video game challenge…three of the tests work fine but getting wa for rest…I really cant figure out why I am getting WA?

#include
#include
using namespace std;
int main()
{
long long N;
long long H;
cin>>N;
cin>>H;
long long n=1;
long long b=0;
long long a[N];
for(long long i=1;i<=N;i++)
{
cin>>a[i];
}
long long com[100000];
long long m=0;
while(1) {
cin>>com[m];
if(com[m]!=0)
{

m++;
}
else if(com[m]==0)
break;

}

 for(long long t=0;t<m;t++)
 {
 switch(com[t])
 {
 case 1:
 {
    
   if(n> 1)
   n--;
  
     else
     {}
     
      break;
 }
 
 case 2:
 { 
   if(n< N)
   n++;
   
     else{}
      break;
 }
 
 case 3:
 {
     if(b==1)
     {
     }
     else if(b==0)
     {
         if(a[n]>0)
         {
         a[n]=a[n]-1;
         b=1;
         }
         else{}
     }
        
     
      break; 
 }   
         
         
         
    
     
    
 case 4:
 { 
     if(b==0)
     {
     }
     else if(b==1)
     {
         if(a[n]<H)
        { a[n]=a[n]+1;
         b=0;}
     
         else
    
    {
    }
         
     }    
         
      break;   
         
     }

}

 }

for(long long i=1;i<=N;i++)
{
cout<<a[i];

}

}