Submission #481178

#TimeUsernameProblemLanguageResultExecution timeMemory
481178rainboyDrvca (COCI19_drvca)C11
110 / 110
47 ms3060 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...