Submission #508835

#TimeUsernameProblemLanguageResultExecution timeMemory
508835rainboy별자리 (JOI12_constellation)C11
100 / 100
53 ms4008 KiB
/* https://ioi.te.lv/locations/ioi06/contest/day2/points/points_sol.pdf */ #include <stdio.h> #define N 100000 #define MD 1000000007 unsigned int X = 12345; 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; } } long long solve(int *ii, int n, int c) { int i, j, l, l_, r, r_; long long ans; l_ = 0; while (l_ < n && cc[ii[l_]] != c) l_++; r_ = n - 1; while (r_ >= 0 && cc[ii[r_]] != c) r_--; if (l_ == 0) return 0; if (l_ == n) { ans = 1; for (i = 0, j = 1; j <= n; j++) if (j == n || cc[ii[j]] == (c ^ 1)) { ans += (long long) (j - i) * (j - i - 1) / 2; i = j; } return ans; } else { for (i = l_; i <= r_; i++) if (cc[ii[i]] == (c ^ 1)) return 0; l = l_; while (l > 0 && cc[ii[l]] != (c ^ 1)) l--; r = r_; while (r < n && cc[ii[r]] != (c ^ 1)) r++; return (long long) (l_ - l) * (r - r_); } } int main() { static int ii[N]; static char hull[N]; int n, cnt, h, i, ans; 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]; } for (h = 0; h < cnt; h++) hull[ii[h]] = 1; ans = (solve(ii, cnt, 0) + solve(ii, cnt, 1)) % MD; for (i = 0; i < n; i++) if (!hull[i] && cc[i] == -1) ans = ans * 2 % MD; ans = (ans - 2 + MD) % MD; for (i = 0; i < n; i++) if (cc[i] == 1) { ans = (ans + 1) % MD; break; } for (i = 0; i < n; i++) if (cc[i] == 0) { ans = (ans + 1) % MD; break; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

constellation.c: In function 'main':
constellation.c:84:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   84 |   if (o == -1 || xx[o] > xx[i] || xx[o] == xx[i] && yy[o] > yy[i])
      |                                   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
constellation.c:80:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
constellation.c:83:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |   scanf("%d%d%d", &xx[i], &yy[i], &cc[i]), cc[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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...