#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e3 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 7;
int n, a[MAXN], b[MAXN];
vector<int> num;
void Input()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
num.pb(a[i]);
num.pb(b[i] + 1);
}
}
int l[MAXN];
int dp[MAXN][MAXN];
void add(int& a, int b)
{
a += b;
if (a > MOD)
a -= MOD;
}
int comb[MAXN][MAXN];
void Solve()
{
comb[0][0] = 1;
for (int i = 1; i < MAXN; i++)
{
comb[i][0] = comb[i][i] = 1;
for (int j = 1; j < i; j++)
add(comb[i][j], (comb[i - 1][j], comb[i - 1][j - 1]) % MOD);
}
sort(num.begin(), num.end());
num.erase(unique(num.begin(), num.end()), num.end());
for (int i = 1; i < num.size(); i++)
{
l[i] = num[i] - num[i - 1];
}
for (int i = 1; i <= n; i++)
{
a[i] = upper_bound(num.begin(), num.end(), a[i]) - num.begin();
b[i] = upper_bound(num.begin(), num.end(), b[i]) - num.begin();
}
for (int i = 0; i < num.size(); i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++)
{
dp[i][0] = 1;
for (int j = a[i]; j <= b[i]; j++)
{
dp[i][j] = (1ll * dp[i - 1][j - 1] * l[j]) % MOD;
int cnt = 1;
for (int k = i - 1; k; k--)
{
if (a[k] <= j && j <= b[k])
{
cnt++;
add(dp[i][j], 1ll * dp[k - 1][j - 1] * comb[cnt + l[j] - 2][cnt] % MOD);
}
}
}
for (int j = 1; j < num.size(); j++)
{
add(dp[i][j], (1ll * dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD);
}
}
cout << (dp[n][(int)num.size() - 1] - 1 + MOD) % MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
Compilation message
boat.cpp: In function 'void Solve()':
boat.cpp:46:43: warning: left operand of comma operator has no effect [-Wunused-value]
46 | add(comb[i][j], (comb[i - 1][j], comb[i - 1][j - 1]) % MOD);
| ~~~~~~~~~~~~~^
boat.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 1; i < num.size(); i++)
| ~~^~~~~~~~~~~~
boat.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < num.size(); i++)
| ~~^~~~~~~~~~~~
boat.cpp:77:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (int j = 1; j < num.size(); j++)
| ~~^~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6228 KB |
Output is correct |
2 |
Correct |
9 ms |
6228 KB |
Output is correct |
3 |
Correct |
10 ms |
6252 KB |
Output is correct |
4 |
Correct |
11 ms |
6228 KB |
Output is correct |
5 |
Correct |
9 ms |
6208 KB |
Output is correct |
6 |
Correct |
9 ms |
6224 KB |
Output is correct |
7 |
Correct |
8 ms |
6228 KB |
Output is correct |
8 |
Correct |
9 ms |
6208 KB |
Output is correct |
9 |
Correct |
8 ms |
6228 KB |
Output is correct |
10 |
Correct |
8 ms |
6164 KB |
Output is correct |
11 |
Correct |
8 ms |
6228 KB |
Output is correct |
12 |
Correct |
8 ms |
6268 KB |
Output is correct |
13 |
Correct |
8 ms |
6228 KB |
Output is correct |
14 |
Correct |
8 ms |
6228 KB |
Output is correct |
15 |
Correct |
8 ms |
6228 KB |
Output is correct |
16 |
Correct |
5 ms |
6228 KB |
Output is correct |
17 |
Correct |
5 ms |
6228 KB |
Output is correct |
18 |
Correct |
6 ms |
6228 KB |
Output is correct |
19 |
Correct |
6 ms |
6228 KB |
Output is correct |
20 |
Correct |
7 ms |
6244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6228 KB |
Output is correct |
2 |
Correct |
9 ms |
6228 KB |
Output is correct |
3 |
Correct |
10 ms |
6252 KB |
Output is correct |
4 |
Correct |
11 ms |
6228 KB |
Output is correct |
5 |
Correct |
9 ms |
6208 KB |
Output is correct |
6 |
Correct |
9 ms |
6224 KB |
Output is correct |
7 |
Correct |
8 ms |
6228 KB |
Output is correct |
8 |
Correct |
9 ms |
6208 KB |
Output is correct |
9 |
Correct |
8 ms |
6228 KB |
Output is correct |
10 |
Correct |
8 ms |
6164 KB |
Output is correct |
11 |
Correct |
8 ms |
6228 KB |
Output is correct |
12 |
Correct |
8 ms |
6268 KB |
Output is correct |
13 |
Correct |
8 ms |
6228 KB |
Output is correct |
14 |
Correct |
8 ms |
6228 KB |
Output is correct |
15 |
Correct |
8 ms |
6228 KB |
Output is correct |
16 |
Correct |
5 ms |
6228 KB |
Output is correct |
17 |
Correct |
5 ms |
6228 KB |
Output is correct |
18 |
Correct |
6 ms |
6228 KB |
Output is correct |
19 |
Correct |
6 ms |
6228 KB |
Output is correct |
20 |
Correct |
7 ms |
6244 KB |
Output is correct |
21 |
Incorrect |
122 ms |
6152 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
8520 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6228 KB |
Output is correct |
2 |
Correct |
9 ms |
6228 KB |
Output is correct |
3 |
Correct |
10 ms |
6252 KB |
Output is correct |
4 |
Correct |
11 ms |
6228 KB |
Output is correct |
5 |
Correct |
9 ms |
6208 KB |
Output is correct |
6 |
Correct |
9 ms |
6224 KB |
Output is correct |
7 |
Correct |
8 ms |
6228 KB |
Output is correct |
8 |
Correct |
9 ms |
6208 KB |
Output is correct |
9 |
Correct |
8 ms |
6228 KB |
Output is correct |
10 |
Correct |
8 ms |
6164 KB |
Output is correct |
11 |
Correct |
8 ms |
6228 KB |
Output is correct |
12 |
Correct |
8 ms |
6268 KB |
Output is correct |
13 |
Correct |
8 ms |
6228 KB |
Output is correct |
14 |
Correct |
8 ms |
6228 KB |
Output is correct |
15 |
Correct |
8 ms |
6228 KB |
Output is correct |
16 |
Correct |
5 ms |
6228 KB |
Output is correct |
17 |
Correct |
5 ms |
6228 KB |
Output is correct |
18 |
Correct |
6 ms |
6228 KB |
Output is correct |
19 |
Correct |
6 ms |
6228 KB |
Output is correct |
20 |
Correct |
7 ms |
6244 KB |
Output is correct |
21 |
Incorrect |
122 ms |
6152 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |