답안 #444741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444741 2021-07-15T03:22:29 Z penguinhacker Drvca (COCI19_drvca) C++14
110 / 110
146 ms 4040 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=2e5;
int n, a[mxN], prv[mxN], nxt[mxN], cnt;
vector<int> cur={0};
bool rem[mxN]={1}, bad[mxN];

void calc(int i) {
	if (i==-1)
		return;
	cnt-=bad[i];
	if (rem[i])
		bad[i]=0;
	else {
		if (prv[i]==-1||nxt[i]==-1)
			bad[i]=0;
		else {
			assert(!rem[prv[i]]&&!rem[nxt[i]]);
			bad[i]=a[i]-a[prv[i]]!=a[nxt[i]]-a[i];
		}
	}
	cnt+=bad[i];
}

void ck() {
	if (cnt)
		return;
	assert(cnt==0&&cur.size()&&n-cur.size()>0);
	vector<bool> other(n, 1);
	cout << cur.size() << "\n";
	for (int i : cur) {
		other[i]=0;
		cout << a[i] << " ";
	}
	cout << "\n" << n-cur.size() << "\n";
	for (int i=0; i<n; ++i)
		if (other[i])
			cout << a[i] << " ";
	exit(0);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0; i<n; ++i)
		cin >> a[i];
	sort(a, a+n);
	for (int i=1; i<n; ++i) {
		prv[i]=i-1;
		nxt[i]=i+1;
	}
	prv[1]=-1, nxt[n-1]=-1;
	for (int i=1; i<n; ++i)
		calc(i);
	ck();
	for (int i=1; i<n; ++i) {
		int d=a[i]-a[0];
		for (int j=i; j<n;) {
			assert(!rem[j]);
			cur.push_back(j);
			nxt[prv[j]]=nxt[j], prv[nxt[j]]=prv[j], rem[j]=1;
			calc(j), calc(prv[j]), calc(nxt[j]);
			ck();
			int p=lower_bound(a, a+n, a[j]+d)-a;
			p=max(j+1, p);
			if (p==n||a[p]!=a[j]+d)
				break;
			j=p;
		}
		while(cur.size()>1) {
			int j=cur.back();
			cur.pop_back();
			nxt[prv[j]]=j, prv[nxt[j]]=j, rem[j]=0;
			calc(j), calc(prv[j]), calc(nxt[j]);
		}
	}
	cout << -1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 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 332 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 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3036 KB Output is correct
2 Correct 36 ms 2896 KB Output is correct
3 Correct 36 ms 2952 KB Output is correct
4 Correct 36 ms 2960 KB Output is correct
5 Correct 37 ms 3036 KB Output is correct
6 Correct 37 ms 3940 KB Output is correct
7 Correct 43 ms 4000 KB Output is correct
8 Correct 45 ms 3952 KB Output is correct
9 Correct 34 ms 3328 KB Output is correct
10 Correct 37 ms 3920 KB Output is correct
11 Correct 26 ms 3568 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 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 332 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 332 KB Output is correct
31 Correct 38 ms 3036 KB Output is correct
32 Correct 36 ms 2896 KB Output is correct
33 Correct 36 ms 2952 KB Output is correct
34 Correct 36 ms 2960 KB Output is correct
35 Correct 37 ms 3036 KB Output is correct
36 Correct 37 ms 3940 KB Output is correct
37 Correct 43 ms 4000 KB Output is correct
38 Correct 45 ms 3952 KB Output is correct
39 Correct 34 ms 3328 KB Output is correct
40 Correct 37 ms 3920 KB Output is correct
41 Correct 26 ms 3568 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 45 ms 4040 KB Output is correct
44 Correct 124 ms 3040 KB Output is correct
45 Correct 31 ms 3140 KB Output is correct
46 Correct 37 ms 3920 KB Output is correct
47 Correct 131 ms 2992 KB Output is correct
48 Correct 40 ms 3168 KB Output is correct
49 Correct 39 ms 3996 KB Output is correct
50 Correct 146 ms 2888 KB Output is correct
51 Correct 33 ms 3240 KB Output is correct
52 Correct 37 ms 3980 KB Output is correct
53 Correct 100 ms 3000 KB Output is correct
54 Correct 36 ms 3192 KB Output is correct
55 Correct 38 ms 4000 KB Output is correct
56 Correct 32 ms 4024 KB Output is correct
57 Correct 28 ms 3488 KB Output is correct
58 Correct 1 ms 332 KB Output is correct