# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
683968 |
2023-01-19T20:00:48 Z |
rainboy |
Park (JOI17_park) |
C |
|
0 ms |
0 KB |
#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.c: In function 'merge':
park.c:36:13: error: storage size of 'ii_' isn't constant
36 | static int ii_[N];
| ^~~
park.c: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++];
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.c:36:13: warning: unused variable 'ii_' [-Wunused-variable]
36 | static int ii_[N];
| ^~~
park.c: In function 'Detect':
park.c:54:14: error: storage size of 'used' isn't constant
54 | static int used[N];
| ^~~~
park.c:54:14: warning: unused variable 'used' [-Wunused-variable]
park.c:63:14: error: storage size of 'ii' isn't constant
63 | static int ii[N];
| ^~
park.c:63:14: warning: unused variable 'ii' [-Wunused-variable]