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

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

Feel free to discuss the problems here :)

And here's my new rating:

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

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

Congratulations on an unprecedented achievement!

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

And here is the reason if anyone is wondering:

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

I must present you initial version of Easy. You are given W and H. What is the minimum N for which you can fill grid with squares 1, 2, ..., 2N - 1? Who will be the first to find the intended (very short) solution?

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

What did you expect? You weren't even able to overperform anybody in the contest you've participated :)

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

How to solve 800?

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

    Let's draw a directed graph with n vertices and n edges: from x to f(x). Let's look at the required function g(x) as a mapping on this graph: we map each vertex to some other vertex. The condition f(g(x))=g(f(x)) means that mapping should be such that whenever there's an edge from a to b, there should be an edge from g(a) to g(b), so we're kind of embedding the graph onto itself.

    The graph has exactly one outgoing edge for each vertex, so its structure is some cycles with some directed trees growing into the cycles. Consider a vertex X on the cycle of length A. Where can it be mapped? Because of the "edges are mapped to edges" condition, it must be mapped to another vertex on a cycle, and the length of that cycle should divide A. Let's just iterate over all vertices Y that X can be mapped to.

    For each particular Y, the mapping of all vertices on X's cycle is uniquely determined. As for the trees growing into this cycle, we can compute the number of ways to embed them using the following dynamic programming: we just count the number of ways to embed a subtree going to each vertex P in such a way that P is mapped to Q for each vertex Q. When we want to embed a subtree in such a way that P maps to Q, that means that all predecessors of P must be mapped to predecessors of Q, so we can use our dynamic programming results to compute the number of ways to map each branch of the tree, and multiply them.

    The working time of the solution is O(N^2).

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