#include <bits/stdc++.h>
using namespace std;
const int mod = (int) 1e9 + 7;
const int N = 502;
int n, a[N], b[N];
long long dp[N][N];
map<int, int> mp;
long long sol(int i, int hi) {
if (i == n) {
return (hi > 0);
}
long long& ret = dp[i][mp[hi]];
if (ret != -1) {
return ret;
}
ret = sol(i + 1, hi);
for (int j = a[i]; j <= b[i]; j++) {
if (j > hi) {
ret += sol(i + 1, j);
ret %= mod;
}
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
memset(dp, -1, sizeof dp);
cin >> n;
vector<int> se;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
for (int j = a[i]; j <= b[i]; j++) {
se.push_back(j);
}
}
sort(se.begin(), se.end());
int idd = 1;
for (int i = 0; i < (int) se.size(); i++) {
if (i == 0 || se[i] != se[i - 1]) {
mp[se[i]] = idd++;
}
}
cout << sol(0, 0) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
7 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2372 KB |
Output is correct |
5 |
Correct |
7 ms |
2252 KB |
Output is correct |
6 |
Correct |
9 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2368 KB |
Output is correct |
9 |
Correct |
8 ms |
2372 KB |
Output is correct |
10 |
Correct |
7 ms |
2252 KB |
Output is correct |
11 |
Correct |
7 ms |
2368 KB |
Output is correct |
12 |
Correct |
7 ms |
2368 KB |
Output is correct |
13 |
Correct |
7 ms |
2252 KB |
Output is correct |
14 |
Correct |
8 ms |
2364 KB |
Output is correct |
15 |
Correct |
8 ms |
2252 KB |
Output is correct |
16 |
Correct |
3 ms |
2252 KB |
Output is correct |
17 |
Correct |
3 ms |
2252 KB |
Output is correct |
18 |
Correct |
3 ms |
2252 KB |
Output is correct |
19 |
Correct |
3 ms |
2252 KB |
Output is correct |
20 |
Correct |
3 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
7 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2372 KB |
Output is correct |
5 |
Correct |
7 ms |
2252 KB |
Output is correct |
6 |
Correct |
9 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2368 KB |
Output is correct |
9 |
Correct |
8 ms |
2372 KB |
Output is correct |
10 |
Correct |
7 ms |
2252 KB |
Output is correct |
11 |
Correct |
7 ms |
2368 KB |
Output is correct |
12 |
Correct |
7 ms |
2368 KB |
Output is correct |
13 |
Correct |
7 ms |
2252 KB |
Output is correct |
14 |
Correct |
8 ms |
2364 KB |
Output is correct |
15 |
Correct |
8 ms |
2252 KB |
Output is correct |
16 |
Correct |
3 ms |
2252 KB |
Output is correct |
17 |
Correct |
3 ms |
2252 KB |
Output is correct |
18 |
Correct |
3 ms |
2252 KB |
Output is correct |
19 |
Correct |
3 ms |
2252 KB |
Output is correct |
20 |
Correct |
3 ms |
2252 KB |
Output is correct |
21 |
Execution timed out |
2083 ms |
6468 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
539 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
7 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2372 KB |
Output is correct |
5 |
Correct |
7 ms |
2252 KB |
Output is correct |
6 |
Correct |
9 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2368 KB |
Output is correct |
9 |
Correct |
8 ms |
2372 KB |
Output is correct |
10 |
Correct |
7 ms |
2252 KB |
Output is correct |
11 |
Correct |
7 ms |
2368 KB |
Output is correct |
12 |
Correct |
7 ms |
2368 KB |
Output is correct |
13 |
Correct |
7 ms |
2252 KB |
Output is correct |
14 |
Correct |
8 ms |
2364 KB |
Output is correct |
15 |
Correct |
8 ms |
2252 KB |
Output is correct |
16 |
Correct |
3 ms |
2252 KB |
Output is correct |
17 |
Correct |
3 ms |
2252 KB |
Output is correct |
18 |
Correct |
3 ms |
2252 KB |
Output is correct |
19 |
Correct |
3 ms |
2252 KB |
Output is correct |
20 |
Correct |
3 ms |
2252 KB |
Output is correct |
21 |
Execution timed out |
2083 ms |
6468 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |