Hello!
Today, October 23 (Sunday) at 08:00 (UTC) will begin online contest based on recently completed ACM-ICPC NEERC Southern Subregional Programming Contest 2011. Two days ago a competition was held in Saratov (hosted by Saratov State University), but today you can participate in it informally. Onsite participants will in the standings, to give you an oppotunity to compare your results with onsite teams. The statements will be available as a PDF-file and in HTML. To participate, go to the site http://acm.sgu.ru.
After the contest, you may discuss here the problems. I hope you'll like them.
Chairman of the Jury,
MikeMirzayanov
for seg1 in vertical segments
for seg2 in vertical segments (index of seg2 > index of seg1)
{
curCnt = 0;
for seg3 in horizontal segments
if seg3 intersects seg1 && seg3 intersects seg2
curCnt++;
ans += curCnt*(curCnt-1)/2;
}
print ans
Could you explain your approach and share the code, if possible?
in the all rest you are right
How can you know that brute-force is too slow for this problem?
I only see 10! different possibilities, and at each possibilitie you just calculate the gcd with the previous gcd. Is the gcd operation (euclidian's way) to slow for this strategy?
I got AC by just checking 10 random numbers! 10^5 is so much!
And how to approach the Berland Chess problem, constraints says solution will be exponential, but looks too complex for me, please elaborate.
[nice habbit btw. :) ]
I guess you are telling it will be lesser, but how?
Magic.
It's proofable that any array can be sorted in no more than 2 multiswap operations.
If array is sorted, answer is 0.
Now, let's suppose that all numbers in array are distinct. So, we can consider this array as some permutation. Have a look at graph representation of this permutation.
Answer is 1 if this graph contains cycles only with length no more than 2 (we can swap elements of this cycles and sort array this way).
If there is at least one cycle of length more than 2, answer is 2. You can notice that swapping two elements of some cycle, divides this cycle into two cycles. This way by one multiswap operation you can divide any cycle into cycles of length no more than 2. goto previous paragraph.
If not all numbers in array are distinct, we can enumerate all identical numbers as consecutive distinct numbers, and apply algorithm above, so we can still sort array in no more than 2 operations. But not any enumeration will form permutation which requires minimal possible amount of operations for sorting. So, I don't know, what exactly should we do if not all numbers are distinct.
Exactly - try to use greedy matching for sorting in one step, if this fails and two steps are required, you can assume that this is a permutation and use the solution above.
> b=ind+1, line 109
Seems to be wrong for test like this
4 1
100 100500
200 1
300 1
400 100500