Counting Grids

AtCoder
IDarc143_b
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
2
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.
Input #2
5
Output #2
704332752
Input #3
100
Output #3
927703658
API Response (JSON)
{
  "problem": {
    "name": "Counting Grids",
    "description": {
      "content": "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 conditio",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc143_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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 conditio...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments