#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
int pwr(int x, int n) {
if(n == 0) return 1;
if(n == 1) return x;
int h = pwr(x, n/2);
if(n%2 == 0) return h*h%MOD;
else return h*h%MOD*x%MOD;
}
int inv2(int x) {
return pwr(x, MOD-2);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
// regions [l, r)
vector<pair<int, int>> v;
vector<int> len;
int a[n+1], b[n+1], inv[n+1], ans = 0;
for(int i = 1; i <= n; i++) inv[i] = inv2(i);
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
v.push_back({a[i], i});
v.push_back({b[i]+1, i+n});
}
v.push_back({0, 0});
sort(v.begin(), v.end());
int cnt = 0;
for(int i = 0; i < v.size(); i++) {
if(v[i].second <= n) a[v[i].second] = cnt;
else b[v[i].second-n] = cnt-1;
if(i != v.size()-1 && v[i].first != v[i+1].first) {
len.push_back(v[i+1].first-v[i].first);
cnt++;
}
}
int dp[n+1][cnt], pref[n+1][cnt];
memset(dp, 0, sizeof(dp));
memset(pref, 0, sizeof(pref));
dp[0][0] = 1;
for(int i = 0; i < cnt; i++) pref[0][i] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j < cnt; j++) {
if(j >= a[i] && j <= b[i]) {
int c = len[j], cur = 1;
for(int k = i-1; k >= 0; k--) {
dp[i][j] += pref[k][j-1] * c % MOD;
dp[i][j] %= MOD;
if(j >= a[k] && j <= b[k]) {
cur++;
c = c*(len[j]+cur-1)%MOD * inv[cur]%MOD;
}
}
}
pref[i][j] = pref[i][j-1]+dp[i][j];
ans = (ans+dp[i][j]) % MOD;
}
}
cout << ans;
}
Compilation message
boat.cpp: In function 'int32_t main()':
boat.cpp:36:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
boat.cpp:39:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(i != v.size()-1 && v[i].first != v[i+1].first) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8280 KB |
Output is correct |
2 |
Correct |
7 ms |
8284 KB |
Output is correct |
3 |
Correct |
8 ms |
8340 KB |
Output is correct |
4 |
Correct |
7 ms |
8280 KB |
Output is correct |
5 |
Correct |
7 ms |
8284 KB |
Output is correct |
6 |
Correct |
7 ms |
8284 KB |
Output is correct |
7 |
Correct |
7 ms |
8284 KB |
Output is correct |
8 |
Correct |
7 ms |
8280 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
10 |
Correct |
7 ms |
8144 KB |
Output is correct |
11 |
Correct |
7 ms |
8284 KB |
Output is correct |
12 |
Correct |
7 ms |
8224 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
7 ms |
8284 KB |
Output is correct |
15 |
Correct |
7 ms |
8344 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1884 KB |
Output is correct |
19 |
Correct |
2 ms |
1884 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8280 KB |
Output is correct |
2 |
Correct |
7 ms |
8284 KB |
Output is correct |
3 |
Correct |
8 ms |
8340 KB |
Output is correct |
4 |
Correct |
7 ms |
8280 KB |
Output is correct |
5 |
Correct |
7 ms |
8284 KB |
Output is correct |
6 |
Correct |
7 ms |
8284 KB |
Output is correct |
7 |
Correct |
7 ms |
8284 KB |
Output is correct |
8 |
Correct |
7 ms |
8280 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
10 |
Correct |
7 ms |
8144 KB |
Output is correct |
11 |
Correct |
7 ms |
8284 KB |
Output is correct |
12 |
Correct |
7 ms |
8224 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
7 ms |
8284 KB |
Output is correct |
15 |
Correct |
7 ms |
8344 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1884 KB |
Output is correct |
19 |
Correct |
2 ms |
1884 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Incorrect |
223 ms |
7512 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8280 KB |
Output is correct |
2 |
Correct |
7 ms |
8284 KB |
Output is correct |
3 |
Correct |
8 ms |
8340 KB |
Output is correct |
4 |
Correct |
7 ms |
8280 KB |
Output is correct |
5 |
Correct |
7 ms |
8284 KB |
Output is correct |
6 |
Correct |
7 ms |
8284 KB |
Output is correct |
7 |
Correct |
7 ms |
8284 KB |
Output is correct |
8 |
Correct |
7 ms |
8280 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
10 |
Correct |
7 ms |
8144 KB |
Output is correct |
11 |
Correct |
7 ms |
8284 KB |
Output is correct |
12 |
Correct |
7 ms |
8224 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
7 ms |
8284 KB |
Output is correct |
15 |
Correct |
7 ms |
8344 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1884 KB |
Output is correct |
19 |
Correct |
2 ms |
1884 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Incorrect |
223 ms |
7512 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |