Добро пожаловать на 2014-2015 CT S02E05: Codeforces Trainings Season 2 Episode 5 - 2009-2010 ACM-ICPC, NEERC, Южный четвертьфинал. Продолжительность тренировки — 4 часа 30 минут. Тренировка открыта как для команд, так и для индивидуальных участников. После ее окончания вы можете дорешивать задачи тренировки или поучаствовать в ней виртуально, если не смогли принять участие одновременно со всеми. Пожалуйста, участвуйте в тренировке честно.
Так как это тренировка, то возможно набор задач будет расширен, если для значительного количества участников он окажется простым.
Условия задач будут на английском языке, ведь мы же готовимся к ACM-ICPC!
Удачи!
Love that graphic. :)
I don't get the code :))
What does that graphic mean ? I don't get the point.
Neither do I, but it seems like everybody likes it.
Oh! Maybe "Get" here means "understand". Both of them don't understand the code but it works well .23333333
Exactly!
You can replace the word "graphic" with "picture" if you like. I'm using it as a noun so you'll have to scroll a bit more (http://www.merriam-webster.com/dictionary/graphic).
contest is for Practice not for cheating !
It sounds great. Thanks for this.
Hi
I feel like a confused zombie during contests, hopefully this training session brings me back to life.
Do you guys feel its wise to migrate from Java to C++ ? anything to be aware of before shooting myself in the foot?
That pic above there describes me too well xD
I don't think that it's that big of a deal for contests. On the other hand, STL may be really useful sometimes.
Well, from my expirience you can write less code using C++ as opposite to Java, and C++ is much faster than Java. I myself migrated from Java to C++. And I find C++ very pretty after using Java!
But you don't have to migrate from Java to C++ to get successful in contests like ACM ICPC. Moreover, Java is really good because of having built-in long arithmetics. Btw it's much easier to handle bugs with Java, because it simply doesn't allow your program to compile if you have commited some minor mistakes. You can spend a lot of time trying to find annoying typo in your code, since it most probably will compile.
It doesn't really matter wether you use Java or C++, because it's just an instrument. What matters is your skills and knowledge, so you better use a language, which seems to fit you better.
When is it?
This much time is left.
We call it a 'cold' joke in Chinese.
We call it cold joke too in Turkish. Actually, it's also called cold joke in English.
I can't download the problem statements. Can anyone give a link?
Ok. I downloaded it. Sorry for the inconvenience.
Can't find mistake in Perl "G. Plural Form of Nouns" solution: submission — 8159457, ideone — http://ideone.com/v1Occf
When I run this on the sample, I get:
And the last line is missing the newline character. It seems that Perl interprets newline as line separator instead of final character for each line ("lady\n" vs. "lady", "").
Thanks, you shown me a mistake, I forgot newline. I "disabled" line separator, and my mistake — I asked last regex to find and insert "s" in between "not s" and ("\n" OR end_of_string), so regex inserted "s" between "\n" (!="s") and end_of_string.
How do you solve problem E(Meetings)?
hello
IMHO, most interesting thing is to find out what test case #3 checks for. First, I thought it was because of problem misunderstanding, But so much time have already been lost for rereading((
How to solve problem F?
I wrote DP optimized by segment tree. I think there is a better solution.
Code
Indeed, I think I found an O(n) solution. It's based on the on the same DP aproach, but it optimizes finding the maximas. Namely, unlike in the LIS problem, where it has been proven to be a bound of Omega(nlogn), here we can do better because the maximas we want are quite particular. In fact, we have maximas of the kind Max(All elements of a vector except for 2 of them, the ones which have the absolute difference 1 from v[i]). Because of this, we may mantain a data structure witch supports adding a new element and deleting the smallest one (in order to mantain the 3 largest elements of the vector => One of them will always be the maximum in our vector). This is O(n) with a pretty big constant, so it's comparable with the segment tree solutions, but still O(n).
Thank you. It's the solution I've been looking for.
It works 31 milliseconds, so I don't think that constant is such big.
Here is the code
Let's denote by dp[i] = the length of the longest subsequence that fits the properties in the problem statement, ending by element i. You may easily calculate this in O(n^2), but this won't fit into the time limit. In order to optimize this aproach, you will need to use 2 Fenwick trees and a usual array (or just one single segment tree). Let's denote by x[i] = the largest dp[j] already calculated with it's v[j] = i (i.e. the largest dp with a fixed value), then the first Fenwick tree will mantain maxima on segments of the form [1,i] from x, the second one on segments of the form [i,n] and the usual array will be the vector x. Hope this helps.
thanks!
this is a really nice idea.
My idea is as follows.
Since all numbers are between 0 and 10^6, we can store the length of the longest valid sub-sequence ending with each number. We can store those values linked with their numbers in a max-heap. We begin to traverse the given array. For every number x that we encounter, we erase the values for x-1 and x+1 from the max-heap. Then we update the length of the longest sub-sequence ending with x. After that we put values for x+1 and x-1 back in the max-heap. Note that since the length of the original string is at most 10^5, max-heap's size won't be greater than 10^5.
Here is the code: http://pastebin.com/yRqtUSxV I have used STL set for the heap.
How to solve C and D?
D: I didn't succeed with Trie, it gives ML
C: I'm afraid map+dsu+dfs will not work in 0.5 s (compress the destinations with map, find all connectivity components, mark some of them as "cycled" and find the wire that should burn in every "cycled" component)
That's all I can say.
D was a typical cycle-finding problem. One can use the hare and the tortoise algorithm to solve it. You can find it on Wikipedia. It is a simple algorithm with tons of applications.
For C, Ralor's idea is pretty close to the solution. One needs to find the maximum spanning tree for the given graph.
Thanks for the hare & tortoise idea :)
C explanation -> Find mst using kruskal
But edges go in descending order of reliability[since we dont want minimal reliability edges to be included in ans]
And if same reliability, in descending order by cost[since we want higher cost]
Now insertion order is just the reverse of this
My idea of C was same but "wrong answer on test 1". code: 8557052
Can't find my mistake written in Perl in problem "A. Walking around Berhattan" (WA #6): submission — 8159769, ideone — http://ideone.com/wN8bcY . Tried some corner cases, but seemed fine.
test_
1 1
4
MRMRMRM
right answer is 10, and your answer is 7
Why 10, not 7? 4 + (4 div 2) + (2 div 2) = 7
You should only one time do div 2 rounded down for each block, and 10 = 4 + (4 div 2) + (4 div 2) + (4 div 2)
Ok, thank you. I dislike read statements :(
4 + 2 + 2 + 2, each field is divided by 2 at most once.
how do solve the problem B??? :) !
B can be solved by backtracking, Precompute if you can achieve a sum S using L elements if the elements {a1, a2, .. } (can be represented using a mask) are available.
Then use backtracking to fill each of the empty cells, and keep checking after each assignment whether the assignment is possible or not.
code
thans you !! :D!
what's the trick about K?
No tricks. Just a recursion, column by column.
can you give me some test case?
Test case? There are three of them in PDF. What do you mean?
Here is my code, if you need it: Link
sorry,I can't get your link. here is my code http://ideone.com/8udxQ0 but I can't find the error
I think your solution generate wrong output for this test:
thanks,I have found the error.
Could someone help me find what's wrong with my code? http://pastebin.com/C0eJuX1k
I get RTE on test case 19. Seems like I'm having pos>size of the word at some point (cause checking for that turns the RTE in WA :P). But it only calls parse if all the words have the same sequence of '*'s and '#'s (only) up to that point. So, since the strings are guaranteed to have at least one non '*' or '#' character, this shouldn't be a problem :(
Your program throws runtime error on a test with single line. Because it tries to get substring from negative index. Line #27.
yeah, AC now. spent hours trying to figure out this :'( lol
thanks!
Can anybody find a mistake in haskell code for task G: ideone, submission ?
You should read from "input.txt" not from stdin.
Thank you. I still cannot find where files are mentioned. Is it because of the haskell language?
It's mentioned in header of each task, also you can see that in problems page.
How to solve "D. Sequence analysis". I just use bin search for finding "second occurence of the first repeatable member". And check this in O(2e7) time. So, it work in O(2e7*log(2e7)) time. And i get TLE on 8 test.
Look at Floyd's cycle finding algorithm or Hare and the tortoise algorithm. It will work in O(n)
how did you solved it with Floyd? I did it but got TLE, here is my code: http://pastebin.com/XhZa3r77
code
thanks! I thought of exiting the first loop when iterations were bigger, but I still don't get it why it works. Isn't it possible for the algorithm to jump some comparisons and go beyond the 2e7 limit, even if it exists a solution < 2e7?
how to solve E?
Have you found a solution?
How to solve H? Are there some mathematical formulas?
as x0 = x1 = ... = xi, and you know x0 = a0 + b0 and a0 is fixed in s * p / 100, you only need to find the right b0. you can do that using binary search for values between 0 and s and checking if it needs more or less months than m for this b0. this checking can be done in O(m): at the end of m months, check if there's still some debt left. here is my code: http://pastebin.com/Va8yCuGH
I did the same thing, but with float I got TLE. Switched to double and now it works like a charm... Thank you
Why my solution to problem H always WA on test 10?8237424