比赛 2024暑假C班集训9 评测结果 AAAWWWW
题目名称 矩形覆盖 最终得分 43
用户昵称 darkMoon 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2024-07-09 11:54:15
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
// #define fin cin
// #define fout cout
ifstream fin("jxfg.in");
ofstream fout("jxfg.out");
auto mread = [](){
    int x;
    fin >> x;
    return x;
};
const int N = 55;
int n = mread(), k = mread(), a[N], b[N];
signed main(){
    for(int i = 1; i <= n; i ++){
        a[i] = mread();
        b[i] = mread();
    }
    if(k == 1){
        int xmi = 501, xma = -1, ymi = 501, yma = -1;
        for(int i = 1; i <= n; i ++){
            xmi = min(xmi, a[i]);
            xma = max(xma, a[i]);
            ymi = min(ymi, b[i]);
            yma = max(yma, b[i]);
        }
        fout << (xma - xmi) * (yma - ymi);
    }
    else if(k == 2){
        int mi = LONG_LONG_MAX;
        for(int i = 1; i <= n; i ++){
            int xmi = 501, xma = -1, ymi = 501, yma = -1;
            for(int j = 1; j <= n; j ++){
                if(a[j] <= a[i]){
                    xmi = min(xmi, a[j]);
                    xma = max(xma, a[j]);
                    ymi = min(ymi, b[j]);
                    yma = max(yma, b[j]);
                }
            }
            int ans = 0;
            if(xmi <= 500){
                ans += (xma - xmi) * (yma - ymi);
            }
            xmi = 501, xma = -1, ymi = 501, yma = -1;
            for(int j = 1; j <= n; j ++){
                if(a[j] > a[i]){
                    xmi = min(xmi, a[j]);
                    xma = max(xma, a[j]);
                    ymi = min(ymi, b[j]);
                    yma = max(yma, b[j]);
                }
            }
            if(xmi <= 500){
                ans += (xma - xmi) * (yma - ymi);
            }
            mi = min(mi, ans);
        }
        for(int i = 1; i <= n; i ++){
            int xmi = 501, xma = -1, ymi = 501, yma = -1;
            for(int j = 1; j <= n; j ++){
                if(b[j] <= b[i]){
                    xmi = min(xmi, a[j]);
                    xma = max(xma, a[j]);
                    ymi = min(ymi, b[j]);
                    yma = max(yma, b[j]);
                }
            }
            int ans = 0;
            if(xmi <= 500){
                ans += (xma - xmi) * (yma - ymi);
            }
            xmi = 501, xma = -1, ymi = 501, yma = -1;
            for(int j = 1; j <= n; j ++){
                if(b[j] > b[i]){
                    xmi = min(xmi, a[j]);
                    xma = max(xma, a[j]);
                    ymi = min(ymi, b[j]);
                    yma = max(yma, b[j]);
                }
            }
            if(xmi <= 500){
                ans += (xma - xmi) * (yma - ymi);
            }
            mi = min(mi, ans);
        }
        fout << mi;
    }
    else if(k == 3){
        for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= n; j ++){
                for(int k = 1; k <= n; k ++){
                    for(int l = 1; l <= n; l ++){
                        int x_11 = a[i], y_11 = b[i], x_12 = a[j], y_12 = b[j];
                        int x_21 = a[k], y_21 = b[k], x_22 = a[l], y_22 = b[l];
                        int xmi = 501, xma = -1, ymi = 501, yma = -1;
                        for(int j = 1; j <= n; j ++){
                            if(a[j] > a[i]){
                                xmi = min(xmi, a[j]);
                                xma = max(xma, a[j]);
                                ymi = min(ymi, b[j]);
                                yma = max(yma, b[j]);
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}