#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
#define SZ(x) ((int)x.size())
const int mod = (int)1e9+7;
int fast_pw(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b >>= 1;
}
return res;
}
const int N = 505;
int n, f[N], g[N], ftmp[N], a[N], b[N], tmp[N], m;
int choose[N][N], len[N], lenCk[N][N], c1[N];
vector<int> c;
void add(int &x, int y) {
x += y, x %= mod;
if (x < 0) x += mod;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
++b[i];
c.push_back(a[i]);
c.push_back(b[i]);
}
sort(c.begin(), c.end());
c.resize(distance(c.begin(), unique(c.begin(), c.end())));
int sz = 0;
for (int i = 0; i < SZ(c) - 1; ++i) {
len[++sz] = c[i + 1] - c[i];
lenCk[sz][0] = 1;
for (int j = 1; j <= min(len[sz], n); ++j) {
lenCk[sz][j] = 1ll * lenCk[sz][j - 1] * (len[sz] - j + 1) % mod;
lenCk[sz][j] = 1ll * lenCk[sz][j] * fast_pw(j, mod - 2) % mod;
}
}
for (int i = 0; i <= n; ++i) choose[i][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j)
choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % mod;
}
for (int i = 1; i <= sz; ++i) {
m = 0;
for (int j = 1; j <= n; ++j)
if (a[j] <= c[i - 1] && c[i] <= b[j])
tmp[++m] = j;
for (int j = 1; j <= m; ++j) {
int id = tmp[j];
if (j == 1) {
for (int k = 0; k <= m; ++k) c1[k] = 0;
c1[1] = len[i];
for (int k = 2; k <= m; ++k) {
int s = k - j + 1;
for (int x = 2; x <= min(s, len[i]); ++x)
c1[s] = (c1[s] + 1ll * lenCk[i][x] * choose[s - 2][x - 2]) % mod;
}
}
for (int k = j; k <= m; ++k) {
int mid = k - j + 1, id2 = tmp[k];
ftmp[id2] = (ftmp[id2] + 1ll * c1[mid] * (g[id - 1] + 1)) % mod;
}
}
for (int j = 1; j <= n; ++j) {
add(f[j], ftmp[j]);
g[j] = (g[j - 1] + f[j]) % mod;
ftmp[j] = 0;
}
}
printf("%d", g[n]);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:34:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
boat.cpp:36:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i], &b[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2424 KB |
Output is correct |
2 |
Correct |
7 ms |
2424 KB |
Output is correct |
3 |
Correct |
7 ms |
2424 KB |
Output is correct |
4 |
Correct |
8 ms |
2424 KB |
Output is correct |
5 |
Correct |
7 ms |
2424 KB |
Output is correct |
6 |
Correct |
9 ms |
2424 KB |
Output is correct |
7 |
Correct |
9 ms |
2424 KB |
Output is correct |
8 |
Correct |
9 ms |
2424 KB |
Output is correct |
9 |
Correct |
9 ms |
2424 KB |
Output is correct |
10 |
Correct |
9 ms |
2424 KB |
Output is correct |
11 |
Correct |
7 ms |
2424 KB |
Output is correct |
12 |
Correct |
7 ms |
2424 KB |
Output is correct |
13 |
Correct |
7 ms |
2424 KB |
Output is correct |
14 |
Correct |
9 ms |
2424 KB |
Output is correct |
15 |
Correct |
8 ms |
2424 KB |
Output is correct |
16 |
Correct |
4 ms |
2424 KB |
Output is correct |
17 |
Correct |
4 ms |
2424 KB |
Output is correct |
18 |
Correct |
4 ms |
2424 KB |
Output is correct |
19 |
Correct |
4 ms |
2424 KB |
Output is correct |
20 |
Correct |
4 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |