Submission #258758

# Submission time Handle Problem Language Result Execution time Memory
258758 2020-08-06T14:06:02 Z Saboon Hamburg Steak (JOI20_hamburg) C++14
2 / 100
115 ms 3576 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

multiset<int> Ls, Ds, Rs, Us;
int L[maxn], R[maxn], D[maxn], U[maxn];
int mark[maxn];

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)
			cout << x << " " << y << endl;
		return true;
	}
	if (k == 2){
		int x = inf, y1 = inf, y2 = 0;
		for (int i = 1; i <= n; i++)
			if (!mark[i])
				x = min(x, R[i]), y1 = min(y1, U[i]), y2 = max(y2, D[i]);
		if (x == inf and y1 == inf){
			cout << 1 << " " << 1 << endl;
			cout << 1 << " " << 1 << endl;
			return true;
		}
		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, x2 = 0, y1 = inf, y2 = 0;
		for (int i = 1; i <= n; i++)
			if (!mark[i])
				x1 = min(x1, R[i]), x2 = max(x2, L[i]), y1 = min(y1, U[i]), y2 = max(y2, D[i]);
		if (x1 == inf and y1 == inf){
			cout << 1 << " " << 1 << endl;
			cout << 1 << " " << 1 << endl;
			cout << 1 << " " << 1 << endl;
			return true;
		}
		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 true;
	}
}

bool check(int n, int k, int x, int y){
	for (int i = 1; i <= n; i++)
		if (!mark[i] and L[i] <= x and x <= R[i] and D[i] <= y and y <= U[i])
			mark[i] = k;
	bool ret = solve(n, k-1);
	if (ret == true){
		cout << x << " " << y << endl;
		return true;
	}
	for (int i = 1; i <= n; i++)
		if (mark[i] == k)
			mark[i] = 0;
	return false;
}

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];
//		Ls.insert(L[i]), Ds.insert(D[i]), Rs.insert(R[i]), Us.insert(U[i]);
	}
	bool solved = solve(n, k);
	assert(solved);
}

Compilation message

hamburg.cpp: In function 'bool solve(int, int)':
hamburg.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
   67 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 412 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 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 Incorrect 2 ms 384 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 ms 384 KB Output is correct
5 Correct 115 ms 3416 KB Output is correct
6 Correct 110 ms 3448 KB Output is correct
7 Correct 99 ms 3576 KB Output is correct
8 Correct 99 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 412 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 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 Incorrect 2 ms 384 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -