This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "robots.h"
int max(int a, int b) { return a > b ? a : b; }
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 putaway(int n, int m, int k, int xx[], int yy[], int ww[], int ss[]) {
int h, i, j, ans;
if (k == 2 && n + m == 2) {
static int can[2][2];
for (h = 0; h < k; h++)
for (i = 0; i < n + m; i++)
if ((i < n ? ww[h] < xx[i] : ss[h] < yy[i - n]))
can[h][i] = 1;
if (!can[0][0] && !can[0][1] || !can[1][0] && !can[1][1])
return -1;
if (can[0][0] && can[1][1] || can[0][1] && can[1][0])
return 1;
return 2;
} else if (m == 0) {
sort(xx, 0, n);
sort(ww, 0, k);
ans = 0;
for (i = 0, j = 0; i < n; i++) {
while (j < k && ww[j] < xx[i - 1])
j++;
if (i < n - 1)
ans = max(ans, (k - j + n - 2 - i) / (n - 1 - i));
}
return j != k ? -1 : ans;
} else
return 42;
}
Compilation message (stderr)
robots.c: In function 'putaway':
robots.c:40:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
40 | if (!can[0][0] && !can[0][1] || !can[1][0] && !can[1][1])
| ~~~~~~~~~~~^~~~~~~~~~~~~
robots.c:42:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
42 | if (can[0][0] && can[1][1] || can[0][1] && can[1][0])
| ~~~~~~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |