#P17388. [PacNW 2025] Server Room

    ID: 19806 远端评测题 5000ms 2048MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2025轮廓线 DPICPC状压 DP

[PacNW 2025] Server Room

Problem Description

Audrey is system administrator for miHoYo! It is her job to manage the server room and keep her favorite video game, Honkai: Star Rail, up and running.

Audrey manages a rectangular server room divided into rr rows and cc columns. Some cells contain servers, and some of those servers are already on.

The room has poor ventilation. If two orthogonally adjacent servers are both on, the room overheats and every server shuts down. Audrey cannot turn off a server that is already on.

Find the maximum number of currently off servers Audrey can turn on without causing overheating, and count the number of distinct ways to turn on that many servers.

Input Format

The first line contains two positive integers rr and cc with 1rc4001\le r\cdot c\le400.

Each of the next rr lines contains a string of length cc over 0, 1, and 2. A 0 denotes a cell without a server, a 1 an off server, and a 2 an on server. No two initially on servers are adjacent.

Output Format

Let ss be the maximum number of additional servers that can be turned on, and let ww be the number of ways to turn on exactly ss servers. Output ss and wmod998244353w\bmod998244353.

5 5
11011
11001
00200
10010
10000
6 4