Matrix Game
InterviewTime limit0.5sMemory limit512 MB
Given an N by M matrix, it asks who wins a take-away game where a move subtracts 1 to K from the leftmost nonzero entry of some row.
- Level
Medium7 of 10
- Topics
- Game theory, Greedy, Hash map, Matrix
- Solved
- No attempts yet
Problem
Koosaga and Cubelover are about to play a matrix game. The matrix game is played on an N×M matrix, with the two players taking turns, according to the following rules.
- Choose a row that contains at least one nonzero number. In that row, choose the leftmost nonzero number. Let the chosen number be K, and decrease it. The number must be decreased by at least 1 and at most K.
The game ends when every number in the matrix becomes 0. The player who decreases a number last wins the game.
Write a program that determines who wins when both players play optimally. Koosaga moves first.
Input
The first line gives N and M. The following N lines give the integers in the matrix. Every number in the input is a natural number less than or equal to 1,000.
Output
If Koosaga wins the game, print "koosaga"; if Cubelover wins, print "cubelover".