아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Bomboni

시간 제한2초메모리 제한1024 MB

요약
장애물이 있는 n x n 격자에서 왼쪽 위에서 오른쪽 아래로 내려가거나 오른쪽으로만 이동할 때, 사탕 수의 곱이 k로 나누어지는 경로의 수를 998244353으로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 정수론, 조합론
정답자
아직 제출이 없습니다

문제

Iva is a big fan of candy! In front of her is an nn times nn field filled with candy and obstacles. Iva is currently in the upper left cell of the field and by moving only down and right she will travel to the lower right cell. The cell Iva is currently in does not contain an obstacle.

In every cell, there is either an obstacle or a piece of candy with a number written on it. Iva will eat all the candy she gets her hands on during her trip (including the candy in the first and last cell) and then multiply all the numbers on them. Iva knows her favourite number is kk and she wants the product of the numbers on the candy she has eaten to be divisible by kk. She wants to know how many such paths there are. Because that number can be huge, she is interested in it modulo 998,244,353998\\,244\\,353.

입력

The first line contains two integers nn and kk (1≤n≤5001 ≤ n ≤ 500, 1≤k≤1061 ≤ k ≤ 10^6), which denote the size of the field and Iva’s favourite number.

In each of the next nn lines, there are nn numbers describing the ii-th row of the field (−1≤a_i,j≤106-1 ≤ a\_{i,j} ≤ 10^6). If a_i,j=−1a\_{i,j} = -1, then that cell contains an obstacle, otherwise 1≤a_i,j≤1061 ≤ a\_{i,j} ≤ 10^6 and that cell contains a piece of candy with that number.

출력

Print a single line with the required number from the task.

힌트

Clarification of the second example:

There are three possible paths such that the product is divisible by 66: 5⋅2⋅3⋅3⋅1,5⋅2⋅3⋅6⋅1,5⋅7⋅3⋅6⋅15 · 2 · 3 · 3 · 1, 5 · 2 · 3 · 6 · 1, 5 · 7 · 3 · 6 · 1.

예제2

  1. 예제 1

    입력
    2 2
    3 2
    1 4
    
    예상 출력
    2
    
  2. 예제 2

    입력
    3 6
    5 2 -1
    7 3 6
    -1 3 1
    
    예상 출력
    3