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

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

До раунда 15 минут, а анонса всё нет. Не пропустите!

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

»
10 лет назад, # |
  Проголосовать: нравится +25 Проголосовать: не нравится

Та это Omelianenko уснул походу :)

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

Как решалась Div1-500?

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

What was the problem with DIV1 Medium? I couldn't get a solution but so many people failed the system tests or were hacked (I guess their codes TLE'd)

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

    I guess their solutions used wrong assumptions, which leads to wrong solutions, which can be easily challenged with big random tests.

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

    It's not that surprising — the first thing to expect is a greedy strategy, and many such strategies can be invented, but it doesn't actually work.

    Firstly, only relative positions of corresponding rings of the lock matter, so you can replace pairs of (original,target) positions by just their differences D0[i]. You can add a correctly placed ring to the left of the lock and transform the sequence of differences to a new one: D[i] = D0[i] - D0[i - 1] (mod 10). In this case, an operation is just adding 1 to D[i] and subtracting 1 from D[j] for any pair (i, j), or just adding/subtracting 1 from D[i] (that corresponds to rotating several rings at the right side of the lock).

    We want to convert the array D to all zeroes using a sequence of operations; the order of operations doesn't matter. If we'd add 1 to D[i] and subtract 1 from D[k] (or from no D[k]), and at some other time subtract 1 from D[i] and add 1 to D[j] (or to no D[j]), it can be replaced by one operation, for example (D[j], D[k]). That means we only rotate each ring in 1 direction.

    Let's sum up D[i] of rings which are rotated up, and sum up 10 - D[i] of those rotated down; denote them as x and y. The answer is obviously , and x - y is constant (), so if we could find all possible x, we could obtain the result quite easily. And x < 10N, so it's now clear that a DP works. Let dp[i][j] be  > 0 if j is a subset sum from the first i entries of array D, 0 otherwise; dp[i + 1][j + D[i]] = dp[i][j + D[i]] + dp[i][j].

    The time required for this is O(10N2); it can be cut down by half if we're not interested in j + D[i] for j > 5N (because then we just have y > x, and we don't want even larger y); it can also be cut down on memory to O(10N) if we only remember the last 2 rows of the array. I haven't coded it during the contest, but it should pass.

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

The actual input of the first problem is one string , making the input is two vectors of strings was very confusing!!! I wasted time until I realized that this has nothing to do with the solution.

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

    That's normal on topcoder, they can't make the input string too big because challenges are not like codeforces where you can upload a generator or something

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

      Oh thanks for information! I'm new on topcoder.

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

        Yeah, it usually is confusing for the first time. When I did my first div1 contest on TC, the 250pt problem was also partly about parsing strings (but even worse than this time), and it left me really annoyed that "the problems are not about algorithms, but string parsing". I only found out later that such formats of input are not so common.

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

      I think I was lucky coz I took few times to make a large input and then hacked 3/4 TLE codes :p. It was an awesome feelings because TLE hacks are hard to get :p.