#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector<int> xx(1);
int f[505][1005], s[1005], g[505][1005], A[505], B[505];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N; cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> A[i] >> B[i]; B[i]++;
xx.push_back(A[i]);
xx.push_back(B[i]);
}
sort(xx.begin(), xx.end());
xx.erase(unique(xx.begin(), xx.end()), xx.end());
for (int i = 1; i <= N; ++i) {
s[0] = f[i - 1][0] = 1;
for (int j = 1; j + 1 < xx.size(); ++j) s[j] = (s[j - 1] + f[i - 1][j]) % mod;
for (int j = 1; j + 1 < xx.size(); ++j) {
if (A[i] <= xx[j] && xx[j + 1] <= B[i]) {
long long n = xx[j + 1] - xx[j];
f[i][j] = (n * s[j - 1] + g[i - 1][j]) % mod;
g[i][j] = ((n + 1) * n / 2 % mod * s[j - 1] % mod + g[i - 1][j] * n % mod - n * (n - 1) / 2 % mod * f[i - 1][j] % mod + mod) % mod;
}
else {
f[i][j] = f[i - 1][j];
g[i][j] = g[i - 1][j];
}
}
}
int ans = 0;
for (int i = 0; i + 1 < xx.size(); ++i) ans = (ans + f[N][i]) % mod;
cout << ans;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:20:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j + 1 < xx.size(); ++j) s[j] = (s[j - 1] + f[i - 1][j]) % mod;
~~~~~~^~~~~~~~~~~
boat.cpp:21:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j + 1 < xx.size(); ++j) {
~~~~~~^~~~~~~~~~~
boat.cpp:34:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i + 1 < xx.size(); ++i) ans = (ans + f[N][i]) % mod;
~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4344 KB |
Output is correct |
2 |
Correct |
9 ms |
4348 KB |
Output is correct |
3 |
Correct |
9 ms |
4344 KB |
Output is correct |
4 |
Correct |
10 ms |
4344 KB |
Output is correct |
5 |
Correct |
11 ms |
4344 KB |
Output is correct |
6 |
Correct |
11 ms |
4344 KB |
Output is correct |
7 |
Correct |
10 ms |
4344 KB |
Output is correct |
8 |
Correct |
10 ms |
4344 KB |
Output is correct |
9 |
Correct |
9 ms |
4344 KB |
Output is correct |
10 |
Correct |
10 ms |
4344 KB |
Output is correct |
11 |
Correct |
10 ms |
4236 KB |
Output is correct |
12 |
Correct |
10 ms |
4344 KB |
Output is correct |
13 |
Correct |
9 ms |
4348 KB |
Output is correct |
14 |
Correct |
9 ms |
4344 KB |
Output is correct |
15 |
Correct |
9 ms |
4344 KB |
Output is correct |
16 |
Correct |
6 ms |
4344 KB |
Output is correct |
17 |
Correct |
6 ms |
4348 KB |
Output is correct |
18 |
Correct |
6 ms |
4344 KB |
Output is correct |
19 |
Correct |
6 ms |
4344 KB |
Output is correct |
20 |
Correct |
6 ms |
4344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4344 KB |
Output is correct |
2 |
Correct |
9 ms |
4348 KB |
Output is correct |
3 |
Correct |
9 ms |
4344 KB |
Output is correct |
4 |
Correct |
10 ms |
4344 KB |
Output is correct |
5 |
Correct |
11 ms |
4344 KB |
Output is correct |
6 |
Correct |
11 ms |
4344 KB |
Output is correct |
7 |
Correct |
10 ms |
4344 KB |
Output is correct |
8 |
Correct |
10 ms |
4344 KB |
Output is correct |
9 |
Correct |
9 ms |
4344 KB |
Output is correct |
10 |
Correct |
10 ms |
4344 KB |
Output is correct |
11 |
Correct |
10 ms |
4236 KB |
Output is correct |
12 |
Correct |
10 ms |
4344 KB |
Output is correct |
13 |
Correct |
9 ms |
4348 KB |
Output is correct |
14 |
Correct |
9 ms |
4344 KB |
Output is correct |
15 |
Correct |
9 ms |
4344 KB |
Output is correct |
16 |
Correct |
6 ms |
4344 KB |
Output is correct |
17 |
Correct |
6 ms |
4348 KB |
Output is correct |
18 |
Correct |
6 ms |
4344 KB |
Output is correct |
19 |
Correct |
6 ms |
4344 KB |
Output is correct |
20 |
Correct |
6 ms |
4344 KB |
Output is correct |
21 |
Incorrect |
11 ms |
4344 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4344 KB |
Output is correct |
2 |
Correct |
9 ms |
4348 KB |
Output is correct |
3 |
Correct |
9 ms |
4344 KB |
Output is correct |
4 |
Correct |
10 ms |
4344 KB |
Output is correct |
5 |
Correct |
11 ms |
4344 KB |
Output is correct |
6 |
Correct |
11 ms |
4344 KB |
Output is correct |
7 |
Correct |
10 ms |
4344 KB |
Output is correct |
8 |
Correct |
10 ms |
4344 KB |
Output is correct |
9 |
Correct |
9 ms |
4344 KB |
Output is correct |
10 |
Correct |
10 ms |
4344 KB |
Output is correct |
11 |
Correct |
10 ms |
4236 KB |
Output is correct |
12 |
Correct |
10 ms |
4344 KB |
Output is correct |
13 |
Correct |
9 ms |
4348 KB |
Output is correct |
14 |
Correct |
9 ms |
4344 KB |
Output is correct |
15 |
Correct |
9 ms |
4344 KB |
Output is correct |
16 |
Correct |
6 ms |
4344 KB |
Output is correct |
17 |
Correct |
6 ms |
4348 KB |
Output is correct |
18 |
Correct |
6 ms |
4344 KB |
Output is correct |
19 |
Correct |
6 ms |
4344 KB |
Output is correct |
20 |
Correct |
6 ms |
4344 KB |
Output is correct |
21 |
Incorrect |
11 ms |
4344 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |