답안 #787494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787494 2023-07-19T08:31:17 Z 반딧불(#10031) 함박 스테이크 (JOI20_hamburg) C++17
21 / 100
3000 ms 17772 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void input();
bool check1();
bool check2();
bool check3();
bool check4();
void output();

int main(){
    input();
    if(!check1()) if(!check2()) if(!check3()) check4();
    output();
}

int n, k;
vector<int> xCoord(1), yCoord(1);
int L[200002], R[200002], D[200002], U[200002], X, Y;
vector<pair<int, int> > ans;

void input(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++){
        scanf("%d %d %d %d", &L[i], &D[i], &R[i], &U[i]);
        xCoord.push_back(L[i]); xCoord.push_back(R[i]);
        yCoord.push_back(D[i]); yCoord.push_back(U[i]);
    }
    sort(xCoord.begin(), xCoord.end()); xCoord.erase(unique(xCoord.begin(), xCoord.end()), xCoord.end());
    sort(yCoord.begin(), yCoord.end()); yCoord.erase(unique(yCoord.begin(), yCoord.end()), yCoord.end());
    for(int i=1; i<=n; i++){
        L[i] = lower_bound(xCoord.begin(), xCoord.end(), L[i]) - xCoord.begin();
        R[i] = lower_bound(xCoord.begin(), xCoord.end(), R[i]) - xCoord.begin();
        D[i] = lower_bound(yCoord.begin(), yCoord.end(), D[i]) - yCoord.begin();
        U[i] = lower_bound(yCoord.begin(), yCoord.end(), U[i]) - yCoord.begin();
    }
    X = (int)xCoord.size()-1, Y = (int)yCoord.size()-1;
}

bool check1(){
    int maxX = 0, maxY = 0;
    for(int i=1; i<=n; i++) maxX = max(maxX, L[i]), maxY = max(maxY, D[i]);
    for(int i=1; i<=n; i++){
        if(maxX > R[i] || maxY > U[i]) return false;
    }
    ans.push_back(make_pair(maxX, maxY));
    return true;
}

struct namespace2{
    bool tryWith(int x, int y){
        int maxL = 1, maxD = 1, minR = X, minU = Y;
        for(int i=1; i<=n; i++){
            if(L[i] <= x && x <= R[i] && D[i] <= y && y <= U[i]) continue;
            maxL = max(maxL, L[i]), maxD = max(maxD, D[i]);
            minR = min(minR, R[i]), minU = min(minU, U[i]);
        }
        if(maxL <= minR && maxD <= minU){
            ans.push_back(make_pair(x, y));
            ans.push_back(make_pair(maxL, maxD));
            return true;
        }
        return false;
    }

    bool check2(){
        int maxL = *max_element(L+1, L+n+1);
        int minR = *min_element(R+1, R+n+1);
        int maxD = *max_element(D+1, D+n+1);
        int minU = *min_element(U+1, U+n+1);
        if(tryWith(maxL, maxD)) return true;
        if(tryWith(maxL, minU)) return true;
        if(tryWith(minR, maxD)) return true;
        if(tryWith(minR, minU)) return true;
        return false;
    }
} p2;

bool check2(){
    return p2.check2();
}

struct namespace3{
    bool check2(int n, vector<int> &L, vector<int> &R, vector<int> &D, vector<int> &U, int px, int py){
        int maxL = *max_element(L.begin(), L.end());
        int minR = *min_element(R.begin(), R.end());
        int maxD = *max_element(D.begin(), D.end());
        int minU = *min_element(U.begin(), U.end());
        int Xd[2] = {maxL, minR}, Yd[2] = {maxD, minU};
        for(int a: Xd) for(int b: Yd){
            int maxL = 1, maxD = 1, minR = X, minU = Y;
            for(int i=0; i<n; i++){
                if(L[i] <= a && a <= R[i] && D[i] <= b && b <= U[i]) continue;
                maxL = max(maxL, L[i]), maxD = max(maxD, D[i]);
                minR = min(minR, R[i]), minU = min(minU, U[i]);
            }
            if(maxL <= minR && maxD <= minU){
                ans.push_back(make_pair(px, py));
                ans.push_back(make_pair(a, b));
                ans.push_back(make_pair(maxL, maxD));
                return true;
            }
        }
        return false;
    }

    bool tryWith(int x, int y){
        vector<int> _L,_R,_D,_U;
        for(int i=1; i<=n; i++){
            if(L[i]<=x && x<=R[i] && D[i]<=y && y<=U[i]) continue;
            else _L.push_back(L[i]), _R.push_back(R[i]), _D.push_back(D[i]), _U.push_back(U[i]);
        }
        return check2((int)_L.size(),_L,_R,_D,_U,x,y);
    }

    bool check3(){
        int maxL = *max_element(L+1, L+n+1);
        int minR = *min_element(R+1, R+n+1);
        int maxD = *max_element(D+1, D+n+1);
        int minU = *min_element(U+1, U+n+1);
        if(tryWith(maxL, maxD)) return true;
        if(tryWith(maxL, minU)) return true;
        if(tryWith(minR, maxD)) return true;
        if(tryWith(minR, minU)) return true;
        return false;
    }

    bool tryWith(int x, int y, vector<int> &L, vector<int> &R, vector<int> &D, vector<int> &U, int px, int py){
        vector<int> _L,_R,_D,_U;
        for(int i=0; i<(int)L.size(); i++){
            if(L[i]<=x && x<=R[i] && D[i]<=y && y<=U[i]) continue;
            else _L.push_back(L[i]), _R.push_back(R[i]), _D.push_back(D[i]), _U.push_back(U[i]);
        }
        if(check2((int)_L.size(),_L,_R,_D,_U,x,y)){
            ans.push_back(make_pair(px, py));
            return true;
        }
        else return false;
    }

    bool check3(int n, vector<int> &L, vector<int> &R, vector<int> &D, vector<int> &U, int px, int py){
        int maxL = *max_element(L.begin(), L.end());
        int minR = *min_element(R.begin(), R.end());
        int maxD = *max_element(D.begin(), D.end());
        int minU = *min_element(U.begin(), U.end());
        if(tryWith(maxL, maxD, L, R, D, U, px, py)) return true;
        if(tryWith(maxL, minU, L, R, D, U, px, py)) return true;
        if(tryWith(minR, maxD, L, R, D, U, px, py)) return true;
        if(tryWith(minR, minU, L, R, D, U, px, py)) return true;
        return false;
    }
} p3;

bool check3(){
    return p3.check3();
}

struct namespace4{
    bool tryWith(int x, int y){
        vector<int> _L,_R,_D,_U;
        for(int i=1; i<=n; i++){
            if(L[i]<=x && x<=R[i] && D[i]<=y && y<=U[i]) continue;
            else _L.push_back(L[i]), _R.push_back(R[i]), _D.push_back(D[i]), _U.push_back(U[i]);
        }
        return p3.check3((int)_L.size(),_L,_R,_D,_U,x,y);
    }

    bool check4(){
        int maxL = *max_element(L+1, L+n+1);
        int minR = *min_element(R+1, R+n+1);
        int maxD = *max_element(D+1, D+n+1);
        int minU = *min_element(U+1, U+n+1);
        if(tryWith(maxL, maxD)) return true;
        if(tryWith(maxL, minU)) return true;
        if(tryWith(minR, maxD)) return true;
        if(tryWith(minR, minU)) return true;

        /// ���⼭���ʹ� �� ���� ��谡 ������ ���
        for(int i=1; i<=Y; i++) if(tryWith(maxL, i)) return true;
        return false;
    }
} p4;

bool check4(){
    return p4.check4();
}

void output(){
    if(ans.empty()) exit(1);
    while((int)ans.size() < k) ans.push_back(ans.back());
    for(auto p: ans) printf("%d %d\n", xCoord[p.first], yCoord[p.second]);
}

Compilation message

hamburg.cpp: In function 'void input()':
hamburg.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
hamburg.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d %d %d %d", &L[i], &D[i], &R[i], &U[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 412 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 396 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 4 ms 428 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 409 ms 448 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 452 KB Output is correct
17 Correct 270 ms 532 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 314 ms 448 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 3 ms 448 KB Output is correct
23 Correct 312 ms 524 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 262 ms 572 KB Output is correct
32 Correct 262 ms 468 KB Output is correct
33 Correct 300 ms 468 KB Output is correct
34 Correct 300 ms 524 KB Output is correct
35 Correct 341 ms 520 KB Output is correct
36 Correct 240 ms 468 KB Output is correct
37 Correct 468 ms 520 KB Output is correct
38 Correct 455 ms 468 KB Output is correct
39 Correct 322 ms 468 KB Output is correct
40 Correct 218 ms 524 KB Output is correct
41 Correct 426 ms 520 KB Output is correct
42 Correct 406 ms 468 KB Output is correct
43 Correct 411 ms 520 KB Output is correct
44 Correct 301 ms 516 KB Output is correct
45 Correct 3 ms 468 KB Output is correct
46 Correct 464 ms 468 KB Output is correct
47 Correct 219 ms 520 KB Output is correct
48 Correct 425 ms 524 KB Output is correct
49 Correct 278 ms 468 KB Output is correct
50 Correct 334 ms 520 KB Output is correct
51 Correct 371 ms 524 KB Output is correct
52 Correct 282 ms 516 KB Output is correct
53 Correct 369 ms 520 KB Output is correct
54 Correct 524 ms 516 KB Output is correct
55 Correct 317 ms 468 KB Output is correct
56 Correct 307 ms 520 KB Output is correct
57 Correct 294 ms 468 KB Output is correct
58 Correct 300 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 240 ms 7116 KB Output is correct
6 Correct 230 ms 7064 KB Output is correct
7 Correct 235 ms 7172 KB Output is correct
8 Correct 227 ms 7076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 242 ms 7176 KB Output is correct
6 Correct 236 ms 7088 KB Output is correct
7 Correct 256 ms 7228 KB Output is correct
8 Correct 238 ms 7164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 236 ms 9480 KB Output is correct
14 Correct 250 ms 9696 KB Output is correct
15 Correct 249 ms 9776 KB Output is correct
16 Correct 237 ms 9080 KB Output is correct
17 Correct 244 ms 9728 KB Output is correct
18 Correct 242 ms 8236 KB Output is correct
19 Correct 252 ms 11384 KB Output is correct
20 Correct 260 ms 11772 KB Output is correct
21 Correct 253 ms 11384 KB Output is correct
22 Correct 245 ms 11768 KB Output is correct
23 Correct 276 ms 11640 KB Output is correct
24 Correct 248 ms 11508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 412 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 396 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 4 ms 428 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 409 ms 448 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 452 KB Output is correct
17 Correct 270 ms 532 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 314 ms 448 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 3 ms 448 KB Output is correct
23 Correct 312 ms 524 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 262 ms 572 KB Output is correct
32 Correct 262 ms 468 KB Output is correct
33 Correct 300 ms 468 KB Output is correct
34 Correct 300 ms 524 KB Output is correct
35 Correct 341 ms 520 KB Output is correct
36 Correct 240 ms 468 KB Output is correct
37 Correct 468 ms 520 KB Output is correct
38 Correct 455 ms 468 KB Output is correct
39 Correct 322 ms 468 KB Output is correct
40 Correct 218 ms 524 KB Output is correct
41 Correct 426 ms 520 KB Output is correct
42 Correct 406 ms 468 KB Output is correct
43 Correct 411 ms 520 KB Output is correct
44 Correct 301 ms 516 KB Output is correct
45 Correct 3 ms 468 KB Output is correct
46 Correct 464 ms 468 KB Output is correct
47 Correct 219 ms 520 KB Output is correct
48 Correct 425 ms 524 KB Output is correct
49 Correct 278 ms 468 KB Output is correct
50 Correct 334 ms 520 KB Output is correct
51 Correct 371 ms 524 KB Output is correct
52 Correct 282 ms 516 KB Output is correct
53 Correct 369 ms 520 KB Output is correct
54 Correct 524 ms 516 KB Output is correct
55 Correct 317 ms 468 KB Output is correct
56 Correct 307 ms 520 KB Output is correct
57 Correct 294 ms 468 KB Output is correct
58 Correct 300 ms 468 KB Output is correct
59 Correct 290 ms 13024 KB Output is correct
60 Correct 272 ms 12420 KB Output is correct
61 Correct 272 ms 12492 KB Output is correct
62 Correct 260 ms 11944 KB Output is correct
63 Correct 259 ms 12404 KB Output is correct
64 Correct 248 ms 9088 KB Output is correct
65 Correct 281 ms 13056 KB Output is correct
66 Correct 321 ms 16076 KB Output is correct
67 Correct 289 ms 14332 KB Output is correct
68 Correct 379 ms 16600 KB Output is correct
69 Correct 368 ms 17408 KB Output is correct
70 Correct 345 ms 16460 KB Output is correct
71 Correct 279 ms 13988 KB Output is correct
72 Execution timed out 3044 ms 17772 KB Time limit exceeded
73 Halted 0 ms 0 KB -