201431: [AtCoder]ARC143 B - Counting Grids

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

Find the number of ways, modulo $998244353$, to fill the squares of an $N \times N$ grid using each integer from $1$ to $N^2$ once so that every square satisfies at least one of the following conditions.

  • In the same column, there is a square containing a number greater than that of the concerned square.
  • In the same row, there is a square containing a number less than that of the concerned square.

Constraints

  • $1 \leq N \leq 500$

Input

Input is given from Standard Input in the following format:

$N$

Output

Print the answer.


Sample Input 1

2

Sample Output 1

8

Here is one way to fill the grid to satisfy the requirement.

13
42

Here, the top-left square contains a number less than that of the bottom-left square, satisfying the first condition. It does not satisfy the second condition, however.


Sample Input 2

5

Sample Output 2

704332752

Sample Input 3

100

Sample Output 3

927703658

Input

题意翻译

统计将 $1 \sim N^2$ 共 $N^2$ 个整数填入 $N \times N$ 的棋盘并满足对于每个格子均满足以下至少一个条件的方案数,对 $998244353$ 取模: - 该格子不是所处的列的最大值 - 该格子不是所处的行的最小值

加入题单

上一题 下一题 算法标签: