CF1197F.Coloring Game

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob want to play a game. They have nn colored paper strips; the ii-th strip is divided into aia_i cells numbered from 11 to aia_i. Each cell can have one of 33 colors.

In the beginning of the game, Alice and Bob put nn chips, the ii-th chip is put in the aia_i-th cell of the ii-th strip. Then they take turns, Alice is first. Each player during their turn has to choose one chip and move it 11, 22 or 33 cells backwards (i. e. if the current cell is xx, then the chip can be moved to the cell x−1x - 1, x−2x - 2 or x−3x - 3). There are two restrictions: the chip cannot leave the borders of the strip (for example, if the current cell is 33, then you can't move the chip 33 cells backwards); and some moves may be prohibited because of color of the current cell (a matrix ff with size 3×33 \times 3 is given, where fi,j=1f_{i, j} = 1 if it is possible to move the chip jj cells backwards from the cell which has color ii, or fi,j=0f_{i, j} = 0 if such move is prohibited). The player who cannot make a move loses the game.

Initially some cells may be uncolored. Bob can color all uncolored cells as he wants (but he cannot leave any cell uncolored). Let's call a coloring good if Bob can win the game no matter how Alice acts, if the cells are colored according to this coloring. Two colorings are different if at least one cell is colored in different colors in these two colorings.

Bob wants you to calculate the number of good colorings. Can you do it for him?

Since the answer can be really large, you have to print it modulo 998244353998244353.

Alice 和 Bob 想玩一个游戏。他们有 nn 条彩色纸带;第 ii 条纸带被划分为 aia_i 个格子,编号从 11 到 aia_i。每个格子可以是 33 种颜色之一。

游戏开始时,Alice 和 Bob 将 nn 枚棋子放置在纸带上:第 ii 枚棋子被放在第 ii 条纸带的第 aia_i 个格子中。然后两人轮流行动,Alice 先手。每位玩家在自己的回合中必须选择一枚棋子,并将其向后移动 11、22 或 33 个格子(即:若当前格子编号为 xx,则可将棋子移至编号为 x−1x - 1、x−2x - 2 或 x−3x - 3 的格子)。移动需满足两个限制条件:

  • 棋子不能移出纸带边界(例如,若当前格子编号为 33,则不允许向后移动 33 格);
  • 某些移动可能因当前格子的颜色而被禁止(给定一个大小为 3×33 \times 3 的矩阵 ff,其中 fi,j=1f_{i, j} = 1 表示当格子颜色为 ii 时,允许向后移动 jj 格;fi,j=0f_{i, j} = 0 表示该移动被禁止)。

无法进行任何合法移动的玩家输掉游戏。

初始时,部分格子可能未着色。Bob 可以任意为所有未着色的格子染色(但不能留下任何格子未着色)。我们称一种染色方案为好染色,当且仅当:若按该方案对所有格子染色,则无论 Alice 如何行动,Bob 均能获胜。若两种染色方案中至少有一个格子的颜色不同,则认为它们是不同的染色方案。

Bob 希望你计算好染色方案的总数。你能帮他完成吗?

由于答案可能非常大,请对 998244353998244353 取模后输出。

输入格式

The first line contains one integer nn — the number of paper strips (1≤n≤10001 \le n \le 1000).

The second line contains nn integers a1a_1, a2a_2, ..., ana_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i is the number of cells in the ii-th strip.

The third line contains one integer mm (1≤m≤10001 \le m \le 1000) — the number of cells that are already colored.

Then mm lines follow, each describing an already colored cell. The ii-th of these lines contains three integers xix_i, yiy_i and cic_i (1≤xi≤n1 \le x_i \le n, 1≤yi≤axi1 \le y_i \le a_{x_i}, 1≤ci≤31 \le c_i \le 3) denoting that the cell yiy_i in the strip xix_i has color cic_i. It is guaranteed that if i≠ji \ne j, then either xi≠xjx_i \ne x_j or yi≠yjy_i \ne y_j (or both).

Then 33 lines follow, ii-th line containing 33 numbers fi,1f_{i, 1}, fi,2f_{i, 2}, fi,3f_{i, 3} (0≤fi,j≤10 \le f_{i, j} \le 1). If fi,j=1f_{i, j} = 1, then it is possible to move the chip jj cells backwards from the cell having color ii; if fi,j=0f_{i, j} = 0, then such move is impossible.

第一行包含一个整数 nn —— 纸条的数量(1≤n≤10001 \le n \le 1000)。

第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 表示第 ii 条纸条的格子数。

第三行包含一个整数 mm(1≤m≤10001 \le m \le 1000)—— 已着色格子的数量。

接下来 mm 行,每行描述一个已着色的格子。其中第 ii 行包含三个整数 xix_i, yiy_i 和 cic_i(1≤xi≤n1 \le x_i \le n, 1≤yi≤axi1 \le y_i \le a_{x_i}, 1≤ci≤31 \le c_i \le 3),表示第 xix_i 条纸条上的第 yiy_i 个格子颜色为 cic_i。保证当 i≠ji \ne j 时,要么 xi≠xjx_i \ne x_j,要么 yi≠yjy_i \ne y_j(或两者皆成立)。

随后是 33 行,其中第 ii 行包含 33 个数字 fi,1f_{i, 1}, fi,2f_{i, 2}, fi,3f_{i, 3}(0≤fi,j≤10 \le f_{i, j} \le 1)。若 fi,j=1f_{i, j} = 1,则允许从颜色为 ii 的格子向后(即朝纸条起始方向)移动 jj 个格子;若 fi,j=0f_{i, j} = 0,则不允许进行该移动。

输出格式

Print one integer: the number of good colorings, taken modulo 998244353998244353.

输出一个整数:良好染色方案的数量,对 998244353998244353 取模。

输入输出样例

  • 输入#1

    3
    3 4 5
    2
    1 1 1
    2 2 2
    1 1 1
    1 0 0
    0 1 1

    输出#1

    14346
  • 输入#2

    1
    1
    1
    1 1 1
    1 1 1
    1 1 1
    1 1 1

    输出#2

    1
  • 输入#3

    3
    1 1 1
    1
    1 1 1
    1 1 1
    1 1 1
    1 1 1

    输出#3

    9

输入解题思路,AI测评打分。不知道怎么写?

首页