Recently we ran another ACM ICPC quarterfinal qualification contest, whose results influenced the list of teams that will go to Saratov this autumn. The corresponding gym contest on Codeforces will be held on Sunday, Sep 21, 2014, at 11:00 AM.
Link to the contest: 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest
The list of our previous contests:
- 2012, V Samara Regional Intercollegiate Programming Contest
- 2012, Samara SAU ACM ICPC Quarterfinal Qualification Contest
- 2013, VI Samara Regional Intercollegiate Programming Contest
- 2013, Samara SAU ACM ICPC Quarterfinal Qualification Contest
- 2014, VII Samara Regional Intercollegiate Programming Contest
Thx~It seems Chinese have no time to participate in it because of the online contest
How to solve E.? My idea was to use DP. Try all possible split points and solve sub-problem (like matrix chain multiplication) but I couldn't implement it (size of string was an issue as well).
no DP lol, just check for odd and each char contains less then n/2 times.
Could you elaborate?
Why is this correct?
When you have exact n/2 same letters (for ex. 'a') your strategy is to erase letter 'a' and not 'a'. After this operation you'll have again half 'a' letters.
It is clear that it is possible.
You can't erase more than 1 letter 'a' per turn. You are going to do n/2 turns, so you must have less or equal n/2 'a' letters =)
Sorry for my bad english.
Could someone explain me why this is not correct?
I have an stack, for each letter I check the letter on the top of my stack. If it's the same I "push" the new letter, otherwise I "pop" the last one (different letters so could be eliminated) At the end I check the size of my stack, if it's zero my answer is YES
Your algorithm can't pass test "abcc":
Size of stack will be 2 and your answer will be "NO"
But you can remove 'b' and 'c', then 'a' and 'c', so correct answer is "YES"
I can be proved by math induction!
My friend solved this with an extremly short greedy algorithm. Define d[x] as the number of letter x in the string. Declare it as d[300] so that it cover all kind of letters in the ASCII table (not needed though).
At the start of the algorithm: res = s.length(); Then we iterate through every possible character x, and decrease res by d[x]. If d[x] > res-d[x] then the result is NO, else if the algorithm reach the end, the result is YES.
Guys, can you explain why you write all these treaps and splay trees in problems that don't require them?
What is the approach to solve problem I ? In sample test 3 , Why is there no possible answer : I think the possible answer might be 1 2 3 2 . I might be wrong , am I missing anything ?
two region is differents color if only if these is neighbors. In other word if region u the same color region v -> these ara not neighbors
How to solve Problem K (Two Pirates)? Why is greedy approach not working for this problem? And what can be perfect approach to solve this question.Any help?
A counterexample to greedy : 99,1,2,100.
My method :
Use DP, let dp[2k] denote the maximum that the first pirate can get after 2k turns, and the two pirates take only the first 2k items. So we can write dp[2k]=max( dp[2k-2]+a[2k-1] , dp[2k-2]+a[2k] , dp[2k-2]-m+a[2k-1]+a[2k] ),
where m is the minimal value that the first pirate took in dp[2k-2].
My code gives 199 2 as output for this test case.That is as expected to happen.And can you please explain your DP .How you come to it ?
Here is what I did : Suppose I am having a segment tree to update an elemnt and find maximum in a range. cin>>arrLength;
First of all, thanks for the solution. :)
I tried to implement your idea, and it passes the 2 given test cases (and the ones I made) but I keep getting Wrong Answer on Test Case 1.
Can somebody help me in figuring out where is my mistake?
My code: 7949600
Anti-greedy test:
6 3 8 7 2 4 1 5
. We should take 8 and 7, and remain 6 and 3 at the first two iterations.The process described in the problem is equivalent to the following: the first pirate takes all items, but every even step he throws away the cheapest one. Easy to implement with priority queue.
Is answer for your test case 23 13 (As is provided by my approach)?Also whats the priority criteria to throw away the cheapest item.Please explain.Is position of element used as priority criteria?
Optimal solution is 24 12: first pirate takes 8, 7, 5 and 4.
About priority criteria: is the word "cheapest" so unclear?
On every prefix [1, k] of the array (k is even) first pirate must take no more than k/2 items. Think about it. But we take all items, and when we discover that we have taken too many items, we throw away the one with the lowest price. It happens after every even turn.
someone explain the approach behind problem M
Answer:
Length — a*b
(b-1)*a+1, (b-1)*a+2, .. (b-1)*a+a, (b-2)*a+1,(b-2)*a+2,..,(b-2)*a+a, ..., 1,2..,a
Can you please explain how you arrived at this solution. I had no idea on how to proceed :(
I saw a pattern in small tests:)
Excuse me, could anyone explain the meaning of Prob A? Where is the black hole and whether it could move? Thanks a lot!
Sorry for my poor English.
You have a circle moving into a triangle, you cant move so 1 point of circle is out of triangle. Calculate the (surface where some point of circle can be)/(surface of triangle)
Thank you! I misunderstood the word "part" in the problem.
Any hints for solving C and I( I don't understand simple test case #3)?
To solve the problem I, read this: https://en.wikipedia.org/wiki/If_and_only_if
Of course, i know what is "if and only if".
But i understand from this: "The final version of the map two regions must have different color if and only if they are neighbour regions." => I can use only two colors or i'm wrong?
Can you check my code 7895549?
Why only two colors? If we invert that statement, we get "two regions must have the same color if and only if they are not neighbour regions". Create the inverse of the graph and paint each connected component its own color. Then check if all conditions are satisfied.
Sorry , could you please elaborate . I didn't get your comment.
Condition (two regions must have different color if and only if they are neighbour regions) is equivalent to (two regions must have the same color if and only if they are not neighbour regions).
Consider an inverse graph. All its neighbour vertices must have the same color.
Find its connected components and paint each of them its own color.
Check if the condition from (1) is true.
At first I thought the problem was asking for whether the graph is k-color-able or not. Now I realize that I misunderstood the problem. "if and only if" really changed the meaning.
C Let a and b the desired numbers, then:
a*b=n*(a+b) -> a*b-n*(a+b)+n*n=n*n -> (a-n)*(b-n)=n^2, so
a-n and b-n — divisors of n^2. (a,b) = (d+n,n^2/d+n)
We need to find all divisors of n^2.
You can find the factorization of n for sqrt(n). n = p1^a1*...*pk^ak, n^2 = p1^(2*a1)*...*pk^(2*ak). And then recursively find all possible divisors of n^2 using factorization of n^2.
http://pastebin.com/LVKRQaEq
Another solution of C:
n * (a + b) = ab
Let's g = gcd(a, b), so a = g * a', b = g * b'
n * g * (a' + b') = g * g * a' * b' -> n * (a' + b') = g * a' * b'
g = n * (a' + b') / (a' * b')
We can see, that gcd(a', b') == 1 -> a' and b' can't be divisors of (a' + b') -> a', b' are divisors of n
So solution is: Iterate over all pairs(a', b') of divisors n, check gcd(a', b') == 1, find g = n * (a' + b') / (a' * b') -> a = g * a', b = g * b'
http://pastebin.com/LtBR5Suh
This is how i solved the problem.
ab = nab => b = na/(a-n)
This is a function b(a). Graph has asymptote a = n. For all (a < n) => b < 0. => Our possible b looks like b = n + c = na/(a-n); where is c >= 1. Ok, lets solve this.
a = n*n/c + n; b = n + c.
code: http://pastebin.com/rU1cDd1L
Can someone tell me why my solution for problem E is not correct ? Basically, my idea consists of matching each character with another one different from it.
I solved problem E with this pseudo code:
Normally, my code should handle those cases. Can you spot the problem please ?
What if
al = {8, 6, 4, 4}
?My code will give NO. How can the matching be done ?
This is not very hard, just take a pen and paper and figure it out by yourself.
I always end up with two characters. How come please.
Every turn choose two maximal numbers and descrease them by 1.
Can problem L use other idea other than splay?
Use three deques: for left, middle and right parts, and one boolean flag — if the middle part is reversed.
ALMOST EVERYONE has used treaps or splay trees. It's just a three star local SSAU contest, of course, there is much easier solution!
Can you explain it in more detail?How does the reverse operation update?
Easy, just
midReversed ^= true
.Then, if you move one of the heads, let's say it's the left head moving to the left, you should 1) pop the last character from the left deque 2) push it into the mid deque, and depending on
midReversed
flag it is push_front or push_back.in the question l<r is given then how this is possible for n==1
How to solve A.?
Simple geometry: http://ideone.com/bEzVz0
The key thing is a knowledge about similar triangles and their proportions: https://en.wikipedia.org/wiki/Triangle#Similarity_and_congruence
I did not understand your solution. How did you use similar triangles? The only part I understood is using Heron's theorem for area. Please explain.
S == p*r
If S1 and S2 are the areas of two similar triangles, then
S1 / S2 == k^2
, where k is a ratio of their sidesThe same is correct for the areas of the similar parts of the similar triangles
What is this? Come on dude. Invest some time in writing something readable.
Maybe you find some time to learn basic school geometry? Believe me, it will be very helpful.
Just explain your solution in English and don't try to make an impression :)
Draw a triangle that is similar to the given one and for that the inscribed circle has the radius r. The rest is up to you.
Muuuuuuuuuuuuuuuch better :)
Let me try to explain it.(Atleast my solution, don't know if it is the best one) With Cosine Theorem, we can calculate angles of the given triangle. Now, we need to subtract from area 3 surfaces(in every corner, one), where some point of the circle will never be albe to be in. The picture will look like this: The famous picture You need to subtract the red surface from red+green one Colored one^^ Red+green one is 2*surface of right-angled triangle with sides r and the opposite angle one of the angles of the triangle/2(Can be easy calculated by some easy trigonometry) Red one is (PI-angle/2)/(2*PI)*(r*r*PI) (Surface of the circle) Do that for every 3 points(A,B,C), add the green surfaces, and print 1-(sum of green surfaces/area of rectangle(Can be calculated with Heron's formula. Wish I helped.
It's like using splay trees in problem L, see my solution above :)
In Problem G, I tried a greedy approach since all coins are multiples of each other ! But it doesn't work can someone give me a counter example!
My code is here
It doesn't work because you haven't thought about overflow of integer types.
Thank you ! I thought that the max would be 109 × 105 while it is 109 × 105
Just stop that if coinValue>sum, you wont be able to use that coin eitherway.
How to solve H,J,K?
H: binary search on the cost of the cheapest trick made
J: find the answer in the following form:
aa..aabcaa..aadeaa..aafg......
K: see in the comments above
what's the second testcase of J,I can't find a worng case for my code.
First test cases are the same as in the PDF. Your solution doesn't output anything on the second test case.
BTW, you can check your answer using the solution to problem H from NEERC: 2012-2013 ACM-ICPC Northeastern European Regional Contest (NEERC 12)
Sorry again,I used your idea by tring many random cases .But I still can't find any error.
I find a mistake just now,thanks again.
Could you explain H? I can't understand how we get an answer if we know the cheapest trick made.
We should count total number and total cost of tricks with price >X — we'll made them all. Total cost may be calculated as sum of few arithmetic progressions.
And we also know that cheapest trick has cost X, therefore all remaining tricks (total number of tricks minus number of tricks with cost >X) also have cost X.
can we have an editorial?
You can find parts of editorial in comments here or ask for the missing problems
How to solve I?
Was explained above: /blog/entry/13826#comment-188679
What's test 24 of prob C? I got TLE but I don't know why.
My codes: A B C D E F G H I J K L M