답안 #260224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260224 2020-08-09T20:18:48 Z shayan_p 함박 스테이크 (JOI20_hamburg) C++14
21 / 100
3000 ms 20168 KB
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, pii> rect;

const int maxn = 2e5 + 10, mod = 1e9 + 7, inf = 1e9;

rect operator & (rect a, rect b){
    return { {max(a.F.F, b.F.F), max(a.F.S, b.F.S)}, {min(a.S.F, b.S.F), min(a.S.S, b.S.S)} };
}
pii operator & (pii a, pii b){
    return {max(a.F, b.F), min(a.S, b.S)};
}
bool inside(rect a, pii b){
    return a.F.F <= b.F && b.F <= a.S.F && a.F.S <= b.S && b.S <= a.S.S;
}
bool emp(rect a){
    return a.F.F > a.S.F || a.F.S > a.S.S;
}
bool emp(pii a){
    return a.F > a.S;
}
    
    

rect big = { {1, 1}, {inf, inf} };

int choose_and_del(vector<pii> &v){
    if(v.empty())
	return 1;
    int x = v[0].S;
    for(pii p : v)
	x = min(x, p.S);
    vector<pii> v2;
    for(pii p : v){
	if(x < p.F)
	    v2.PB(p);
    }
    v = v2;
    return x;
}

bool ok(vector<rect> &inp, vector<pii> &ans){
    for(auto a : inp){
	bool is = 0;
	for(auto b : ans)
	    is|= inside(a, b);
	if(!is)
	    return 0;
    }
    return 1;
}
vector<rect> del(vector<rect> &inp, pii p){
    vector<rect> ans;
    for(auto r : inp){
	if(inside(r, p) == 0)
	    ans.PB(r);
    }
    return ans;
}
/*
bool delta(vector<pii> &v){
    if(v.empty()){
	v.PB({1, inf});
	v.PB({1, inf});
	return 1;
    }
    vector<pii> ans;
    while(sz(v) < 2)
	v.PB(v.back());
    for(int i = 1; i < sz(v); i++)
	if(v[i].S < v[0].S)
	    swap(v[i], v[0]);
    for(int i = 2; i < sz(v); i++)
	if(v[1].F < v[i].F)
	    swap(v[i], v[1]);
    if(v[1].F <= v[0].S){
	int L = v[1].F, R = v[0].S;
	ans.PB({v[1].F, v[0].S});
	ans.PB({1, inf});
	v[1].F = R + 1;
	v[0].S = L - 1;
	for(pii p : v){
	    if((v[0] & p) == v[0] || (v[1] & p == v[1]))
		continue;	    
	}
	if(v[0].F <= v[0].S && v[1].F <= v[1].S)
		    
    }
    else{
    }
}
*/

pair<bool, vector<pii> > solve(vector<rect> inp, int k){
    vector<pii> ans;
    rect r = big;
    for(auto x : inp)
	r = r & x;
    if(r.F.F <= r.S.F){
	vector<pii> v;
	for(rect r : inp)
	    v.PB({r.F.S, r.S.S});
	for(int i = 0; i < k; i++)
	    ans.PB({r.F.F, choose_and_del(v)});
	if(v.empty())
	    return {1, ans};
	else
	    ans.clear();
	return {0, ans};
    }
    if(r.F.S <= r.S.S){
	vector<pii> v;
	for(rect r : inp)
	    v.PB({r.F.F, r.S.F});
	for(int i = 0; i < k; i++)
	    ans.PB({choose_and_del(v), r.F.S});
	if(v.empty())
	    return {1, ans};
	else
	    ans.clear();
	return {0, ans};	
    }
    if(k == 1){
	return {0, ans};
    }
    
    swap(r.F, r.S);
    
    if(k == 2){
	ans.PB(r.F);
	ans.PB(r.S);
	if(ok(inp, ans))
	    return {1, ans};
	swap(ans[0].S, ans[1].S);
	if(ok(inp, ans))
	    return {1, ans};
	ans.clear();
	return {0, ans};
    }

    for(int x : {r.F.F, r.S.F})
	for(int y : {r.F.S, r.S.S}){
	    auto p = solve(del(inp, {x, y}), k-1);
	    if(p.F){
		p.S.PB({x, y});
		return p;
	    }
	}
    if(k == 3){
	return {0, ans};
    }

    
    //    now k == 4
    
    //    vector<pii> UD, LR;
    
    rect D = {r.F, {r.S.F, r.F.S}}, U = {{r.F.F, r.S.S}, r.S}, L = {r.F, {r.F.F, r.S.S}}, R = {{r.S.F, r.F.S}, r.S};

    int BEF = 0;
    for(int w = 0; w < 50; w++){
	int NW = 0;	
	random_shuffle(inp.begin(), inp.end());
	for(rect p : inp){
	    rect eD = D & p, eU = U & p, eL = L & p, eR = R & p;
	    int C = emp(eD) + emp(eU) + emp(eL) + emp(eR);
	    if(C == 4)
		return {0, ans};
	    if(C == 3){
		NW++;
		
		if(!emp(eD))
		    D = eD;
		if(!emp(eU))
		    U = eU;
		if(!emp(eL))
		    L = eL;
		if(!emp(eR))
		    R = eR;
	    }
	    /*	    if(C == 2){
		if(!emp(eD) && !emp(eU))
		    UD.PB({p.F.F, p.S.F});
		if(!emp(eL) && !emp(eR))
		    LR.PB({p.F.S, p.S.S});	    
		    }*/
	    if(NW == BEF)
		break;
	    BEF = NW;
	}
    }
    if(emp(D) || emp(U) || emp(L) || emp(R)){
	return {0, ans};
    }
    /*
    if(!delta(UD))
	return {0, ans};
    if(!delta(LR))
	return {0, ans};
    */

    while(true){
	random_shuffle(inp.begin(), inp.end());
	rect r = D;
	vector<rect> inp2;	
	for(rect p : inp){
	    if(emp(p & r))
		inp2.PB(p);
	    else
		r = p & r;	    
	}
	auto x = solve(inp2, k-1);
	if(x.F){
	    x.S.PB(r.F);
	    return {1, x.S};
	}
    }	
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    srand(time(0));
    
    int n, k;
    cin >> n >> k;
    vector< rect > inp(n);
    for(int i = 0; i < n; i++){
	cin >> inp[i].F.F >> inp[i].F.S >> inp[i].S.F >> inp[i].S.S;
    }
    auto _ = solve(inp, k);
    vector<pii> v = _.S;
    assert(_.F);
    for(pii p : v)
	cout << p.F << " " << p.S << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 488 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 2 ms 488 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 9 ms 512 KB Output is correct
32 Correct 6 ms 544 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 4 ms 512 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 5 ms 512 KB Output is correct
44 Correct 6 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 5 ms 488 KB Output is correct
49 Correct 4 ms 512 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 4 ms 512 KB Output is correct
52 Correct 4 ms 512 KB Output is correct
53 Correct 4 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 4 ms 544 KB Output is correct
56 Correct 4 ms 512 KB Output is correct
57 Correct 5 ms 512 KB Output is correct
58 Correct 4 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 108 ms 8764 KB Output is correct
6 Correct 110 ms 8768 KB Output is correct
7 Correct 112 ms 8772 KB Output is correct
8 Correct 100 ms 8816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 98 ms 6648 KB Output is correct
6 Correct 103 ms 6648 KB Output is correct
7 Correct 98 ms 6648 KB Output is correct
8 Correct 99 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 108 ms 9964 KB Output is correct
14 Correct 106 ms 9836 KB Output is correct
15 Correct 103 ms 9196 KB Output is correct
16 Correct 102 ms 9196 KB Output is correct
17 Correct 109 ms 9964 KB Output is correct
18 Correct 133 ms 9068 KB Output is correct
19 Correct 105 ms 8816 KB Output is correct
20 Correct 164 ms 8816 KB Output is correct
21 Correct 123 ms 13844 KB Output is correct
22 Correct 112 ms 10760 KB Output is correct
23 Correct 108 ms 10860 KB Output is correct
24 Correct 155 ms 10860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 488 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 2 ms 488 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 9 ms 512 KB Output is correct
32 Correct 6 ms 544 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 4 ms 512 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 5 ms 512 KB Output is correct
44 Correct 6 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 5 ms 488 KB Output is correct
49 Correct 4 ms 512 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 4 ms 512 KB Output is correct
52 Correct 4 ms 512 KB Output is correct
53 Correct 4 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 4 ms 544 KB Output is correct
56 Correct 4 ms 512 KB Output is correct
57 Correct 5 ms 512 KB Output is correct
58 Correct 4 ms 512 KB Output is correct
59 Correct 131 ms 10172 KB Output is correct
60 Correct 106 ms 9964 KB Output is correct
61 Correct 105 ms 9836 KB Output is correct
62 Correct 104 ms 9708 KB Output is correct
63 Correct 104 ms 11244 KB Output is correct
64 Correct 101 ms 9068 KB Output is correct
65 Correct 162 ms 10220 KB Output is correct
66 Correct 102 ms 9964 KB Output is correct
67 Correct 119 ms 12956 KB Output is correct
68 Correct 117 ms 11776 KB Output is correct
69 Correct 116 ms 11712 KB Output is correct
70 Correct 122 ms 12724 KB Output is correct
71 Correct 171 ms 16748 KB Output is correct
72 Correct 1230 ms 18036 KB Output is correct
73 Correct 183 ms 16104 KB Output is correct
74 Correct 145 ms 16720 KB Output is correct
75 Correct 1303 ms 20168 KB Output is correct
76 Correct 151 ms 15536 KB Output is correct
77 Correct 213 ms 16012 KB Output is correct
78 Correct 461 ms 16284 KB Output is correct
79 Correct 158 ms 15512 KB Output is correct
80 Correct 154 ms 15752 KB Output is correct
81 Correct 845 ms 18264 KB Output is correct
82 Correct 155 ms 15072 KB Output is correct
83 Correct 128 ms 15548 KB Output is correct
84 Correct 123 ms 12772 KB Output is correct
85 Correct 145 ms 16612 KB Output is correct
86 Correct 127 ms 14916 KB Output is correct
87 Correct 139 ms 16504 KB Output is correct
88 Correct 143 ms 16316 KB Output is correct
89 Correct 1469 ms 19980 KB Output is correct
90 Correct 510 ms 16204 KB Output is correct
91 Correct 711 ms 14932 KB Output is correct
92 Correct 541 ms 16888 KB Output is correct
93 Correct 847 ms 16496 KB Output is correct
94 Correct 541 ms 18312 KB Output is correct
95 Correct 512 ms 16064 KB Output is correct
96 Correct 906 ms 19344 KB Output is correct
97 Correct 1637 ms 16376 KB Output is correct
98 Correct 622 ms 15788 KB Output is correct
99 Correct 674 ms 15904 KB Output is correct
100 Correct 673 ms 16336 KB Output is correct
101 Correct 467 ms 16396 KB Output is correct
102 Execution timed out 3067 ms 13800 KB Time limit exceeded
103 Halted 0 ms 0 KB -