답안 #258819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258819 2020-08-06T15:06:50 Z Saboon 함박 스테이크 (JOI20_hamburg) C++14
6 / 100
122 ms 4272 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;

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

int L[maxn], R[maxn], D[maxn], U[maxn];
int mark[maxn];
pair<int,int> ans[5];
int rot = 0;

bool check(int,int,int,int);

bool solve(int n, int k){
	if (k == 1){
		bool cor = 1;
		int x = inf-1, y = inf-1;
		for (int i = 1; i <= n; i++)
			if (!mark[i])
				x = min(x, R[i]), y = min(y, U[i]);
		for (int i = 1; i <= n; i++)
			if (!mark[i])
				cor &= (L[i] <= x and x <= R[i] and D[i] <= y and y <= U[i]);
		if (cor)
			ans[k] = {x,y};
		return cor;
	}
	if (k == 2){
		int x = inf-1, y1 = inf-1, y2 = 1;
		for (int i = 1; i <= n; i++)
			if (mark[i] <= i)
				x = min(x, R[i]), y1 = min(y1, U[i]), y2 = max(y2, D[i]);
		bool ret = check(n, k, x, y1);
		if (ret == true)
			return true;
		ret = check(n, k, x, y2);
		return ret;
	}
	if (k == 3){
		int x1 = inf-1, x2 = 1, y1 = inf-1, y2 = 1;
		for (int i = 1; i <= n; i++)
			if (mark[i] <= i)
				x1 = min(x1, R[i]), x2 = max(x2, L[i]), y1 = min(y1, U[i]), y2 = max(y2, D[i]);
		bool ret = check(n, k, x1, y1);
		if (ret == true)
			return true;
		ret = check(n, k, x1, y2);
		if (ret == true)
			return true;
		ret = check(n, k, x2, y1);
		if (ret == true)
			return true;
		ret = check(n, k, x2, y2);
		return ret;
	}
	if (k == 4){
		int x = inf-1;
		for (int i = 1; i <= n; i++)
			x = min(x, R[i]);
		vector<pair<int,int>> seg;
		for (int i = 1; i <= n; i++)
			if (L[i] <= x)
				seg.push_back({D[i],i});
		sort(seg.rbegin(), seg.rend());
		int minl = inf;
		for (auto it : seg){
			int idx = it.second;
			if (U[idx] < minl){
				bool ret = check(n, k, x, U[idx]);
				if (ret)
					return true;
				minl = U[idx];
			}
		}
		int cnt = 0;
		for (int i = 1; i <= n; i++)
			if (L[i] <= x)
				seg[cnt++] = {U[i],i};
		sort(seg.begin(), seg.end());
		int maxr = 0;
		for (auto it : seg){
			int idx = it.second;
			if (maxr < D[idx]){
				bool ret = check(n, k, x, D[idx]);
				if (ret)
					return true;
				maxr = D[idx];
			}
		}
		if (rot == 0){
			for (int i = 1; i <= n; i++){
				int l = L[i], r = R[i], u = U[i], d = D[i];
				L[i] = inf - r, R[i] = inf - l;
			}
			rot ++;
			bool ret = solve(n,k);
			if (ret == true){
				for (int i = 1; i <= k; i++)
					ans[i].first = inf - ans[i].first;
				return true;
			}
		}
	}
	return false;
}

bool check(int n, int k, int x, int y){
	for (int i = 1; i <= n; i++){
		if (mark[i] > k)
			continue;
		if (L[i] <= x and x <= R[i] and D[i] <= y and y <= U[i])
			mark[i] = k;
		else
			mark[i] = 0;
	}
	ans[k] = {x,y};
	bool ret = solve(n, k-1);
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> L[i] >> D[i] >> R[i] >> U[i];
	bool solved = solve(n, k);
	assert(solved);
	for (int i = 1; i <= k; i++)
		cout << ans[i].first << " " << ans[i].second << endl;
}

Compilation message

hamburg.cpp: In function 'bool solve(int, int)':
hamburg.cpp:94:29: warning: unused variable 'u' [-Wunused-variable]
   94 |     int l = L[i], r = R[i], u = U[i], d = D[i];
      |                             ^
hamburg.cpp:94:39: warning: unused variable 'd' [-Wunused-variable]
   94 |     int l = L[i], r = R[i], u = U[i], d = D[i];
      |                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 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 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 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 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 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 100 ms 3448 KB Output is correct
6 Correct 106 ms 3448 KB Output is correct
7 Correct 100 ms 3400 KB Output is correct
8 Correct 98 ms 3448 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 109 ms 4272 KB Output is correct
6 Correct 102 ms 4240 KB Output is correct
7 Correct 122 ms 4176 KB Output is correct
8 Correct 108 ms 4268 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 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -