← 返回 amazon 的题目列表Multi-Player N-by-N Tic-Tac-Toe
类型:online_judge
Implement an N x N Tic-Tac-Toe game for K players. Players take turns and each player has its own character.
play(player, row, col) -> Status: place a mark. Return INVALID for a wrong turn, invalid coordinate, occupied cell, or finished game. Return WIN:<player> when that player fills an entire row, column, main diagonal, or anti-diagonal; return TIE when the board is full without a winner; otherwise return IN_PROGRESS.
getStatus() -> Status
Follow-up: how can space be reduced when winning means filling a whole row, column, or either full diagonal?
CLI input is JSON: {"n":3,"players":["X","O"],"moves":[["X",0,0],...]}. Print statuses after each move.
Constraints: 1 <= N <= 10^5; do not allocate an O(N^2) board.
Example
Input
{"n":3,"players":["X","O"],"moves":[["X",0,0],["O",0,1],["X",1,1],["O",0,2],["X",2,2]]}
Output
["IN_PROGRESS","IN_PROGRESS","IN_PROGRESS","IN_PROGRESS","WIN:X"]