{"problem":{"name":"B. Ilya and tic-tac-toe game","description":{"content":"Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish t","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF754B"},"statements":[{"statement_type":"Markdown","content":"Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.\n\nThe rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets **three of his signs in a row next to each other** (horizontal, vertical or diagonal).\n\n## Input\n\nThe tic-tac-toe position is given in four lines.\n\nEach of these lines contains four characters. Each character is '_._' (empty cell), '_x_' (lowercase English letter _x_), or '_o_' (lowercase English letter _o_). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.\n\n## Output\n\nPrint single line: \"_YES_\" in case Ilya could have won by making single turn, and \"_NO_\" otherwise.\n\n[samples]\n\n## Note\n\nIn the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.\n\nIn the second example it wasn't possible to win by making single turn.\n\nIn the third example Ilya could have won by placing X in the last row between two existing Xs.\n\nIn the fourth example it wasn't possible to win by making single turn.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Ilya 是一名在 #cf_span[4 × 4] 棋盘上玩井字棋的资深玩家。他总是先手并使用 X。今天他与朋友 Arseny 玩了很多局游戏。两人感到疲倦，没有完成最后一局。当他们离开时，轮到 Ilya 下棋。请判断 Ilya 是否可以通过一步棋获胜。\n\n在 #cf_span[4 × 4] 棋盘上玩井字棋的规则如下：在第一手之前，所有格子都是空的。两名玩家轮流在空格中放置自己的符号（先手放置 X，后手放置 O）。先放置 X 的玩家先手，另一名玩家后手。获胜者是第一个在一行（水平、垂直或对角线）上连续获得 *三个自己的符号* 的玩家。\n\n井字棋的局面由四行给出。\n\n每行包含四个字符。每个字符是 '_._'（空格）、'_x_'（小写英文字母 _x_）或 '_o_'（小写英文字母 _o_）。保证该局面是可以通过合法井字棋对局达到的，且当前轮到 Ilya 下棋（这意味着游戏尚未结束）。所有格子都可能是空的，这意味着朋友们甚至没有下过任何一手。\n\n请输出一行：如果 Ilya 可以通过一步棋获胜，则输出 \"_YES_\"；否则输出 \"_NO_\"。\n\n在第一个例子中，Ilya 有两个获胜走法：左列的空格和第一行最左边的空格。\n\n在第二个例子中，无法通过一步棋获胜。\n\n在第三个例子中，Ilya 可以通过在最后一行两个已有的 X 之间放置 X 获胜。\n\n在第四个例子中，无法通过一步棋获胜。\n\n## Input\n\n井字棋的局面由四行给出。每行包含四个字符。每个字符是 '_._'（空格）、'_x_'（小写英文字母 _x_）或 '_o_'（小写英文字母 _o_）。保证该局面是可以通过合法井字棋对局达到的，且当前轮到 Ilya 下棋（这意味着游戏尚未结束）。所有格子都可能是空的，这意味着朋友们甚至没有下过任何一手。\n\n## Output\n\n请输出一行：如果 Ilya 可以通过一步棋获胜，则输出 \"_YES_\"；否则输出 \"_NO_\"。\n\n[samples]\n\n## Note\n\n在第一个例子中，Ilya 有两个获胜走法：左列的空格和第一行最左边的空格。在第二个例子中，无法通过一步棋获胜。在第三个例子中，Ilya 可以通过在最后一行两个已有的 X 之间放置 X 获胜。在第四个例子中，无法通过一步棋获胜。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**\n\nLet $S = \\{\\text{'x'}, \\text{'o'}, \\text{'.'}\\}$.\nLet $G$ be a $4 \\times 4$ matrix where $G_{i,j} \\in S$ for $1 \\le i, j \\le 4$.\n\nLet $L$ be the set of all sets of coordinates representing 3 consecutive cells in horizontal, vertical, or diagonal directions within the grid bounds. Formally:\n$$\n\\begin{aligned}\nL = \\quad &\\{ \\{(i, j), (i, j+1), (i, j+2)\\} \\mid 1 \\le i \\le 4, 1 \\le j \\le 2 \\} \\\\\n\\cup \\quad &\\{ \\{(i, j), (i+1, j), (i+2, j)\\} \\mid 1 \\le i \\le 2, 1 \\le j \\le 4 \\} \\\\\n\\cup \\quad &\\{ \\{(i, j), (i+1, j+1), (i+2, j+2)\\} \\mid 1 \\le i \\le 2, 1 \\le j \\le 2 \\} \\\\\n\\cup \\quad &\\{ \\{(i, j), (i+1, j-1), (i+2, j-2)\\} \\mid 1 \\le i \\le 2, 3 \\le j \\le 4 \\}\n\\end{aligned}\n$$\n\nLet $CheckWin(M)$ be a predicate defined for a matrix $M \\in S^{4 \\times 4}$ as:\n$$ CheckWin(M) \\iff \\exists \\mathcal{l} \\in L \\text{ such that } \\forall (r, c) \\in \\mathcal{l}, M_{r,c} = \\text{'x'} $$\n\n**Input**\n\nA matrix $G \\in S^{4 \\times 4}$ representing the current game state, where it is player 'x's turn.\n\n**Objective**\n\nDetermine if there exists a move $(r, c)$ such that:\n1.  $G_{r,c} = \\text{'.'}$\n2.  $CheckWin(G')$ is true, where $G'$ is defined as:\n    $$\n    G'_{i,j} = \\begin{cases} \n    \\text{'x'} & \\text{if } (i,j) = (r,c) \\\\\n    G_{i,j} & \\text{otherwise}\n    \\end{cases}\n    $$\n\n**Output**\n\n*   \"YES\" if such a move $(r, c)$ exists.\n*   \"NO\" otherwise.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF754B","tags":["brute force","implementation"],"sample_group":[["xx..\n.oo.\nx...\noox.","YES"],["x.ox\nox..\nx.o.\noo.x","NO"],["x..x\n..oo\no...\nx.xo","YES"],["o.x.\no...\n.x..\nooxx","NO"]],"created_at":"2026-03-03 11:00:39"}}