Stripes
Time limit3sMemory limit512 MB
Given stripe lengths c, z, n, decide for each board length p whether the first player wins the impartial placement game.
- Level
Medium7 of 10
- Topics
- Game theory, Dynamic programming
- Solved
- No attempts yet
Problem
Stripes is a game for two players. To play it you need one board and rectangular stripes in three colors: red, green, and blue. Every red stripe has size , every green stripe , and every blue stripe , where , , and are positive integers. Each player has an unlimited supply of stripes of every color.
The board is a rectangle made up of cells of size .
The players move alternately. A single move consists of placing one stripe of any color on the board, subject to the following rules:
- a stripe may not stick out of the board,
- a stripe may not cover, even partially, any stripe that was placed earlier,
- the two ends of a stripe must line up exactly with the cell boundaries of the board.
The player who cannot make a legal move loses. The player who moves first is called the first player. We say the first player has a winning strategy if he can always win, no matter how the second player plays.
Write a program that reads the stripe sizes and the length of one or more boards, and for each board decides whether the first player has a winning strategy.
Input
The first line contains three integers , , and (), separated by single spaces: the lengths of the red, green, and blue stripes respectively.
The second line contains one integer (): the number of boards to consider.
Each of the next lines contains one integer (): the length of the corresponding board.
Output
Print lines. In the -th line print a single integer:
- if the first player has a winning strategy on the -th board,
- otherwise.