Submission #481178

# Submission time Handle Problem Language Result Execution time Memory
481178 2021-10-19T18:04:05 Z rainboy Drvca (COCI19_drvca) C
110 / 110
47 ms 3060 KB
#include <stdio.h>
#include <string.h>

#define N	100000

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

void sort(int *aa, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (aa[j] == a)
				j++;
			else if (aa[j] < a) {
				tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
			}
		sort(aa, l, i);
		l = k;
	}
}

int solve(int *aa, int n, int a, int b) {
	static char in[N];
	static int dd[N];
	int i, k, c, d;

	memset(in, 0, n * sizeof *in);
	for (i = n - 2; i >= 0; i--)
		dd[i] = i == n - 2 || dd[i + 1] == aa[i + 1] - aa[i] ? aa[i + 1] - aa[i] : -2;
	k = 0, c = -1, d = -1;
	for (i = 0; i < n; i++)
		if (aa[i] == a) {
			in[i] = 1, a += b, k++;
			if (k < n) {
				if (i == n - 2) {
					if (c != -1 && d != -1 && aa[i + 1] - c != d)
						continue;
				} else if (i < n - 2) {
					if (dd[i + 1] == -2)
						continue;
					if (d != -1 && d != dd[i + 1])
						continue;
					if (c != -1 && aa[i + 1] - c != dd[i + 1])
						continue;
				}
				printf("%d\n", k);
				for (i = 0; i < n; i++)
					if (in[i])
						printf("%d ", aa[i]);
				printf("\n");
				printf("%d\n", n - k);
				for (i = 0; i < n; i++)
					if (!in[i])
						printf("%d ", aa[i]);
				printf("\n");
				return 1;
			}
		} else {
			if (c != -1) {
				if (d != -1 && aa[i] - c != d)
					return 0;
				d = aa[i] - c;
			}
			c = aa[i];
		}
	return 0;
}

int main() {
	static int aa[N];
	int n, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	sort(aa, 0, n);
	if (!solve(aa, n, aa[0], aa[1] - aa[0]) && !solve(aa, n, aa[0], aa[2] - aa[0]) && !solve(aa, n, aa[1], aa[2] - aa[1])) {
		printf("-1\n");
		return 0;
	}
	return 0;
}

Compilation message

drvca.c: In function 'main':
drvca.c:82:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
drvca.c:84:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 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 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 276 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2060 KB Output is correct
2 Correct 37 ms 2116 KB Output is correct
3 Correct 37 ms 2116 KB Output is correct
4 Correct 47 ms 2120 KB Output is correct
5 Correct 37 ms 2064 KB Output is correct
6 Correct 34 ms 2064 KB Output is correct
7 Correct 47 ms 2060 KB Output is correct
8 Correct 39 ms 2116 KB Output is correct
9 Correct 35 ms 1812 KB Output is correct
10 Correct 33 ms 2064 KB Output is correct
11 Correct 24 ms 2124 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 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 276 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 37 ms 2060 KB Output is correct
32 Correct 37 ms 2116 KB Output is correct
33 Correct 37 ms 2116 KB Output is correct
34 Correct 47 ms 2120 KB Output is correct
35 Correct 37 ms 2064 KB Output is correct
36 Correct 34 ms 2064 KB Output is correct
37 Correct 47 ms 2060 KB Output is correct
38 Correct 39 ms 2116 KB Output is correct
39 Correct 35 ms 1812 KB Output is correct
40 Correct 33 ms 2064 KB Output is correct
41 Correct 24 ms 2124 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 37 ms 2116 KB Output is correct
44 Correct 28 ms 2028 KB Output is correct
45 Correct 33 ms 2500 KB Output is correct
46 Correct 35 ms 3052 KB Output is correct
47 Correct 29 ms 2040 KB Output is correct
48 Correct 35 ms 2500 KB Output is correct
49 Correct 36 ms 3048 KB Output is correct
50 Correct 27 ms 2116 KB Output is correct
51 Correct 46 ms 2520 KB Output is correct
52 Correct 35 ms 3060 KB Output is correct
53 Correct 29 ms 2116 KB Output is correct
54 Correct 35 ms 2500 KB Output is correct
55 Correct 38 ms 3012 KB Output is correct
56 Correct 25 ms 3020 KB Output is correct
57 Correct 23 ms 3056 KB Output is correct
58 Correct 0 ms 204 KB Output is correct