Submission #378435

#TimeUsernameProblemLanguageResultExecution timeMemory
378435rainboyBoat (APIO16_boat)C11
9 / 100
511 ms512 KiB
#include <stdio.h> #define N 500 #define MD 1000000007 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int vv[N + 1], ff[N + 1], gg[N + 1]; void init() { int i; ff[0] = gg[0] = 1; for (i = 1; i <= N; i++) { vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD; ff[i] = (long long) ff[i - 1] * i % MD; gg[i] = (long long) gg[i - 1] * vv[i] % MD; } } int xx[N * 2]; 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) if (xx[ii[j]] == xx[i_]) j++; else if (xx[ii[j]] < xx[i_]) { 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 choose(int n, int k) { return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD; } int main() { static int ii[N * 2], xx_[N * 2], dp[N + 1]; int n, h, i, j, ans; init(); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]); xx[i << 1 | 1]++; } for (i = 0; i < n * 2; i++) ii[i] = i; sort(ii, 0, n * 2); for (i = 0; i < n * 2; i++) xx_[i] = xx[ii[i]], xx[ii[i]] = i; dp[0] = 1; for (h = 0; h + 1 < n * 2; h++) { int x = xx_[h + 1] - xx_[h]; if (x > 0) for (j = n; j > 0; j--) if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) { int k; k = 0; for (i = j - 1; i >= 0; i--) { if (xx[i << 1 | 0] <= h && h < xx[i << 1 | 1]) k++; dp[j] = (dp[j] + dp[i] * choose(k + x - 1, x - 1)) % MD; } } } ans = 0; for (i = 1; i <= n; i++) ans = (ans + dp[i]) % MD; printf("%d\n", ans); return 0; }

Compilation message (stderr)

boat.c: In function 'main':
boat.c:71:13: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   71 |    if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
      |           ~~^~~
boat.c:71:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   71 |    if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
      |                                          ~~^~~
boat.c:55:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   55 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
boat.c:57:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   57 |   scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...