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

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

Hello! I'm happy to announce XXI Open Cup: Grand Prix of Weihai, which will be held today.

Authors of this contest come from Nanjing University, including gisp_zjz, zyb, sy_chen, Roundgod, calabash_boy, uuzlovetree,love.zy. This contest was originally used as China Collegiate Programming Contest(CCPC), Weihai Site. Enjoy!

Testers: -skyline-, chenjb, Subconscious, oipotato, 374272,VincentLx, Shedneryan, Icdereap. Thank you!

Contest link: http://official.contest.yandex.ru/opencupXXI/contest/21761/enter (Only visible for users with OpenCup login)

I will post the editorial after the contest. We are looking forward to your participation!

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

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

How to solve A?

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

    Find vertex with the lowest degree $$$v$$$. It should be in the first frame. Choose its neighbour $$$u$$$ and try to check wether there is a solution where $$$u$$$ is a copy of $$$v$$$ in the second frame. Degree of $$$v$$$ is $$$O(\sqrt{m})$$$, so it works fast.

    Now if we know that $$$v$$$ and $$$u$$$ are the same vertex in the first and second frames, we know that all other neighbours of $$$v$$$ are in the first frame. For each such neighbour $$$w$$$ we know that $$$w$$$ and $$$u$$$ should have exactly 2 common neighbours: $$$v$$$ and copy of $$$w$$$ in the second frame. So we can find all copies of neighbours of $$$v$$$ in the second frame. Using the same ideas and bfs we can find all the vertices in all the frames.

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

please, explain E

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

Great contest!

Can J be solved in other way than sqrt + segment tree + hashes? It took me 350 lines to code it x.x

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

    Segment tree + hashes was enough, I needed no sqrt.

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

    We did segment tree + hashes: to check that two substrings are equal you need to check that:

    • Their first character is the same.
    • The sequence of value differences between adjacent characters starting from the second one is the same.

    First part can be maintained in a segment tree by doing segment updates & point queries. Second part is doable by segment tree over the array of differences: since each update changes differences for only 2 positions, you can do point updates & segment queries.

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

    I don't know what your "sqrt" means, but a usual segment tree is enough. Just add 1 on a segment and also track the maximum value with its position. While the maximum value is $$$65\,536$$$, decrease it by $$$65\,536$$$, and repeat. There will be no more than $$$\lceil \frac{q}{65\,536} \rceil \cdot n$$$ such decreases. To compare the substrings, we maintain hashes.

    My code has only 140 lines.

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

    We used just Fenwick tree + hashing for getting range sum and update value of one element (one Fenwick tree for current prefix hashing and one for getting current value of element after increase queries).

    Really nice tasks!

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

    For a large prime $$$p = k \cdot 2^{16} + 1$$$ (or several such primes) we can find $$$\omega$$$ of multiplicative order $$$2^{16}$$$, and $$$x$$$ of any large order. Substring hashes $$$h(s_0 \ldots s_{n - 1}) = \sum_{i = 0}^{n - 1} x^i \omega^{s_i}$$$ can be maintained with an RSQ structure with range multiplication updates (add $$$1$$$ to $$$a_i$$$ = multiply hashes by $$$\omega$$$).

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

How to solve G?

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

    Let's assume that there are $$$n$$$ black piles, no white piles, the size of the smallest black pile is $$$x$$$ and there are $$$k$$$ black piles with size $$$x$$$. Then if $$$k = n$$$, the Sprague-Grundy function of this game is $$$x$$$ if $$$k$$$ is odd and $$$x - 1$$$ otherwise. If $$$k \lt n$$$, it's the other way around: $$$x - 1$$$ if $$$k$$$ is odd and $$$x$$$ if $$$k$$$ is even. You can easily prove this by induction. Now the white piles are just usual nim, so you should xor their sizes with Sprague-Grundy function for black piles and check if it's zero.

    Let's fix the smallest black pile $$$x$$$. Also fix the parity of black piles with size $$$x$$$. Now there are 2 cases: if we don't take black piles with size greater than $$$x$$$, then the value of the game is already fixed, and we just need to check wether it's zero. Otherwise, we need to choose among piles with size greater than $$$x$$$ a subset with a fixed xor so that the total xor is zero. So we reduced our problem to a standard one: maintain a set of binary vectors with 2 queries: add a new vector to the set and count number of subsets with fixed xor. This is solved with Gauss. We maintain the basis of vectors in the set and when we need to count number of subsets with xor $$$x$$$, if $$$x$$$ is in subspace generated by our set, the answer is $$$2^{size \, of \, set - size \, of \, basis}$$$, otherwise it's zero. Also don't forget to check the case when all piles are white.

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

Contest finished! Final scoreboard: link

This problem set was originally prepared for an onsite contest(actually online, but made to work as onsite under many regulations), China Collegiate Programming Contest(CCPC), Weihai Site. When used in Open Cup, snarks permuted the problems and changed the problems' names to prevent some possible unfairness that would occur.

Here we present the original problem statement and the tutorial. You can easily find the correspondence between the problems in both files.

Problem Statement: link

Tutorial: link

Scoreboard for the onsite contest(Chinese): link

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

We prepared this contest mainly to fit the requirements for our onsite contestants. We cut some hard problems and modified some constraints to meet that requirement, thus the contest is not very hard. Hope you still enjoyed it. Anyway, thanks for the participation!

The contest is already uploaded to Codeforces Gym. Enjoy!

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

It looks like Memory usage counting for Java on Yandex Contest is completely broken. We got Memory Limit Exceeded for problem I (see submission 1 and even more optimized submission), but the same codes passes in Gym: 97933469 and 97933601 (with 64M or even 8M memory usage).

Could somebody please take a look?

snarknews

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

    Not saying it's not broken on YandexContest but 8MiB doesn't sound right. You have 3 int arrays of length of a 1000000, it is 12Mb already

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

      Yeah, agree that Codeforces doesn't do a perfect job in memory counting also, but at least result is much closer to what I'd expect.

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

        Just as a wild guess after looking at the submission code and nothing else, I think the issue might be in the reading of input. We need to read 1 million lines with 3 integers each. You are creating 5 objects per line (the line itself, tokenizer, 3 strings for each integer).

        Random searching shows that a string with length 8 consumes 60 bytes of memory, not sure how accurate it is, but probably in the right ballpark, so you're allocating on the order of 300M with your 5M objects, and the ML is 256M.

        You're not allocating them all at once, but here I think the real issue of Yandex.Contest manifests: they probably don't pass the correct value for -Xmx (unlike Codeforces), so the garbage collector doesn't see a need to free the objects you're no longer using, because it thinks there's still a lot of memory available.

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

          Good guess! I replaced Scanner with static char buffer and manual integer parsing and got AC with 40M memory usage (interesting, does InputStream.read allocate?).

          Still wondering about differences in Codeforces and Yandex Contest Java configurations. If the only difference is in -Xmx, then for submission 97933601 I'd expect Codeforces to show memory usage, which is bigger than 8M (at least by size of young generation heap).

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

          Don't you think that escape analysis should help in this case?

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

            Good point! I'm way too unfamiliar with the internals of Java to answer :)

            I guess from what we're seeing we can hypothesize that it helps on Codeforces but not on Yandex.

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

I didn't make it to the contest(: