답안 #442659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442659 2021-07-08T13:53:09 Z Saynaa Drvca (COCI19_drvca) C++14
110 / 110
147 ms 7372 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
int n, a[MAXN];
multiset< int > all, m1, m2;

bool solve(int d, int mn){
	m1.clear(), m2.clear(), all.clear();
	for(int i = 0; i < n; i ++)
		all.insert(a[i]);
	while( 1 ){
		if( all.empty() || *all.lower_bound(mn) != mn)
			break;
		m1.insert(mn), all.erase(all.lower_bound(mn));
		mn += d;
	}
	if( all.empty()){
		cout << m1.size() - 1 << endl;
		int i = 0;
		for(multiset< int > :: iterator it = m1.begin(); i < m1.size() - 1; it ++, i ++)
			cout << *it << " ";
		cout << endl << 1 << endl;
		cout << *(--m1.end()) << endl;
		return true;
	}
	if( all.size() <= 2){
		cout << m1.size() << endl;
		for(multiset< int > :: iterator it = m1.begin(); it != m1.end(); it ++)
			cout << *it << " ";
		cout << endl << m2.size() << endl;
		for(multiset< int > :: iterator it = m2.begin();it != m2.end(); it ++)
			cout << *it << " ";
		cout << endl;
		return true;
	}
	multiset< int > :: iterator ls = all.end();
	ls --;
	bool ok = false;
	mn = *all.begin();
	d = min(*(++all.begin()) - mn, *(all.rbegin()) - *(--ls));
	while( all.size() ){
		if( *all.lower_bound(mn) != mn){
			if( m1.count(mn)){
				m1.erase(m1.lower_bound(mn));
				m2.insert(mn);
				mn += d;
				ok = true;
				continue;
			}	
			else return false;
		}
		m2.insert(mn);
		all.erase(all.lower_bound(mn));
		mn += d;
	}
	while( ok && *m1.lower_bound(mn) == mn){
		m1.erase(m1.lower_bound(mn));
		m2.insert(mn);
		mn += d;
	}
	if( ok && *m1.lower_bound(mn) == mn) return false;
	if( m1.empty()) return false;
	cout << m1.size() << endl;
	for(multiset< int > :: iterator it = m1.begin(); it != m1.end(); it ++)
		cout << *it << " ";
	cout << endl << m2.size() << endl;
	for(multiset< int > :: iterator it = m2.begin();it != m2.end(); it ++)
		cout << *it << " ";
	cout << endl;
	return true;	
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	if( n == 2){
		cout << 1 << endl << a[0] << endl;
		cout << 1 << endl << a[1] << endl;
		return 0;
	}
	sort(a, a + n);
	if( solve(a[1] - a[0], a[0]))
		return 0;
	if( solve(a[2] - a[0], a[0]))
		return 0;
	if( solve(a[2] - a[1], a[1]))
		return 0;
	cout << -1 << endl;
	
	return 0;
}

Compilation message

drvca.cpp: In function 'bool solve(int, int)':
drvca.cpp:21:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::multiset<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(multiset< int > :: iterator it = m1.begin(); i < m1.size() - 1; it ++, i ++)
      |                                                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 7320 KB Output is correct
2 Correct 87 ms 7308 KB Output is correct
3 Correct 90 ms 7356 KB Output is correct
4 Correct 84 ms 7268 KB Output is correct
5 Correct 92 ms 7308 KB Output is correct
6 Correct 88 ms 7364 KB Output is correct
7 Correct 90 ms 7296 KB Output is correct
8 Correct 88 ms 7316 KB Output is correct
9 Correct 86 ms 6736 KB Output is correct
10 Correct 88 ms 7324 KB Output is correct
11 Correct 81 ms 7292 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 89 ms 7320 KB Output is correct
32 Correct 87 ms 7308 KB Output is correct
33 Correct 90 ms 7356 KB Output is correct
34 Correct 84 ms 7268 KB Output is correct
35 Correct 92 ms 7308 KB Output is correct
36 Correct 88 ms 7364 KB Output is correct
37 Correct 90 ms 7296 KB Output is correct
38 Correct 88 ms 7316 KB Output is correct
39 Correct 86 ms 6736 KB Output is correct
40 Correct 88 ms 7324 KB Output is correct
41 Correct 81 ms 7292 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 87 ms 7344 KB Output is correct
44 Correct 147 ms 6316 KB Output is correct
45 Correct 92 ms 6704 KB Output is correct
46 Correct 85 ms 7308 KB Output is correct
47 Correct 125 ms 6276 KB Output is correct
48 Correct 85 ms 6724 KB Output is correct
49 Correct 89 ms 7372 KB Output is correct
50 Correct 123 ms 6380 KB Output is correct
51 Correct 89 ms 6780 KB Output is correct
52 Correct 85 ms 7364 KB Output is correct
53 Correct 122 ms 6376 KB Output is correct
54 Correct 91 ms 6780 KB Output is correct
55 Correct 88 ms 7356 KB Output is correct
56 Correct 79 ms 7364 KB Output is correct
57 Correct 81 ms 7300 KB Output is correct
58 Correct 1 ms 320 KB Output is correct