This page is still under construction.

Parts of this page are still being built. What you see may change.

Painting Squares

Time limit4sMemory limit1024 MB

Summary
Paint squares black or white and choose the smallest k so that the color pattern in any window of length k, together with whether it runs off the row, always identifies the window's start.
Level

Hard8 of 10

Topics
String, Combinatorics, Greedy, Implementation
Solved
No attempts yet

Problem

Mike is playing a game with Peter. There are nn squares drawn on the ground in a single row, numbered 00 to n−1n-1 from left to right. At the start of the game, Peter is allowed to paint each of these squares either black or white. He will then give Mike a single positive integer kk (1≤k≤n1 \leq k \leq n).

This game lasts a total of qq rounds. In each round, Mike will randomly pick a square xx (0≤x<n0 \leq x \lt n), and tell Peter the colours of the squares from positions xx to x+k−1x+k-1 inclusive. If any of these positions are out of range, Mike will inform Peter accordingly as well. Peter will then need to correctly deduce xx based purely on this information alone.

Peter wishes to impress Mike, and thus wants to pick a value of kk that is as low as possible. Help Peter devise a strategy to win this game with the minimum possible value of kk.

Constraints

  • 1≤r≤101 \leq r \leq 10
  • 2≤n,q≤10002 \leq n, q \leq 1000
  • −1≤c[i]≤1-1 \leq c[i] \leq 1 (0≤i<k0 \leq i \lt k)

Examples1

  1. Example 1

    Input
    2 2
    
    Expected output
    1