이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 500
#define MD 1000000007
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int vv[N + 1];
void init() {
int i;
for (i = 1; i <= N; i++)
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % 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;
}
}
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, c;
k = 0, c = 1;
for (i = j - 1; i >= 0; i--) {
if (xx[i << 1 | 0] <= h && h < xx[i << 1 | 1])
k++, c = (long long) c * (x - 1 + k) % MD * vv[k] % MD;
dp[j] = (dp[j] + (long long) dp[i] * c) % MD;
}
}
}
ans = 0;
for (i = 1; i <= n; i++)
ans = (ans + dp[i]) % MD;
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
boat.c: In function 'main':
boat.c:63:14: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
63 | if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
| ~~^~~
boat.c:63:45: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
63 | if (xx[j - 1 << 1 | 0] <= h && h < xx[j - 1 << 1 | 1]) {
| ~~^~~
boat.c:47:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
47 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
boat.c:49:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
49 | scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |