답안 #259457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259457 2020-08-07T21:24:53 Z shayan_p 함박 스테이크 (JOI20_hamburg) C++14
15 / 100
129 ms 13844 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)} };
}
bool inside(rect a, rect b){// b inside a
    return a.F.F < b.F.F && a.F.S < b.F.S && b.S.F < a.S.F && b.S.S < a.S.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;
}

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;
}

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;
	    }
	}
    return {0, ans};   	    
}

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

    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 2 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 2 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 2 ms 384 KB Output is correct
2 Correct 2 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 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 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 1 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 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 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 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 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 106 ms 8816 KB Output is correct
6 Correct 103 ms 8820 KB Output is correct
7 Correct 103 ms 8772 KB Output is correct
8 Correct 100 ms 8768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 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 106 ms 6648 KB Output is correct
6 Correct 103 ms 6600 KB Output is correct
7 Correct 102 ms 6648 KB Output is correct
8 Correct 102 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 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 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 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 111 ms 9968 KB Output is correct
14 Correct 105 ms 9836 KB Output is correct
15 Correct 101 ms 9196 KB Output is correct
16 Correct 106 ms 9196 KB Output is correct
17 Correct 110 ms 9964 KB Output is correct
18 Correct 103 ms 9068 KB Output is correct
19 Correct 105 ms 8772 KB Output is correct
20 Correct 104 ms 8816 KB Output is correct
21 Correct 120 ms 13844 KB Output is correct
22 Correct 115 ms 10724 KB Output is correct
23 Correct 129 ms 10808 KB Output is correct
24 Correct 112 ms 10816 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 1 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 512 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 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 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -