#include<bits/stdc++.h>
#define M 1000000007
#define maxn 502
using namespace std;
typedef long long ll;
ll norm(ll a) {
return (a < 0 ? a + M : (a >= M ? a - M : a));
}
ll mul(ll a, ll b) {
return a * b % M;
}
ll power(ll a, ll b) {
if (b == 0) return 1;
if (b&1) return mul(power(a, b - 1), a);
ll t = power(a, b / 2);
return mul(t, t);
}
ll gt[maxn], igt[maxn];
void precalc(){
int n = 500;
gt[0] = 1;
for (int i = 1; i <= n; ++i)
gt[i] = mul(gt[i - 1], i);
igt[n] = power(gt[n], M - 2);
for (int i = n - 1; i >= 0; --i)
igt[i] = mul(igt[i + 1], i + 1);
}
ll C(int n, int k) {
return mul(mul(gt[n], igt[k]), igt[n - k]);
}
int n;
int l[maxn], r[maxn];
vector < pair < int, int > > seg;
vector < vector < int > > a;
vector < int > leng;
ll dp[maxn * 3][maxn];
int main(){
#define TASK "ABC"
//freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
ios_base::sync_with_stdio(0);
precalc();
cin >> n;
vector < int > ret;
for (int i = 1; i <= n; ++i) {
cin >> l[i] >> r[i];
ret.push_back(l[i]);
ret.push_back(r[i]);
}
sort(ret.begin(), ret.end());
seg.push_back({ret[0], ret[0]});
for (int i = 1; i < ret.size(); ++i)
if (ret[i] != ret[i - 1]) {
if (ret[i - 1] + 1 != ret[i])
seg.push_back({ret[i - 1] + 1, ret[i] - 1});
seg.push_back({ret[i], ret[i]});
}
a = vector < vector < int > >(seg.size(), vector < int >(0, 0));
leng = vector < int > (seg.size(), 0);
for (int i = 0; i < seg.size(); ++i) {
for (int j = 1; j <= n; ++j)
if (l[j] <= seg[i].first && seg[i].second <= r[j])
a[i].push_back(j);
leng[i] = seg[i].second - seg[i].first + 1;
}
ll ans = 0;
for (int i = 0; i < seg.size(); ++i) {
ll l = leng[i];
vector < ll > c(a[i].size() + 1, 0), val(a[i].size() + 1, 0);
c[0] = 1;
for (int k = 1; k <= a[i].size(); ++k) {
if (k <= l)
c[k] = mul(mul(c[k - 1], l - k + 1), power(k, M - 2));
for (int x = k; x > 0; --x)
if (x <= l)
val[k] = norm(val[k] + mul(c[x], C(k - 1, x - 1)));
}
for (int k = 0; k <= n; ++k) {
ll res = (k == 0 ? 1 : 0);
for (int j = 0; j < i; ++j)
res = norm(res + dp[j][k]);
int cnt = 0;
for (auto j : a[i])
if (j > k) {
cnt++;
dp[i][j] = norm(dp[i][j] + mul(res, val[cnt]));
}
ans = norm(ans + dp[i][k]);
}
}
cout << ans;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:75:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < ret.size(); ++i)
~~^~~~~~~~~~~~
boat.cpp:85:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < seg.size(); ++i) {
~~^~~~~~~~~~~~
boat.cpp:94:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < seg.size(); ++i) {
~~^~~~~~~~~~~~
boat.cpp:101:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 1; k <= a[i].size(); ++k) {
~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
2424 KB |
Output is correct |
2 |
Correct |
434 ms |
2552 KB |
Output is correct |
3 |
Correct |
439 ms |
2424 KB |
Output is correct |
4 |
Correct |
439 ms |
2360 KB |
Output is correct |
5 |
Correct |
436 ms |
2424 KB |
Output is correct |
6 |
Correct |
433 ms |
2552 KB |
Output is correct |
7 |
Correct |
429 ms |
2552 KB |
Output is correct |
8 |
Correct |
428 ms |
2468 KB |
Output is correct |
9 |
Correct |
429 ms |
2424 KB |
Output is correct |
10 |
Correct |
429 ms |
2424 KB |
Output is correct |
11 |
Correct |
430 ms |
2424 KB |
Output is correct |
12 |
Correct |
442 ms |
2424 KB |
Output is correct |
13 |
Correct |
438 ms |
2412 KB |
Output is correct |
14 |
Correct |
429 ms |
2552 KB |
Output is correct |
15 |
Correct |
434 ms |
2412 KB |
Output is correct |
16 |
Correct |
20 ms |
896 KB |
Output is correct |
17 |
Correct |
21 ms |
896 KB |
Output is correct |
18 |
Correct |
20 ms |
896 KB |
Output is correct |
19 |
Correct |
22 ms |
896 KB |
Output is correct |
20 |
Correct |
20 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
2424 KB |
Output is correct |
2 |
Correct |
434 ms |
2552 KB |
Output is correct |
3 |
Correct |
439 ms |
2424 KB |
Output is correct |
4 |
Correct |
439 ms |
2360 KB |
Output is correct |
5 |
Correct |
436 ms |
2424 KB |
Output is correct |
6 |
Correct |
433 ms |
2552 KB |
Output is correct |
7 |
Correct |
429 ms |
2552 KB |
Output is correct |
8 |
Correct |
428 ms |
2468 KB |
Output is correct |
9 |
Correct |
429 ms |
2424 KB |
Output is correct |
10 |
Correct |
429 ms |
2424 KB |
Output is correct |
11 |
Correct |
430 ms |
2424 KB |
Output is correct |
12 |
Correct |
442 ms |
2424 KB |
Output is correct |
13 |
Correct |
438 ms |
2412 KB |
Output is correct |
14 |
Correct |
429 ms |
2552 KB |
Output is correct |
15 |
Correct |
434 ms |
2412 KB |
Output is correct |
16 |
Correct |
20 ms |
896 KB |
Output is correct |
17 |
Correct |
21 ms |
896 KB |
Output is correct |
18 |
Correct |
20 ms |
896 KB |
Output is correct |
19 |
Correct |
22 ms |
896 KB |
Output is correct |
20 |
Correct |
20 ms |
1024 KB |
Output is correct |
21 |
Execution timed out |
2047 ms |
15932 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2048 KB |
Output is correct |
2 |
Correct |
26 ms |
2048 KB |
Output is correct |
3 |
Correct |
29 ms |
2040 KB |
Output is correct |
4 |
Correct |
26 ms |
2048 KB |
Output is correct |
5 |
Correct |
29 ms |
2048 KB |
Output is correct |
6 |
Correct |
31 ms |
2040 KB |
Output is correct |
7 |
Correct |
33 ms |
2048 KB |
Output is correct |
8 |
Correct |
31 ms |
2060 KB |
Output is correct |
9 |
Correct |
31 ms |
2040 KB |
Output is correct |
10 |
Correct |
31 ms |
2068 KB |
Output is correct |
11 |
Correct |
28 ms |
2040 KB |
Output is correct |
12 |
Correct |
25 ms |
2048 KB |
Output is correct |
13 |
Correct |
26 ms |
2040 KB |
Output is correct |
14 |
Correct |
26 ms |
2040 KB |
Output is correct |
15 |
Correct |
27 ms |
2048 KB |
Output is correct |
16 |
Correct |
11 ms |
1024 KB |
Output is correct |
17 |
Correct |
11 ms |
1024 KB |
Output is correct |
18 |
Correct |
11 ms |
1024 KB |
Output is correct |
19 |
Correct |
11 ms |
1024 KB |
Output is correct |
20 |
Correct |
12 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
2424 KB |
Output is correct |
2 |
Correct |
434 ms |
2552 KB |
Output is correct |
3 |
Correct |
439 ms |
2424 KB |
Output is correct |
4 |
Correct |
439 ms |
2360 KB |
Output is correct |
5 |
Correct |
436 ms |
2424 KB |
Output is correct |
6 |
Correct |
433 ms |
2552 KB |
Output is correct |
7 |
Correct |
429 ms |
2552 KB |
Output is correct |
8 |
Correct |
428 ms |
2468 KB |
Output is correct |
9 |
Correct |
429 ms |
2424 KB |
Output is correct |
10 |
Correct |
429 ms |
2424 KB |
Output is correct |
11 |
Correct |
430 ms |
2424 KB |
Output is correct |
12 |
Correct |
442 ms |
2424 KB |
Output is correct |
13 |
Correct |
438 ms |
2412 KB |
Output is correct |
14 |
Correct |
429 ms |
2552 KB |
Output is correct |
15 |
Correct |
434 ms |
2412 KB |
Output is correct |
16 |
Correct |
20 ms |
896 KB |
Output is correct |
17 |
Correct |
21 ms |
896 KB |
Output is correct |
18 |
Correct |
20 ms |
896 KB |
Output is correct |
19 |
Correct |
22 ms |
896 KB |
Output is correct |
20 |
Correct |
20 ms |
1024 KB |
Output is correct |
21 |
Execution timed out |
2047 ms |
15932 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |