CF1197F.Coloring Game
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob want to play a game. They have n colored paper strips; the i -th strip is divided into ai cells numbered from 1 to ai . Each cell can have one of 3 colors.
In the beginning of the game, Alice and Bob put n chips, the i -th chip is put in the ai -th cell of the i -th strip. Then they take turns, Alice is first. Each player during their turn has to choose one chip and move it 1 , 2 or 3 cells backwards (i. e. if the current cell is x , then the chip can be moved to the cell x−1 , x−2 or x−3 ). There are two restrictions: the chip cannot leave the borders of the strip (for example, if the current cell is 3 , then you can't move the chip 3 cells backwards); and some moves may be prohibited because of color of the current cell (a matrix f with size 3×3 is given, where fi,j=1 if it is possible to move the chip j cells backwards from the cell which has color i , or fi,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 998244353 .
输入格式
The first line contains one integer n — the number of paper strips ( 1≤n≤1000 ).
The second line contains n integers a1 , a2 , ..., an ( 1≤ai≤109 ), where ai is the number of cells in the i -th strip.
The third line contains one integer m ( 1≤m≤1000 ) — the number of cells that are already colored.
Then m lines follow, each describing an already colored cell. The i -th of these lines contains three integers xi , yi and ci ( 1≤xi≤n , 1≤yi≤axi , 1≤ci≤3 ) denoting that the cell yi in the strip xi has color ci . It is guaranteed that if i=j , then either xi=xj or yi=yj (or both).
Then 3 lines follow, i -th line containing 3 numbers fi,1 , fi,2 , fi,3 ( 0≤fi,j≤1 ). If fi,j=1 , then it is possible to move the chip j cells backwards from the cell having color i ; if fi,j=0 , then such move is impossible.
输出格式
Print one integer: the number of good colorings, taken modulo 998244353 .
输入输出样例
输入#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