AT_awtf2026algo_e.Even Rows
入门
通过率:0%
时间限制:5.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a board with N rows and M columns. Let us call the cell at the i-th row from the top and j-th column from the left cell (i,j).
Each cell is empty or has one piece placed on it. The state of the board is given by N length-M strings S1,S2,…,SN: if the j-th character of Si is ., cell (i,j) is empty, and if it is O, cell (i,j) has a piece placed on it.
For integers L and R (1≤L≤R≤N), define f(L,R) as follows.
-
Extract only rows L through R of the board, obtaining a board with R−L+1 rows. Call this new board X.
-
You can repeat the following operation on X zero or more times.
- Choose one piece and move it to any of the cells adjacent to it (up, down, left, or right). Here, the destination cell must not have another piece on it. Also, you cannot perform an operation that would move a piece outside of X.
-
Your goal is to reach a state where, for every row of X, the number of pieces in that row is even. If it is impossible to achieve the goal, let f(L,R)=0. If it is possible, let f(L,R) be the minimum number of operations required to do so.
Find ∑1≤L≤R≤Nf(L,R), modulo 998244353.
Solve T cases for each input.
有一个 N 行 M 列的棋盘。我们将从上往下数第 i 行、从左往右数第 j 列的格子记为 (i,j)。
每个格子要么为空,要么恰好放置一枚棋子。棋盘的状态由 N 个长度为 M 的字符串 S1,S2,…,SN 给出:若 Si 的第 j 个字符为 .,则格子 (i,j) 为空;若为 O,则格子 (i,j) 上有一枚棋子。
对整数 L 和 R(满足 1≤L≤R≤N),定义函数 f(L,R) 如下:
-
仅提取棋盘的第 L 行至第 R 行,得到一个具有 R−L+1 行的新棋盘,记为 X。
-
可以在 X 上执行以下操作零次或多次:
- 任选一枚棋子,并将其移动到与其相邻的任意一个格子(上、下、左、右)。目标格子必须为空;且不允许将棋子移出 X 的边界。
-
目标状态是:X 的每一行中,棋子数量均为偶数。若无法达到该目标,则令 f(L,R)=0;否则,令 f(L,R) 为达成目标所需的最少操作次数。
求 ∑1≤L≤R≤Nf(L,R) 对 998244353 取模的结果。
对每组输入,需解决 T 个测试用例。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N M
S1
S2
⋮
SN
输入从标准输入中给出,格式如下:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
N M
S1
S2
⋮
SN
输出格式
For each test case, output the answer.
对于每个测试用例,输出答案。
输入输出样例
输入#1
7 3 2 O. O. .O 4 3 OOO OOO ... OOO 5 3 OOO OOO ..O OOO ... 7 3 OOO ..O OOO OOO O.. OOO .OO 8 3 OO. OOO OOO ..O OOO .O. .OO O.. 4 5 .O..O OOOOO OOOOO .O.O. 10 10 O.O..O..OO ........O. OOO.O.OO.O O..O..OOOO OO..O..... .OOOO..OO. O.......O. OOO.O..... O.O.O....O .....OO.O.
输出#1
3 5 9 7 29 9 44
说明/提示
Sample 1 Explanation:
The values of f(L,R) in the first test case are as follows.
- f(1,1)=0
- f(1,2)=2
- f(1,3)=0
- f(2,2)=0
- f(2,3)=1
- f(3,3)=0
Constraints
- 1≤T≤250000
- 2≤N≤500000
- 2≤M≤10
- Si is a string of length M consisting of
.andO. - The sum of N over the T cases is at most 500000.
样例 1 解释:
第一个测试用例中,f(L,R) 的取值如下:
- f(1,1)=0
- f(1,2)=2
- f(1,3)=0
- f(2,2)=0
- f(2,3)=1
- f(3,3)=0
约束条件
- 1≤T≤250000
- 2≤N≤500000
- 2≤M≤10
- Si 是一个长度为 M 的字符串,仅由字符
.和O组成。 - 所有 T 个测试用例的 N 值之和不超过 500000。
输入解题思路,AI测评打分。不知道怎么写?