#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 515, Mod = 1e9 + 7;
int n, m, A[N], B[N], dp[N][N], I[N];
long long F[N][N];
pair < int , int > P[N];
vector < int > U;
inline void Add(int &a, int b)
{
a += b;
if (a >= Mod)
a -= Mod;
if (a < 0)
a += Mod;
}
inline int Power(int a, int b)
{
int ret = 1;
for (; b; b >>= 1, a = 1LL * a * a % Mod)
if (b & 1) ret = 1LL * ret * a % Mod;
return (ret);
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d%d", &A[i], &B[i]);
U.pb(A[i]); U.pb(B[i] + 1);
}
U.pb(0); U.pb(1);
sort(U.begin(), U.end());
U.resize(unique(U.begin(), U.end()) - U.begin());
for (int i = 0; i < (int)U.size() - 1; i++)
P[m ++] = {U[i], U[i + 1] - 1};
reverse(P, P + m);
for (int i = I[0] = 1; i < N; i++)
I[i] = I[i - 1] * 1LL * Power(i, Mod - 2) % Mod;
for (int i = 0; i < m; i++)
{
int len = P[i].second - P[i].first + 1;
for (int lev = 0; lev <= n; lev ++)
{
long long vl = 1;
for (int h = 1; h <= lev + 1; h ++)
vl = vl * (len + lev - h + 1) % Mod;
F[i][lev] = vl * I[lev + 1] % Mod;
}
}
for (int i = 0; i <= n; i++)
dp[m - 1][i] = 1;
for (int k = 1; k <= n; k ++)
{
int sum = 0;
for (int i = 1; i < m; i ++)
Add(sum, dp[i][0]);
for (int i = 0; i < m; i ++, Add(sum, - dp[i][0]))
if (A[k] <= P[i].first && P[i].second <= B[k])
for (int j = 0; j <= n; j ++)
dp[i][j] = (dp[i][j + 1] + F[i][j] * sum) % Mod;
}
int tot = 0;
for (int i = 0; i < m - 1; i++)
Add(tot, dp[i][0]);
return !printf("%d\n", tot);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:29:14: 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 |
Runtime error |
517 ms |
6764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
517 ms |
6764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1536 KB |
Output is correct |
2 |
Correct |
9 ms |
1536 KB |
Output is correct |
3 |
Correct |
12 ms |
1536 KB |
Output is correct |
4 |
Correct |
10 ms |
1536 KB |
Output is correct |
5 |
Correct |
10 ms |
1536 KB |
Output is correct |
6 |
Correct |
11 ms |
1536 KB |
Output is correct |
7 |
Correct |
11 ms |
1536 KB |
Output is correct |
8 |
Correct |
11 ms |
1536 KB |
Output is correct |
9 |
Correct |
11 ms |
1536 KB |
Output is correct |
10 |
Correct |
12 ms |
1536 KB |
Output is correct |
11 |
Correct |
10 ms |
1536 KB |
Output is correct |
12 |
Correct |
11 ms |
1572 KB |
Output is correct |
13 |
Correct |
10 ms |
1536 KB |
Output is correct |
14 |
Correct |
11 ms |
1536 KB |
Output is correct |
15 |
Correct |
13 ms |
1536 KB |
Output is correct |
16 |
Correct |
8 ms |
1024 KB |
Output is correct |
17 |
Correct |
6 ms |
1024 KB |
Output is correct |
18 |
Correct |
8 ms |
1024 KB |
Output is correct |
19 |
Correct |
7 ms |
1024 KB |
Output is correct |
20 |
Correct |
7 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
517 ms |
6764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |