Official
A - 縞模様の布 / Striped Cloth Editorial by admin
swe-2-highThe square at position \(i\) (0-indexed) belongs to stripe number \(\lfloor i / K \rfloor\), obtained by integer division. Since stripes alternate red, blue, red, … starting from stripe \(0\), the square is red when this quotient is even and blue when it is odd. For each \(i\), the program appends R if (i / k) % 2 == 0 and B otherwise. Even when the final stripe is shorter than \(K\) squares, the same formula still yields the correct color, so nothing special is needed. Processing each of the \(N\) squares once gives \(O(N)\) time, and holding the output string uses \(O(N)\) space.