답안 #671753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671753 2022-12-13T16:47:35 Z Nimbostratus Drvca (COCI19_drvca) C++17
110 / 110
236 ms 12188 KB
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using lint = long long;
const int maxn = 2e5 + 5;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;

int n;
int a[maxn];
multiset<int> s1;
multiset<int> s2;
multiset<int> sd;

void print() {
	cout << s1.size() << endl;
	while(!s1.empty()) {
		cout << *s1.begin() << " ";
		s1.erase(s1.begin());
	}
	cout << endl;
	cout << s2.size() << endl;
	while(!s2.empty()) {
		cout << *s2.begin() << " ";
		s2.erase(s2.begin());
	}
}

bool trav(int i, int j) {
	s1.clear();
	s2.clear();
	sd.clear();
	for(int pos = 0; pos < n; pos++) {
		if(pos > 0 && pos != i && pos - 1 != i)
			sd.insert(a[pos] - a[pos - 1]);
		else if(pos > 1 && pos != i && pos - 1 == i)
			sd.insert(a[pos] - a[pos - 2]);
		if(pos == i)
			s1.insert(a[pos]);
		else
			s2.insert(a[pos]);
	}
	int d = a[j] - a[i];
	for(int k = 2, curr; k <= n; k++) {
		curr = a[i] + (k - 1) * d;
		auto it = s2.find(curr);
		if(it == s2.end())
			return false;
		int prv = 0, nxt = 0;
		if(it != s2.begin()) {
			prv = *prev(it);
			sd.erase(sd.find(curr - prv));
		}
		it++;
		if(it != s2.end()) {
			nxt = *it;
			sd.erase(sd.find(nxt - curr));
		}
		it--;
		if(prv && nxt)
			sd.insert(nxt - prv);
		s2.erase(it);
		s1.insert(curr);
		if(*sd.begin() == *sd.rbegin())
			return true;
	}
	return false;
}

signed main() {
	#ifdef Local
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	if(n == 2) {
		cout << 1 << endl << a[0] << endl;
		cout << 1 << endl << a[1] << endl;
		return 0;
	}
	if(n == 3) {
		cout << 1 << endl << a[0] << endl;
		cout << 2 << endl << a[1] << " " << a[2] << endl;
		return 0;
	}
	if(trav(0, 1)) {
		print();
		return 0;
	}
	if(trav(0, 2)) {
		print();
		return 0;
	}
	if(trav(1, 2)) {
		print();
		return 0;
	}
	cout << -1 << endl;
}
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 244 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 11072 KB Output is correct
2 Correct 79 ms 12044 KB Output is correct
3 Correct 105 ms 12056 KB Output is correct
4 Correct 82 ms 12188 KB Output is correct
5 Correct 96 ms 11976 KB Output is correct
6 Correct 81 ms 11980 KB Output is correct
7 Correct 97 ms 12064 KB Output is correct
8 Correct 82 ms 11980 KB Output is correct
9 Correct 79 ms 11380 KB Output is correct
10 Correct 95 ms 12020 KB Output is correct
11 Correct 63 ms 12164 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 244 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 98 ms 11072 KB Output is correct
32 Correct 79 ms 12044 KB Output is correct
33 Correct 105 ms 12056 KB Output is correct
34 Correct 82 ms 12188 KB Output is correct
35 Correct 96 ms 11976 KB Output is correct
36 Correct 81 ms 11980 KB Output is correct
37 Correct 97 ms 12064 KB Output is correct
38 Correct 82 ms 11980 KB Output is correct
39 Correct 79 ms 11380 KB Output is correct
40 Correct 95 ms 12020 KB Output is correct
41 Correct 63 ms 12164 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 105 ms 11976 KB Output is correct
44 Correct 236 ms 11080 KB Output is correct
45 Correct 74 ms 11516 KB Output is correct
46 Correct 80 ms 12092 KB Output is correct
47 Correct 204 ms 11084 KB Output is correct
48 Correct 71 ms 11472 KB Output is correct
49 Correct 90 ms 12076 KB Output is correct
50 Correct 164 ms 10980 KB Output is correct
51 Correct 72 ms 11524 KB Output is correct
52 Correct 84 ms 12092 KB Output is correct
53 Correct 194 ms 11064 KB Output is correct
54 Correct 73 ms 11468 KB Output is correct
55 Correct 93 ms 12056 KB Output is correct
56 Correct 80 ms 12076 KB Output is correct
57 Correct 61 ms 12032 KB Output is correct
58 Correct 1 ms 212 KB Output is correct