/* https://ioi.te.lv/locations/ioi06/contest/day2/points/points_sol.pdf */
#include <stdio.h>
#define N 10
unsigned int X;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N], yy[N], cc[N], o;
long long cross(int i, int j, int k) {
return (long long) (xx[j] - xx[i]) * (yy[k] - yy[i]) - (long long) (xx[k] - xx[i]) * (yy[j] - yy[i]);
}
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
long long c = cross(o, ii[j], i_);
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int ii[N];
int n, cnt, h, i, b, ans, comp;
scanf("%d", &n);
o = -1;
for (i = 0; i < n; i++) {
scanf("%d%d%d", &xx[i], &yy[i], &cc[i]), cc[i]--;
if (o == -1 || xx[o] > xx[i] || xx[o] == xx[i] && yy[o] > yy[i])
o = i;
ii[i] = i;
}
ii[0] = o, ii[o] = 0;
sort(ii, 1, n);
cnt = 0;
for (i = 0; i < n; i++) {
while (cnt >= 2 && cross(ii[cnt - 2], ii[cnt - 1], ii[i]) >= 0)
cnt--;
ii[cnt++] = ii[i];
}
ans = 0;
for (b = 1; b < (1 << n) - 1; b++) {
int k;
comp = 1;
for (i = 0; i < n; i++)
if (cc[i] != -1 && cc[i] != (b >> i & 1)) {
comp = 0;
break;
}
if (!comp)
continue;
k = 0;
for (h = 0; h < cnt; h++)
if ((b >> ii[h] & 1) != (b >> ii[(h + 1) % cnt] & 1))
k++;
if (k <= 2)
ans++;
}
printf("%d\n", ans);
return 0;
}
Compilation message
constellation.c: In function 'main':
constellation.c:48:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
48 | if (o == -1 || xx[o] > xx[i] || xx[o] == xx[i] && yy[o] > yy[i])
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
constellation.c:44:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
constellation.c:47:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d%d", &xx[i], &yy[i], &cc[i]), cc[i]--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
276 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
284 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
284 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
268 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
272 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |