Submission #744221

# Submission time Handle Problem Language Result Execution time Memory
744221 2023-05-18T09:37:02 Z hmm789 Izvanzemaljci (COI21_izvanzemaljci) C++14
26 / 100
47 ms 9380 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) {
		if(n == 1) {
			cout << a[0].first << " " << a[0].second << " " << 1 << '\n';
			cout << a[0].first+2 << " " << a[0].second << " " << 1 << '\n';
			return 0;
		}
		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:35:63: warning: 'ans2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |   int u[n], d[n], l[n], r[n], mn = INF, x1, y1, x2, y2, ans1, ans2;
      |                                                               ^~~~
izvanzemaljci.cpp:120:19: warning: 'x1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  120 |   else cout << x1-1 << " " << y1-1 << " " << 1 << '\n';
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 2096 KB Output is correct
8 Correct 22 ms 2020 KB Output is correct
9 Correct 22 ms 2036 KB Output is correct
10 Correct 22 ms 2072 KB Output is correct
11 Correct 22 ms 1992 KB Output is correct
# 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 320 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 0 ms 312 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 43 ms 9380 KB Output is correct
11 Correct 43 ms 8940 KB Output is correct
12 Correct 44 ms 8944 KB Output is correct
13 Correct 47 ms 8904 KB Output is correct
14 Correct 44 ms 8920 KB Output is correct
15 Correct 45 ms 8908 KB Output is correct
16 Correct 45 ms 8932 KB Output is correct
17 Correct 40 ms 8304 KB Output is correct
18 Correct 41 ms 8048 KB Output is correct
19 Correct 35 ms 7464 KB Output is correct
20 Correct 37 ms 7932 KB Output is correct
21 Correct 43 ms 9028 KB Output is correct
22 Correct 42 ms 9020 KB Output is correct
23 Correct 47 ms 8908 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 340 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -