/// adil sultanov | vonat1us
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 510;
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int a[N], b[N], len[N];
vector<int> dp[N];
void ma1n() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
len[i] = b[i]-a[i]+1;
}
if (n == 1) {
cout << b[1]-a[1]+1, exit(0);
}
dp[0].resize(1);
for (int i = 1; i <= n; ++i) {
dp[i].resize(len[i]+1);
dp[i][0] = add(dp[i-1][0], dp[i-1][len[i-1]]);
for (int x = a[i]; x <= b[i]; ++x) {
for (int j = 1; j < i; ++j) {
int r = min(b[j], x-1);
if (a[j] <= r) {
dp[i][x-a[i]+1] = add(dp[i][x-a[i]+1], dp[j][r-a[j]+1]);
}
}
}
for (int x = 1; x <= len[i]; ++x) {
if (x+1 <= len[i]) dp[i][x+1] = add(dp[i][x+1], dp[i][x]);
dp[i][x] = add(dp[i][x], x);
}
}
cout << add(dp[n][0], dp[n][len[n]]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
906 ms |
3796 KB |
Output is correct |
22 |
Correct |
834 ms |
3812 KB |
Output is correct |
23 |
Correct |
795 ms |
3576 KB |
Output is correct |
24 |
Correct |
862 ms |
3968 KB |
Output is correct |
25 |
Correct |
871 ms |
3820 KB |
Output is correct |
26 |
Correct |
1185 ms |
4108 KB |
Output is correct |
27 |
Correct |
1244 ms |
4276 KB |
Output is correct |
28 |
Correct |
1211 ms |
4132 KB |
Output is correct |
29 |
Correct |
1223 ms |
4288 KB |
Output is correct |
30 |
Correct |
1625 ms |
4228 KB |
Output is correct |
31 |
Correct |
1618 ms |
4188 KB |
Output is correct |
32 |
Correct |
1603 ms |
4168 KB |
Output is correct |
33 |
Correct |
1558 ms |
4264 KB |
Output is correct |
34 |
Correct |
1572 ms |
4316 KB |
Output is correct |
35 |
Correct |
786 ms |
3880 KB |
Output is correct |
36 |
Correct |
952 ms |
4000 KB |
Output is correct |
37 |
Correct |
917 ms |
4120 KB |
Output is correct |
38 |
Correct |
1020 ms |
3980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
239 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
906 ms |
3796 KB |
Output is correct |
22 |
Correct |
834 ms |
3812 KB |
Output is correct |
23 |
Correct |
795 ms |
3576 KB |
Output is correct |
24 |
Correct |
862 ms |
3968 KB |
Output is correct |
25 |
Correct |
871 ms |
3820 KB |
Output is correct |
26 |
Correct |
1185 ms |
4108 KB |
Output is correct |
27 |
Correct |
1244 ms |
4276 KB |
Output is correct |
28 |
Correct |
1211 ms |
4132 KB |
Output is correct |
29 |
Correct |
1223 ms |
4288 KB |
Output is correct |
30 |
Correct |
1625 ms |
4228 KB |
Output is correct |
31 |
Correct |
1618 ms |
4188 KB |
Output is correct |
32 |
Correct |
1603 ms |
4168 KB |
Output is correct |
33 |
Correct |
1558 ms |
4264 KB |
Output is correct |
34 |
Correct |
1572 ms |
4316 KB |
Output is correct |
35 |
Correct |
786 ms |
3880 KB |
Output is correct |
36 |
Correct |
952 ms |
4000 KB |
Output is correct |
37 |
Correct |
917 ms |
4120 KB |
Output is correct |
38 |
Correct |
1020 ms |
3980 KB |
Output is correct |
39 |
Runtime error |
239 ms |
524292 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |