How to solve BCF (preferably in a proved way)?

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

1 | tourist | 3843 |

2 | jiangly | 3705 |

3 | Benq | 3628 |

4 | orzdevinwang | 3571 |

5 | Geothermal | 3569 |

5 | cnnfls_csy | 3569 |

7 | jqdai0815 | 3530 |

8 | ecnerwala | 3499 |

9 | gyh20 | 3447 |

10 | Rebelz | 3409 |

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

1 | maomao90 | 171 |

2 | adamant | 163 |

2 | awoo | 163 |

4 | TheScrasse | 157 |

5 | nor | 153 |

6 | maroonrk | 152 |

6 | -is-this-fft- | 152 |

8 | Petr | 145 |

9 | orz | 144 |

9 | pajenegod | 144 |

How to solve BCF (preferably in a proved way)?

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/17/2024 19:35:35 (j3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

D: Is segmented ternary search the correct solution? I am getting WA10,so not sure if it's because my code is wrong or the approach is wrong

Yes, it's correct.

C: I permuted over the order of kings going to a new column. Other than that, I just made a valid move (either move current king in the order to a new column or just make other valid moves not clicking king)

We got WA but passed with some additional random strategy. Not sure whether our first solution has some bugs.

abistrigova used backtracking with memoization and restriction on iterations.

In B I bruteforced 3 of the strings which have fewest question marks, then in the last string if we know either first or last symbol, we can find the other one, the same for the second and second to last symbol and so on. It works in $$$2^{26}n$$$, but passes in 1 second.

If we don't know the two ends?

Bruteforce one of them.

Brute force from both borders to middle, with checking s for which all is known works in $$$O(2^{3n/4})$$$, because one ? in first two lines can be found because of modulo 4 equation, and one in last two lines can be found.

In fact, you don't need to find them, this only proves, that for each s, at least 1/4 of branches will be thrown away imidiatly.

The same proved complexity but probably faster in practice (and works in 5 ms): Do a recursive brute in this order: first and last column first, then going inside, and checking that currently everything is ok.

I have solved F with the following solution:

Bruteforce width of the first column(there are only O(1e6) interesting widths). Then, measure the width of the second column with ternary search by the answer.

Not sure, if it is correct or not.

Why 64Mb in F?

At first I've tried to solve B with MITM. But ML 64 MB was fighting against me. In the end I've solved it with local optimization.

What's MITM?

Meet in the middle

How to solve J?

You can find with DP in $$$O(n \cdot 2^n)$$$ that the answer is a linear recurrence of order $$$8$$$. So you can solve it with Berlekamp-Massey.

Let $$$f[S]$$$ be the possibility that you start from $$$0$$$ to state $$$S$$$, where $$$S$$$ is a $$$n$$$-bit integer. The state means you are now at $$$0$$$ and a position $$$k$$$ is visited if and only if $$$S_k=1$$$.

For each state $$$S$$$, find the first and last $$$11$$$, and set all the bits between them to $$$1$$$.

i.e.

0010101011000110000110101 -> 0010101011111111111110101

It is not hard to prove that the number of states is now acceptable.

Solution from my team: run random simulation multiple times, print arithmetic mean of number of moves in all simulations.

Don't you need $$$10^{18}$$$ simulations to get the required precision ($$$10^{-9}$$$)?

No, only about 10^11 simulations are required. So we had like non-polynomial which passed around 30 tests, and the rest 20 tests we passed with such a precalculation. One test proceeds in about 1 minute on my PC.

When we repeat simulations $$$10^{11}$$$ times and take the average, the standard deviation of the result is multiplied by $$$1 / sqrt(10^{11})$$$. So it's very strange that this is accurate enough.

My output for $$$n = 50$$$ is 3.845878128958. What's yours?

3.8458781294876384241

I'm doubtful about the validity of test 8 of problem D. I checked if the given polygon was convex, and it failed. Could anybody responsible for the problem take an inspection?