[AtCoder] B

Posted Push your limit!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[AtCoder] B相关的知识,希望对你有一定的参考价值。

 

 

The key observation is that there is always at most 1 cell that violates both conditions. 

Proof: 

if x violates both conditions, that means all other numbers on the same column < x and all other nubmers on the same row > x, so we have u < x && v > x.

if there is another violating cell, by definition, it can not be on the same row or the same column with x, so have the following diagram. similarly we have u > y && v < y.

using x\'s info we have u < v; using y\'s info we have u > v, contradiction!

 

 

 

With the above observation, we iterate over all the possible violating numbers and for each such number X, we do the following calculation to get the number of invalid ways.

1. pick a cell, there are N * N possible spots.

2. For each spot, pick N - 1 numbers < X and get their permutation count; do the same for > X. 

3. For the remaining unfilled cells, there are (N * N - (N * 2 - 1))! possible ways.

4. multiply the results from step 1-3 to get the total number of invalid ways for a single violating number X.

 

Subtract the sum of all invalid ways from (N^2)! to get the final answer.

 

以上是关于[AtCoder] B的主要内容,如果未能解决你的问题,请参考以下文章

AtCoder Beginner Contest 259 - B - Counterclockwise Rotation - 题解

AtCoder Regular Contest 102

AtCoder Grand Contest 031 B - Reversi(DP)

AtCoder Beginner Contest 302

ATcoder D - Handstand 2

AtCoder Beginner Contest 155 简要题解