Блог пользователя MikeMirzayanov

Автор MikeMirzayanov, 12 лет назад, По-русски

Добро пожаловать на 2014-2015 CT S02E05: Codeforces Trainings Season 2 Episode 5 - 2009-2010 ACM-ICPC, NEERC, Южный четвертьфинал. Продолжительность тренировки — 4 часа 30 минут. Тренировка открыта как для команд, так и для индивидуальных участников. После ее окончания вы можете дорешивать задачи тренировки или поучаствовать в ней виртуально, если не смогли принять участие одновременно со всеми. Пожалуйста, участвуйте в тренировке честно.

Так как это тренировка, то возможно набор задач будет расширен, если для значительного количества участников он окажется простым.

Условия задач будут на английском языке, ведь мы же готовимся к ACM-ICPC!

Удачи!

  • Проголосовать: нравится
  • +78
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Love that graphic. :)

»
12 лет назад, скрыть # |
 
Проголосовать: нравится -6 Проголосовать: не нравится

contest is for Practice not for cheating !

»
12 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

It sounds great. Thanks for this.

»
12 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится -13 Проголосовать: не нравится

Hi

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

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

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I don't think that it's that big of a deal for contests. On the other hand, STL may be really useful sometimes.

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    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.

»
12 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

When is it?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

We call it a 'cold' joke in Chinese.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I can't download the problem statements. Can anyone give a link?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can't find mistake in Perl "G. Plural Form of Nouns" solution: submission — 8159457, ideone — http://ideone.com/v1Occf

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +6 Проголосовать: не нравится

    When I run this on the sample, I get:

    contests
    heroes
    ladies
    s
    

    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", "").

    • »
      »
      »
      12 лет назад, скрыть # ^ |
      ← Rev. 3  
      Проголосовать: нравится 0 Проголосовать: не нравится

      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.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

How do you solve problem E(Meetings)?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

How to solve problem F?

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +6 Проголосовать: не нравится

    I wrote DP optimized by segment tree. I think there is a better solution.

    Code

    • »
      »
      »
      12 лет назад, скрыть # ^ |
      ← Rev. 2  
      Проголосовать: нравится +14 Проголосовать: не нравится

      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).

  • »
    »
    12 лет назад, скрыть # ^ |
    ← Rev. 3  
    Проголосовать: нравится +10 Проголосовать: не нравится

    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.

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    thanks!

    this is a really nice idea.

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

How to solve C and D?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

how do solve the problem B??? :) !

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

what's the trick about K?

»
12 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can anybody find a mistake in haskell code for task G: ideone, submission ?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve E?

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve H? Are there some mathematical formulas?

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why my solution to problem H always WA on test 10?8237424