AT_scpc2026_div1_g.오fill
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Cenix wants to fill an N×M grid using the following six types of square tiles. There are plenty of each type of tile, and they can be rotated before placement. When placing tiles, every edge connected to a path must touch an edge connected to a path on a neighboring tile. However, not all paths need to be connected.

While filling the grid, Cenix realized that the task was too easy. Cenix now intends to fill the remaining cells using only tiles that connect one side and tiles that connect three sides.

A grid with some cells already filled with tiles is given as follows.
- The type of tile placed in the i-th row and j-th column of the grid is denoted by Ai,j.
- If no tile is placed in that cell, Ai,j is −1.
- If a tile is placed in that cell, Ai,j is the sum of 1 (if the tile is connected to the top edge), 2 (if connected to the bottom edge), 4 (if connected to the left edge), and 8 (if connected to the right edge).
Find the number of ways to fill the remaining cells using only these two types of tiles.
Cenix 想要用以下六种类型的方形单元格瓷砖铺满一个 N×M 的网格。每种瓷砖均有无限供应,且可在放置前任意旋转。放置瓷砖时,每条与路径相连的边必须与相邻瓷砖上一条同样与路径相连的边相接。但并非所有路径都必须相互连通。

在铺填过程中,Cenix 发现该任务过于简单。因此,Cenix 决定:仅使用仅连接一侧的瓷砖和连接三侧的瓷砖来填充剩余的空单元格。

给定一个部分已铺填瓷砖的网格,具体如下:
- 网格中第 i 行、第 j 列单元格所放置的瓷砖类型记为 Ai,j。
- 若该单元格尚未放置瓷砖,则 Ai,j=−1;
- 若该单元格已放置瓷砖,则 Ai,j 定义为如下各项之和:若瓷砖与上边相连则加 1,与下边相连则加 2,与左边相连则加 4,与右边相连则加 8。
求仅用上述两种瓷砖(即仅连接一侧与连接三侧的瓷砖)填满所有剩余空单元格的方案总数。
输入格式
The input is given from Standard Input in the following format:
N M
A1,1 A1,2 … A1,M
A2,1 A2,2 … A2,M
⋮
AN,1 AN,2 … AN,M
输入从标准输入中按以下格式给出:
N M
A1,1 A1,2 … A1,M
A2,1 A2,2 … A2,M
⋮
AN,1 AN,2 … AN,M
输出格式
Output the number of ways to fill the grid, modulo 998244353.
输出填充网格的方案数,对 998244353 取模。
输入输出样例
输入#1
3 3 10 -1 6 -1 -1 -1 9 -1 -1
输出#1
2
输入#2
1 3 -1 -1 -1
输出#2
0
输入#3
5 5 -1 -1 0 0 0 -1 -1 0 0 0 0 0 -1 0 -1 0 0 3 0 3 0 0 -1 0 -1
输出#3
2
说明/提示
表示言語
/ /
Sample 1 Explanation:

Constraints
- 1≤N,M≤500000
- 1≤NM≤500000
- −1≤Ai,j≤15
- All input values are integers.
表示语言
/ /
样例 1 解释:

约束条件
- 1≤N,M≤500000
- 1≤NM≤500000
- −1≤Ai,j≤15
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?