首先求出 L 和 R 的最大匹配,如果匹配小于 $nm/2$,那就能利用剩下的格子使得匹配满足要求,否则还需要判断是否需要 $-1$。把方向看作模 $4$ 意义下的数(不妨设上左下右分别对应 $0,1,2,3$),每次旋转都是让一个数 $+1$,另一个数 $-1$,所以总和不变。最终的方案要求纵向的匹配和为 $2$,横向的匹配和为 $0$,而完美匹配中纵向、横向匹配的数量奇偶性只和 $n$, $m$ 有关,在所有完美匹配中都是相等的。因此只需要判断所有数的总和是否与这个数相等即可。时间复杂度 $O(n^2m^2)$。
QOJ.ac
QOJ
As we are currently experiencing an overwhelming number of web requests for fetching user submissions, we have temporarily disabled the full submissions list. You must now be logged in to view submissions.
Discussion #359 for Problem #12309. Slippers
Type: Editorial
Status: Open
Posted by: jiangly
Posted at: 2025-12-14 07:17:12
Last updated: 2025-12-14 07:17:22
题解
Comments
No comments yet.