#include<stdio.h>
#include<algorithm>
using namespace std;
int n, m, R;
int w[251][2];
long long R1, R2, Mod = 1000000007, D[2][251][251];
void Do(int x){
int i, j, k;
for (i = 0; i <= n; i++){
for (j = 0; j < R; j++){
D[0][i][j] = D[1][i][j] = 0;
}
}
D[0][0][0] = 1;
for (i = 1; i <= n; i++){
for (j = 0; j < R; j++){
if (w[i][0] <= x && x <= w[i][1] && j != R-1){
D[1][i][j + 1] = (D[1][i][j + 1] + D[0][i - 1][j] + D[1][i - 1][j]) % Mod;
}
for (k = 0; k < 2; k++){
if (w[i][0] < x){
D[k][i][j] = (D[k][i][j] + D[k][i - 1][j] * (min(x - 1, w[i][1]) - w[i][0] + 1)) % Mod;
}
if (w[i][1] > x && j != R - 1){
D[k][i][j + 1] = (D[k][i][j + 1] + D[k][i - 1][j] * (w[i][1] - max(w[i][0], x + 1) + 1)) % Mod;
}
}
}
}
R2 = (R2 + D[1][n][R - 1]) % Mod;
}
int main()
{
int i;
scanf("%d%d", &n, &m);
R1 = 1;
for (i = 1; i <= n; i++){
scanf("%d%d", &w[i][0], &w[i][1]);
R1 = R1*(w[i][1] - w[i][0] + 1) % Mod;
}
scanf("%d", &R);
if (R == 1){
printf("0\n");
return 0;
}
for (i = 0; i <= m; i++){
Do(i);
}
printf("%lld\n", (R1 - R2 + Mod) % Mod);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2072 KB |
Output is correct |
2 |
Correct |
0 ms |
2072 KB |
Output is correct |
3 |
Correct |
0 ms |
2072 KB |
Output is correct |
4 |
Correct |
0 ms |
2072 KB |
Output is correct |
5 |
Correct |
0 ms |
2072 KB |
Output is correct |
6 |
Correct |
0 ms |
2072 KB |
Output is correct |
7 |
Correct |
0 ms |
2072 KB |
Output is correct |
8 |
Correct |
0 ms |
2072 KB |
Output is correct |
9 |
Correct |
0 ms |
2072 KB |
Output is correct |
10 |
Correct |
0 ms |
2072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2072 KB |
Output is correct |
2 |
Correct |
0 ms |
2072 KB |
Output is correct |
3 |
Correct |
0 ms |
2072 KB |
Output is correct |
4 |
Correct |
0 ms |
2072 KB |
Output is correct |
5 |
Correct |
0 ms |
2072 KB |
Output is correct |
6 |
Correct |
0 ms |
2072 KB |
Output is correct |
7 |
Correct |
0 ms |
2072 KB |
Output is correct |
8 |
Correct |
0 ms |
2072 KB |
Output is correct |
9 |
Correct |
0 ms |
2072 KB |
Output is correct |
10 |
Correct |
0 ms |
2072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2072 KB |
Output is correct |
2 |
Correct |
0 ms |
2072 KB |
Output is correct |
3 |
Correct |
0 ms |
2072 KB |
Output is correct |
4 |
Correct |
0 ms |
2072 KB |
Output is correct |
5 |
Correct |
0 ms |
2072 KB |
Output is correct |
6 |
Correct |
4 ms |
2072 KB |
Output is correct |
7 |
Correct |
4 ms |
2072 KB |
Output is correct |
8 |
Correct |
4 ms |
2072 KB |
Output is correct |
9 |
Correct |
0 ms |
2072 KB |
Output is correct |
10 |
Correct |
0 ms |
2072 KB |
Output is correct |
11 |
Correct |
8 ms |
2072 KB |
Output is correct |
12 |
Correct |
4 ms |
2072 KB |
Output is correct |
13 |
Correct |
4 ms |
2072 KB |
Output is correct |
14 |
Correct |
4 ms |
2072 KB |
Output is correct |
15 |
Correct |
4 ms |
2072 KB |
Output is correct |
16 |
Correct |
8 ms |
2072 KB |
Output is correct |
17 |
Correct |
8 ms |
2072 KB |
Output is correct |
18 |
Correct |
8 ms |
2072 KB |
Output is correct |
19 |
Correct |
8 ms |
2072 KB |
Output is correct |
20 |
Correct |
8 ms |
2072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2072 KB |
Output is correct |
2 |
Correct |
8 ms |
2072 KB |
Output is correct |
3 |
Correct |
0 ms |
2072 KB |
Output is correct |
4 |
Correct |
24 ms |
2072 KB |
Output is correct |
5 |
Correct |
64 ms |
2072 KB |
Output is correct |
6 |
Correct |
72 ms |
2072 KB |
Output is correct |
7 |
Correct |
60 ms |
2072 KB |
Output is correct |
8 |
Correct |
248 ms |
2072 KB |
Output is correct |
9 |
Correct |
0 ms |
2072 KB |
Output is correct |
10 |
Correct |
148 ms |
2072 KB |
Output is correct |
11 |
Correct |
116 ms |
2072 KB |
Output is correct |
12 |
Correct |
36 ms |
2072 KB |
Output is correct |
13 |
Correct |
316 ms |
2072 KB |
Output is correct |
14 |
Correct |
84 ms |
2072 KB |
Output is correct |
15 |
Correct |
368 ms |
2072 KB |
Output is correct |
16 |
Correct |
524 ms |
2072 KB |
Output is correct |
17 |
Correct |
560 ms |
2072 KB |
Output is correct |
18 |
Correct |
12 ms |
2072 KB |
Output is correct |
19 |
Correct |
1180 ms |
2072 KB |
Output is correct |
20 |
Execution timed out |
1500 ms |
2072 KB |
Program timed out |