← 返回 databricks 的题目列表Generalized Tic-Tac-Toe
类型:online_judge
Design a generalized Tic-Tac-Toe game.
Given a board of size N x M and a winning length K, two players take turns placing marks. A player wins when they own at least K consecutive marks in any of these directions:
horizontal
vertical
main diagonal
anti-diagonal
Implement move(row, col, player):
Reject an out-of-bounds move or a move to an occupied cell.
Otherwise place the mark and return whether that player wins after this move.
Determine the winner immediately after each move. Discuss time and space complexity when K is near a board dimension or when the board is very large.
Example: for N = 3, M = 3, K = 3, after (0,0,1), (0,1,2), (1,1,1), (0,2,2), (2,2,1), player 1 wins on the main diagonal.
Example
Input
3 3 3
5
0 0 1
0 1 2
1 1 1
0 2 2
2 2 1
Output
false
false
false
false
true