QOJ.ac

QOJ

时间限制: 3 s 内存限制: 2048 MB 总分: 100

#4234. 井字棋计数

统计

井字棋(Tic Tac Toe)是一个简单的儿童游戏。它在一个 $3 \times 3$ 的网格上进行。第一位玩家在 9 个格子中的任意一个放置一个 'X'。下一位玩家在剩余的 8 个格子中的任意一个放置一个 'O'。玩家轮流在空位上放置 'X' 和 'O',直到某位玩家在行、列或对角线上连成三个相同的符号,或者网格被填满。如果任一玩家在三行、三列或两条对角线中的任意一条上连成三个符号,该玩家获胜,游戏结束。

Fred 和 Sam 正在玩井字棋。在游戏进行到一半时,Fred 感到好奇:“从当前局面开始,后续有多少种游戏过程最终以 X 获胜?又有多少种以 O 获胜?”如果两个游戏过程的落子顺序不同,即使在任何时刻网格看起来相同,它们也被视为不同的游戏过程。

给定一系列网格,首先确定它们是否可以在井字棋游戏中达到;如果可以,计算从该状态开始,后续有多少种游戏过程最终以 X 获胜,以及多少种以 O 获胜。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^5$),表示测试用例网格的数量。

接下来的 $t$ 行,每行包含一个长度为 9 的字符串 $s$ ($|s| = 9$),仅由字符 '.'、'X' 和 'O' 组成。这些是测试用例网格。前三个字符代表第一行,中间三个代表第二行,最后三个代表第三行,其中 '.' 代表空位。例如,字符串 XX..O.... 代表以下网格:

输出格式

对于每个测试用例,输出两个空格分隔的整数。如果该网格在井字棋游戏中无法达到,输出 -1 -1。如果网格可以达到,输出从该状态开始(包含当前网格状态)最终以 X 获胜的游戏过程数量,以及以 O 获胜的游戏过程数量。

样例

样例输入 1

4
XX..O....
X...OX...
OOOX.X.X.
OOOXXX...

样例输出 1

191 194
232 200
0 1
-1 -1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.