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

Автор giorgosgiapis, 6 лет назад, По-английски

Third round of COCI 2017/2018 season will take place this Saturday at 14:00 UTC.
You can find the full schedule for this season here and register for the contest here.

Let's discuss the problems here after the contest.

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

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

Sorry if this question has been asked before, but I quickly Googled it just now and can't find it.

Is there a way to change our COCI account password? Thanks.

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

duration ?

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

Good luck to everyone!

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

Weird. I don't see tasks.

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

Is there something with 0, (2^m)-1 and subsequence that xor of all elements == (2^m)-1 in E task?

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

How to solve C, E, F?
Is there smth faster than for C?

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

    E: An interval can't win iff it contains exactly 2k pair (x, 2n - 1 - x).

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

      Do you have any proof?

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 3   Проголосовать: нравится +16 Проголосовать: не нравится

        Proof is easy. Let its xor sum be X. Then for each element a in that interval we must have a^(2n - 1)^X also is in that interval. So we have d pairs (a, a^(2n - 1)^X). Because its xor sum is X, so X must be 0.

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

      How do you check if an interval meets the condition effectively?

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

        Denote N = 2M - 1.

        You can answer the queries of the type "maximum/minimum index i such that N - perm[i] exists in the target interval" in O(1) with O(NlogN) or even O(N) precomputation with RMQ. Then, if the answer to any of the queries doesn't belong to the target interval, the interval is winnable (as explained in chemthan's post).

        Unfortunately, as the task is to count the winnable intervals rather than answer to queries, this method is only O(N2), which is enough only for 50% of the points.

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

      How to solve it after this? It seems now it reduces to: count the number of subarrays with exactly 0 or 2 instances of every element.

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

    If my solution is correct, time complexity of my solution is O(R2 * S)

    Problem C

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

      Yeah, that was the intended solution.

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

      So can you explain it?

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится +9 Проголосовать: не нравится

        Sure, let's first think about the game in a different light. Suppose that everything on the grid stays still and the main character can in one second move from (r, c) to (r - 1, c - 1), (r - 1, c) or (r - 1, c + 1). It is easy to see those games are equivalent.

        Let dp[r][c][o] denote the longest valid expression you can acquire if you are currently on position (r, c) on the screen and the difference between the number of open parentheses and closed parentheses in the expression you have acquired thus far equals o. Computing all dp values takes O(R3) time. This solves the part of the problem that deals with the length of the sequence.

        For the reconstruction, we'll keep around a set of dp states that can potentially lead us to the lexicographically smallest solution. At the beginning, that set contains only Mirko's initial position. We will now make transitions from those states (similar to transitions in dp) that lead to longest solutions and traverse only the empty cells of the grid (this is a standard bfs). Once we have exhausted the empty cells, we have obtained the set of cells that contain the next parenthesis in our sequence. At this point we will disregard all cells that have ')' written on them in case there exists a single cell with '(' written on it. Repeating this process yields the lexicographically smallest sequence in O(R2).

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
          Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

          Since there is no test case with expression longer than 50, separate reconstruction part is actually not needed. We can define dp value as pair of (longest valid expression, lexicographic price of expression) and then just maximize this pair using dp.

          If for some state longest valid expression is k then lexicographic price is k-bit number created from this expression with ( being 1 and ) being 0 — this k-bit number is solution itself.

          EDIT: Actually I modified this approach a bit and it works for all possible cases i.e. with expressions up to 100, just replace k-bit number with solution string, add custom operator< and then just print that string at the end.

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

            What makes you think there is no test case with expression longer than 50?

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

              Well, I meant in this specific contest there was not :). Of course there could be a test case with expression longer than 50.

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

                You made me a bit paranoid for a second because I generated the test data :)

                Now I see that we uploaded the wrong .zip archive at hsin.hr/coci which contains the test data for our local version of the contest (honi). That version of the task had looser constraints and the solution you described was supposed to get accepted.

                The correct archive should be up tomorrow.

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

                  As noted in the edit of my comment above, this approach is working for all possible test cases if the lexicographic price part is replaced by plain string, bitset could be used as well. Thus special reconstruction phase could be avoidable after all. Waiting for additional test cases.

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

Wasn't C was harder than other C's in COCI?

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

D is pretty easy right? Unless I missed something that made it hard...

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

Do you know when can i see the results?

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

What is the optimal solution in problem B?

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

    Precalculate prefix sums for each letter. When answering queries, check if count of each letter in same on intervals.

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

What is the solution for C? I wrote a solution that works in O(3^R), but it is obviously too slow.

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

Will they open the analysis mode?

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

Turn on analysis mode please.