Let us discuss div2+div1 today's Opencup problems here

# | User | Rating |
---|---|---|

1 | tourist | 3509 |

2 | OO0OOO00O0OOO0O0…O | 3327 |

3 | Um_nik | 3297 |

4 | Syloviaely | 3274 |

5 | LHiC | 3216 |

6 | Petr | 3161 |

7 | Benq | 3130 |

8 | ko_osaga | 3124 |

9 | Swistakk | 3089 |

10 | dotorya | 3060 |

# | User | Contrib. |
---|---|---|

1 | Radewoosh | 185 |

2 | rng_58 | 161 |

3 | tourist | 158 |

4 | Petr | 152 |

5 | Swistakk | 150 |

5 | Vovuh | 150 |

7 | csacademy | 147 |

8 | Errichto | 145 |

8 | Um_nik | 145 |

8 | PikMike | 145 |

Let us discuss div2+div1 today's Opencup problems here

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/19/2018 11:03:43 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|

How to solve div2 D Nice set of Points?

There was similar problem on Yandex finals 2011 (link). Solution on Russian is explained here.

How to solve B and J?

B — Let's say that 2 points are connected if they can be paired. it's possible to pair 2*N points iff each component of such graph has even size (I don't know proof). To make number of edges linear connect each point only with 2 closest points in each direction (not 1 point because this point can be deleted). Now we need to check if sizes of all components are even if we delete a vertex. This can found with similar approach to finding articulation vertices.

Code

The proof is obvious if you know Tutte theorem. Let's assume the graph is connected and |

V| is even. If we delete vertexv, there will be at most 2 connected components(one will contain vertices on the same vertical asv, other will contain vertices on the same horizontal). Therefore, if we deletekvertices, there will be at mostk+ 1 connected components. If for some subset of sizekafter deleting it there will bek+ 1 odd components, then which is odd. Contradiction.sorry, this not, the sol to the problem J

J — I have some shitty dp, but some team solved it very fast so I believe that there exists neater solution.

A simpler approach:

DP[position in array][mask of used positions in permutation][remainder]; code.Nice! On the other hand my solution is polynomial :)

Can you please explain the idea behind it?

Let's process positions one by one. We'll keep track of current position, mask of entries in the final permutations which we already picked and remainder of current distance. The trick is — in case you know that mask, you can calculate how many times you'll pass through the next segment

(and therefore how much does it add to the total length of the route)— for each two adjacent positions in your route you can check the mask and see if they are on the same side of the segment or not.Can you please explain your parameters?

Can you please explain your sol?

And G?

My code. It generates correct board for every prime k with size

k^{2}×k^{2}andk^{3}zeros.How to solve H?

The solution is based on Sprague–Grundy theory. Let's solve the problem where we have only one bean:

We are going to calculate the grundy function for each

i. According to the theory:G_{i}=mex(G_{i - Ci},G_{i - Ci + 1}, ...,G_{i - 1}), wheremexis the minimum non-negative integer, that doesn't appear in the set (e.x.mex(0, 1, 4) = 2 ).To find it on

O(logn) I used a segment-tree, where I kept for each number in range [0, 10^{5}] it's last appearance inG. Having this information, we run a simple recursion to find the minimum number, which last time appeared earlier, thani-C_{i}. It is ourG_{i}, now we update the tree.After calculating

G, let's calculate the answer. According to the theory,G_{game}is the xor-sum of allG_{i}, such thatA_{i}is odd. The answer is "Second" ifG_{game}is equal to zero, otherwise "First".code

How to solve E and F?

E

You need 3 facts (I'll list them without proof). First, our trajectory has period

g=gcd(h,w). Second, if the trajectory period hasuup moves (alonghside) andrright moves, thengcd(u,h) =gcd(r,w) = 1. Third, any trajectory satisfying these constraints is good, so the answer is , wheregcd(u,h) =gcd(g-u,w) = 1.F

Note that every empty cell that's neither start nor finish has exactly one vertical and one horizontal connection. This means that for every line (row or column) we can go from one side and greedily pair empty cells with connections (this implies the number of empty cells is even). This works for all lines that contain no end points and gives a hint where finish can be located: if there's 0 lines with odd number of empty cells, it is in the same line as start, if there are 2 — start must lie in one of them and finish in the other, and if it's more than 2 — the answer is NO. We have

O(N) candidates for finish, we just check all of them and construct the path inO(N^{2}) for each. I heard this solution can even be improved toO(N^{2}) if we build DSU over the paths once for every line where we check the finish position.Are Opencup problems open to the public?