Comments

This wasn't a part of the problem, but I was wondering what is the maximum number of rectangles that can be formed for problem D?

My approach

Please correct me if I am wrong.

Can someone explain why this solution fails? Instead of finding the length of the side directly, I found it using an indirect approach. Submission

I found the length of the longest diagonal and then using Pythagorean theorem the side of the square can be found. I think there were some precision issues with square root calculation. How to go around this?

Edit: Got the problem. The setprecision() is in the wrong order :(

Is there a name for the technique used in E? Or where can I read more on it (formal proofs, etc.)?

$$$b$$$ cannot be anything. $$$a_i \lt = b_i$$$ for all $$$i$$$ has to still hold for the inclusion-exclusion calculation to hold. P.S. Thanks for the link.

How would you solve $$$(a, D)$$$? This is precisely where I was stuck.

A quick Google search found the definitions of these terms but only in the context of the ambiguities that arise out of using them :)
I hope that contest setters will define their terms in upcoming contests.

Anyway, I feel that despite this I stumbled upon an interesting problem. How would you approach problem C if non-descending is to be interpreted as not descending and non-ascending as not ascending.
For example, if $$$[1, 2, 3, 4]$$$ and $$$[3, 2, 1, 5]$$$ are non-descending (say).

I spent the entirety of the contest and much later trying to solve this but couldn't. Any ideas?

Well, when they say sorted in some order, the ordering is often clear. For example, if they say sorted in alphabetical, lexicographic, ascending or descending, it is known what they mean or even then in some cases, they explicitly define the ordering.
What kind of ordering does non-descending or non-ascending establish?
I understand from here that it is fairly obvious to everyone who got an AC and even to several others, but it wasn't obvious to me. I just feel it should have been defined for the benefit of participants.

What is the meaning of non-ascending? Isn't the array $$$[1, 2, 5, 4]$$$ non-ascending because, well, it is not ascending?

Yes, I figured it out. I was comparing the numbers stored in the arrays incorrectly.

for (int i = 1; i <= n; i++) 
    if (num1[i] > num2[i]) 
        flag++;

This is not the correct way to check if num1 > num2. Thanks!

Could anyone here help me figure out what's wrong with my solution for Div 2 (C)? I have tried to follow the editorial here.
Link.

+2

Yes, that makes sense if the tester is expecting an $$$O(1)$$$ or $$$O(log n)$$$ solution. But I suppose for $$$O(n)$$$ and $$$O(n log n)$$$ solutions, it hardly makes a difference.

+1

Are you saying that having several separate test cases is worse than having the same test cases compiled into a single query-based test case?

I'm assuming that the former works by generating a single output file from the code and running it several times. The latter would work by running the same output file only once in this case. But even then I don't see how there would be a significant benefit from doing this.

+1

Is there some added advantage on asking query-based test cases? Do they do it so they can test on more cases this way?

0

It's always taken care of on its own. For ex., when you're doing 98+76, you're essentially doing (9*10)+(8*1)+(7*10)+(6*1). Any generated carry will be taken into account in the calculations by itself.

+1

It's very similar. You just have to be careful about the weights in the 10's expansion that you assign to the longer number.

For this, my approach was to maintain a frequency array having a[i] as the number of elements with length i.

Now, for each number in your input array, traverse its 10's expansion. If you're at the ith digit then surely, all numbers with >=i digits will ensure that this ith digit will play out similarly as in D1. Only for numbers with <i digits, you'll have to figure out the 10's expansion weights.

For ex., f(12,3456) = 341526 and f(3456,12) = 345162. Observe how for the lowermost 2 digits, this case was similar to the case for D1, ie. f(12,56) and f(56,12). You only have to be careful about the weights you assign to 3 and 4. You should be able to arrive at an equation for the weights in terms of the len(a[i]) and i. Think about it.

My submission: http://codeforces.me/contest/1195/submission/57237562

+7

Observe that for each digit of each number, you can predict what position it would occupy in the functional output. For ex., if the numbers are 22 34 then f(22,34) = 2324 and f(34,22) = 3242. So, the ith digit in, say, x would be the 2*ith or the (2*i + 1)th digit in the functional output. So, simply iterate over the 10's expansion of each number and add to an ans variable the value that each digit in the expansion would occupy in the output.

To complete the example above, you'd have s=(4*(10^0)+4*(10^1))+(3*(10^0)+3*(10^1)) from 34 for each number it is going to be paired with. Each number will be paired with n numbers (including itself), so, you'd have ans+=(n*s) for 34. Proceed similarly for each number in the input array.

My submission: http://codeforces.me/contest/1195/submission/57225770

With reference to the editorial for problem B:

It can be shown that the answer does not depend on the order of deletions.

Can this fact be elaborated on?

I tried a few cases but I'm unable to build an intuition for this. For ex., consider the string abcbbccbb. There are several places that you can start performing operations from, but no matter where you start, you will always end up with only 3 operations. I can't manage to prove this though. Any help would be very appreciated.