Submission #744218

# Submission time Handle Problem Language Result Execution time Memory
744218 2023-05-18T09:31:02 Z hmm789 Izvanzemaljci (COI21_izvanzemaljci) C++14
5 / 100
25 ms 2252 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define INF 1000000000000000000

bool cmp(pair<int, int> a, pair<int, int> b) {
	if(a.second != b.second) return a.second < b.second;
	else return a.first < b.first;
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	pair<int, int> a[n];
	for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
	if(k == 1) {
		int u = -INF, d = INF, l = INF, r = -INF;
		for(int i = 0; i < n; i++) {
			u = max(u, a[i].second);
			d = min(d, a[i].second);
			r = max(r, a[i].first);
			l = min(l, a[i].first);
		}
		cout << l << " " << d << " " << max(1LL, max(u-d, r-l)) << '\n';
	} else if(k == 2) {
		sort(a, a+n);
		int u[n], d[n], l[n], r[n], mn = INF, x1, y1, x2, y2, ans1, ans2;
		u[0] = d[0] = a[0].second;
		l[0] = r[0] = a[0].first;
		int u2[n], d2[n], l2[n], r2[n];
		u2[n-1] = d2[n-1] = a[n-1].second;
		l2[n-1] = r2[n-1] = a[n-1].first;
		for(int i = 1; i < n; i++) {
			u[i] = max(u[i-1], a[i].second);
			d[i] = min(d[i-1], a[i].second);
			r[i] = max(r[i-1], a[i].first);
			l[i] = min(l[i-1], a[i].first);
		}
		for(int i = n-2; i >= 0; i--) {
			u2[i] = max(u2[i+1], a[i].second);
			d2[i] = min(d2[i+1], a[i].second);
			r2[i] = max(r2[i+1], a[i].first);
			l2[i] = min(l2[i+1], a[i].first);
		}
		for(int i = 0; i < n-1; i++) {
			int len1 = max(u[i]-d[i], r[i]-l[i]);
			int len2 = max(u2[i+1]-d2[i+1], r2[i+1]-l2[i+1]);
			if(max(len1, len2) < mn) {
				if(a[i].first != a[i+1].first) {
					mn = max(len1, len2);
					x1 = l[i]-(len1-(r[i]-l[i])); y1 = d[i];
					x2 = l2[i+1]; y2 = d2[i+1];
					ans1 = len1; ans2 = len2;
				} else {
					if(u[i] < d2[i+1]) {
						mn = max(len1, len2);
						x1 = l[i]; y1 = d[i]-(len1-(u[i]-d[i]));
						x2 = l2[i+1]; y2 = d2[i+1];
						ans1 = len1; ans2 = len2;
					} else if(u2[i+1] < d[i]) {
						mn = max(len1, len2);
						x1 = l[i]; y1 = d[i];
						x2 = l2[i+1]; y2 = d2[i+1]-(len2-(u2[i+1]-d2[i+1]));
						ans1 = len1; ans2 = len2;
					}
				}
			}
		}
		sort(a, a+n, cmp);
		u[0] = d[0] = a[0].second;
		l[0] = r[0] = a[0].first;
		u2[n-1] = d2[n-1] = a[n-1].second;
		l2[n-1] = r2[n-1] = a[n-1].first;
		for(int i = 1; i < n; i++) {
			u[i] = max(u[i-1], a[i].second);
			d[i] = min(d[i-1], a[i].second);
			r[i] = max(r[i-1], a[i].first);
			l[i] = min(l[i-1], a[i].first);
		}
		for(int i = n-2; i >= 0; i--) {
			u2[i] = max(u2[i+1], a[i].second);
			d2[i] = min(d2[i+1], a[i].second);
			r2[i] = max(r2[i+1], a[i].first);
			l2[i] = min(l2[i+1], a[i].first);
		}
		for(int i = 0; i < n-1; i++) {
			int len1 = max(u[i]-d[i], r[i]-l[i]);
			int len2 = max(u2[i+1]-d2[i+1], r2[i+1]-l2[i+1]);
			if(max(len1, len2) < mn) {
				if(a[i].second != a[i+1].second) {
					mn = max(len1, len2);
					x1 = l[i]; y1 = d[i]-(len1-(u[i]-d[i]));
					x2 = l2[i+1]; y2 = d2[i+1];
					ans1 = len1; ans2 = len2;
				} else {
					if(r[i] < l2[i+1]) {
						mn = max(len1, len2);
						x1 = l[i]-(len1-(r[i]-l[i])); y1 = d[i];
						x2 = l2[i+1]; y2 = d2[i+1];
						ans1 = len1; ans2 = len2;
					} else if(r2[i+1] <l[i]) {
						mn = max(len1, len2);
						x1 = l[i]; y1 = d[i];
						x2 = l2[i+1]-(len2-(r2[i+1]-l2[i+1])); y2 = d2[i+1];
						ans1 = len1; ans2 = len2;
					}
				}
			}
		}
		
		if(ans1) cout << x1 << " " << y1 << " " << ans1 << '\n';
		else cout << x1-1 << " " << y1-1 << " " << 1 << '\n';
		cout << x2 << " " << y2 << " " << max(1LL, ans2) << '\n';
	}
}

Compilation message

izvanzemaljci.cpp: In function 'int32_t main()':
izvanzemaljci.cpp:30:63: warning: 'ans2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |   int u[n], d[n], l[n], r[n], mn = INF, x1, y1, x2, y2, ans1, ans2;
      |                                                               ^~~~
izvanzemaljci.cpp:115:19: warning: 'x1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  115 |   else cout << x1-1 << " " << y1-1 << " " << 1 << '\n';
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 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 2124 KB Output is correct
8 Correct 22 ms 2124 KB Output is correct
9 Correct 22 ms 2224 KB Output is correct
10 Correct 22 ms 2252 KB Output is correct
11 Correct 25 ms 2248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Integer 5085241283009 violates the range [1, 2*10^9]
2 Halted 0 ms 0 KB -
# 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 336 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -