Submission #744197

# Submission time Handle Problem Language Result Execution time Memory
744197 2023-05-18T09:07:57 Z siewjh Izvanzemaljci (COI21_izvanzemaljci) C++17
26 / 100
55 ms 9928 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 2e9 + 5;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
bool cmp(pair<ll, ll> &a, pair<ll, ll> &b){
	return a.second < b.second;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int nums, k; cin >> nums >> k;
	if (k == 1){
		ll mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
		for (int i = 0; i < nums; i++){
			ll x, y; cin >> x >> y;
			mnx = min(mnx, x); mny = min(mny, y);
			mxx = max(mxx, x); mxy = max(mxy, y);
		}
		cout << mnx << ' ' << mny << ' ' << max(1ll, max(mxx - mnx, mxy - mny));
	}
	else if (k == 2){
		vector<iii> ans(2); ll sqsz = inf;
		vector<pair<ll, ll>> pts(nums + 1);
		pts[0] = {-inf, -inf};
		for (int i = 1; i <= nums; i++){
			ll x, y; cin >> x >> y;
			pts[i] = {x, y};
		}
		{
			sort(pts.begin(), pts.end());
			vector<iiii> pref(nums + 1), suff(nums + 2);
			ll mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
			pref[0] = {mnx, mny, mxx, mxy};
			for (int i = 1; i <= nums; i++){
				ll x = pts[i].first, y = pts[i].second;
				mnx = min(mnx, x); mny = min(mny, y);
				mxx = max(mxx, x); mxy = max(mxy, y);
				if (i != nums && pts[i].first == pts[i + 1].first) pref[i] = {-inf, -inf, -inf, -inf};
				else pref[i] = {mnx, mny, mxx, mxy};
			}
			mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
			suff[nums + 1] = {mnx, mny, mxx, mxy};
			for (int i = nums; i >= 1; i--){
				ll x = pts[i].first, y = pts[i].second;
				mnx = min(mnx, x); mny = min(mny, y);
				mxx = max(mxx, x); mxy = max(mxy, y);
				if (i != 1 && pts[i].first == pts[i - 1].first) suff[i] = {-inf, -inf, -inf, -inf};
				else suff[i] = {mnx, mny, mxx, mxy};
			}
			for (int i = 0; i <= nums; i++){
				if (get<0>(pref[i]) == -inf) continue;
				iii psq, ssq; ll sz = 1;
				if (i == 0){
					psq = {-inf, -inf, 1};
					sz = max(sz, 1ll);
				}
				else{
					ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = pref[i];
					ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
					psq = {cmxx - csz, cmxy - csz, csz};
					sz = max(sz, csz);
				}
				if (i == nums){
					ssq = {inf, inf, 1};
					sz = max(sz, 1ll);
				}
				else{
					ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = suff[i + 1];
					ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
					ssq = {cmnx, cmny, csz};
					sz = max(sz, csz);
				}
				if (sz < sqsz){
					ans = {psq, ssq};
					sqsz = sz;
				}
			}
		}
		{
			sort(pts.begin(), pts.end(), cmp);
			vector<iiii> pref(nums + 1), suff(nums + 2);
			ll mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
			pref[0] = {mnx, mny, mxx, mxy};
			for (int i = 1; i <= nums; i++){
				ll x = pts[i].first, y = pts[i].second;
				mnx = min(mnx, x); mny = min(mny, y);
				mxx = max(mxx, x); mxy = max(mxy, y);
				if (i != nums && pts[i].second == pts[i + 1].second) pref[i] = {-inf, -inf, -inf, -inf};
				else pref[i] = {mnx, mny, mxx, mxy};
			}
			mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
			suff[nums + 1] = {mnx, mny, mxx, mxy};
			for (int i = nums; i >= 1; i--){
				ll x = pts[i].first, y = pts[i].second;
				mnx = min(mnx, x); mny = min(mny, y);
				mxx = max(mxx, x); mxy = max(mxy, y);
				if (i != 1 && pts[i].second == pts[i - 1].second) suff[i] = {-inf, -inf, -inf, -inf};
				else suff[i] = {mnx, mny, mxx, mxy};
			}
			for (int i = 0; i <= nums; i++){
				if (get<0>(pref[i]) == -inf) continue;
				iii psq, ssq; ll sz = 1;
				if (i == 0){
					psq = {-inf, -inf, 1};
					sz = max(sz, 1ll);
				}
				else{
					ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = pref[i];
					ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
					psq = {cmxx - csz, cmxy - csz, csz};
					sz = max(sz, csz);
				}
				if (i == nums){
					ssq = {inf, inf, 1};
					sz = max(sz, 1ll);
				}
				else{
					ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = suff[i + 1];
					ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
					ssq = {cmnx, cmny, csz};
					sz = max(sz, csz);
				}
				if (sz < sqsz){
					ans = {psq, ssq};
					sqsz = sz;
				}
			}
		}
		for (int i = 0; i < 2; i++){
			ll x, y, sz; tie(x, y, sz) = ans[i];
			cout << x << ' ' << y << ' ' << sz << '\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 22 ms 2216 KB Output is correct
8 Correct 23 ms 2336 KB Output is correct
9 Correct 20 ms 2220 KB Output is correct
10 Correct 22 ms 2212 KB Output is correct
11 Correct 22 ms 2332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 49 ms 9320 KB Output is correct
11 Correct 47 ms 9812 KB Output is correct
12 Correct 47 ms 9928 KB Output is correct
13 Correct 50 ms 9864 KB Output is correct
14 Correct 55 ms 9864 KB Output is correct
15 Correct 51 ms 9900 KB Output is correct
16 Correct 52 ms 9808 KB Output is correct
17 Correct 44 ms 8948 KB Output is correct
18 Correct 45 ms 8744 KB Output is correct
19 Correct 38 ms 7900 KB Output is correct
20 Correct 46 ms 8476 KB Output is correct
21 Correct 55 ms 9860 KB Output is correct
22 Correct 49 ms 9808 KB Output is correct
23 Correct 48 ms 9808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 328 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -