Submission #444742

# Submission time Handle Problem Language Result Execution time Memory
444742 2021-07-15T03:22:59 Z penguinhacker Drvca (COCI19_drvca) C++14
110 / 110
135 ms 3152 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=1e5;
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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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 1 ms 332 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 1 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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 1 ms 332 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 1 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 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 0 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 0 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
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3012 KB Output is correct
2 Correct 37 ms 2892 KB Output is correct
3 Correct 37 ms 2996 KB Output is correct
4 Correct 36 ms 2884 KB Output is correct
5 Correct 37 ms 2900 KB Output is correct
6 Correct 35 ms 2884 KB Output is correct
7 Correct 37 ms 2888 KB Output is correct
8 Correct 36 ms 2940 KB Output is correct
9 Correct 36 ms 2608 KB Output is correct
10 Correct 38 ms 3012 KB Output is correct
11 Correct 25 ms 2556 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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 1 ms 332 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 1 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 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 0 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 0 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 3012 KB Output is correct
32 Correct 37 ms 2892 KB Output is correct
33 Correct 37 ms 2996 KB Output is correct
34 Correct 36 ms 2884 KB Output is correct
35 Correct 37 ms 2900 KB Output is correct
36 Correct 35 ms 2884 KB Output is correct
37 Correct 37 ms 2888 KB Output is correct
38 Correct 36 ms 2940 KB Output is correct
39 Correct 36 ms 2608 KB Output is correct
40 Correct 38 ms 3012 KB Output is correct
41 Correct 25 ms 2556 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 38 ms 2984 KB Output is correct
44 Correct 135 ms 2004 KB Output is correct
45 Correct 31 ms 2456 KB Output is correct
46 Correct 44 ms 2984 KB Output is correct
47 Correct 132 ms 1992 KB Output is correct
48 Correct 31 ms 2500 KB Output is correct
49 Correct 40 ms 3024 KB Output is correct
50 Correct 119 ms 1888 KB Output is correct
51 Correct 31 ms 2500 KB Output is correct
52 Correct 36 ms 2892 KB Output is correct
53 Correct 105 ms 2012 KB Output is correct
54 Correct 33 ms 2496 KB Output is correct
55 Correct 39 ms 3012 KB Output is correct
56 Correct 30 ms 3152 KB Output is correct
57 Correct 25 ms 2508 KB Output is correct
58 Correct 0 ms 204 KB Output is correct