CF1198E.Rectangle Painting 2
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a square grid of size n×n . Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs min(h,w) to color a rectangle of size h×w . You are to make all cells white for minimum total cost.
The square is large, so we give it to you in a compressed way. The set of black cells is the union of m rectangles.
输入格式
The first line contains two integers n and m ( 1≤n≤109 , 0≤m≤50 ) — the size of the square grid and the number of black rectangles.
Each of the next m lines contains 4 integers xi1 yi1 xi2 yi2 ( 1≤xi1≤xi2≤n , 1≤yi1≤yi2≤n ) — the coordinates of the bottom-left and the top-right corner cells of the i -th black rectangle.
The rectangles may intersect.
输出格式
Print a single integer — the minimum total cost of painting the whole square in white.
输入输出样例
输入#1
10 2 4 1 5 10 1 4 10 5
输出#1
4
输入#2
7 6 2 1 2 1 4 2 4 3 2 5 2 5 2 3 5 3 1 2 1 2 3 2 5 3
输出#2
3
说明/提示
The examples and some of optimal solutions are shown on the pictures below.