#include "park.h"
#include <string.h>
const int N = 1400;
int t, n;
int query(int *used, int a, int b) {
int tmp;
if (a > b)
tmp = a, a = b, b = tmp;
return Ask(a, b, used);
}
void answer(int a, int b) {
int tmp;
if (a > b)
tmp = a, a = b, b = tmp;
Answer(a, b);
}
int compare(int a, int b) {
if (a == b)
return 0;
if (a == 0)
return -1;
if (b == 0)
return 1;
int used[N];
for (int i = 0; i < n; i++)
used[i] = i != a;
return query(used, 0, b) ? 1 : -1;
}
void merge(int *ii, int n1, int n2) {
static int ii_[N];
int i1 = 0, i2 = 0, i = 0;
while (i1 < n1 || i2 < n2)
ii_[i++] = i2 == n2 || i1 < n1 && compare(ii[i1], ii[n1 + i2]) < 0 ? ii[i1++] : ii[n1 + i2++];
memcpy(ii, ii_, (n1 + n2) * sizeof *ii_);
}
void mergesort(int *ii, int n) {
if (n == 1)
return;
int m = (n + 1) / 2;
mergesort(ii, m), mergesort(ii + m, n - m);
merge(ii, m, n - m);
}
void Detect(int t_, int n_) {
t = t_, n = n_;
if (t == 1) {
static int used[N];
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
for (int k = 0; k < n; k++)
used[k] = k == i || k == j ? 1 : 0;
if (query(used, i, j))
answer(i, j);
}
} else if (t == 2) {
static int ii[N];
for (int i = 0; i < n; i++)
ii[i] = i;
mergesort(ii, n);
for (int h = 1; h < n; h++)
answer(ii[h - 1], ii[h]);
}
}
Compilation message
park.cpp: In function 'void merge(int*, int, int)':
park.cpp:39:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
39 | ii_[i++] = i2 == n2 || i1 < n1 && compare(ii[i1], ii[n1 + i2]) < 0 ? ii[i1++] : ii[n1 + i2++];
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
284 KB |
Output is correct |
3 |
Correct |
13 ms |
212 KB |
Output is correct |
4 |
Correct |
13 ms |
292 KB |
Output is correct |
5 |
Correct |
13 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
468 KB |
Output is correct |
2 |
Correct |
43 ms |
444 KB |
Output is correct |
3 |
Correct |
47 ms |
452 KB |
Output is correct |
4 |
Correct |
152 ms |
468 KB |
Output is correct |
5 |
Correct |
153 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |