#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = a; i < _a; ++i)
#define llint long long
#define sz(x) (x.size())
#define LL(x) (x * 2)
#define RR(x) (x * 2 + 1)
#define fi first
#define se second
#define db(x) cout << #x << " = " << x << endl;
#define BIT(x, i) ((x >> i) & 1)
#define MASK(i) (1ll << i)
#define times clock() * 1.0 / CLOCKS_PER_SEC
void openFile() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef Tr___
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
#endif
}
const int maxN = 1e3 + 5;
const int maxM = 1e6 + 5;
const llint INF = 1e9 + 7;
int N;
vector<int> all;
int a[maxN], b[maxN];
llint dp[maxN][maxN], len[maxN], inv[maxN];
void enter() {
cin >> N;
FOR(i, 1, N) {
cin >> a[i] >> b[i];
all.push_back(a[i]);
all.push_back(b[i] + 1);
}
}
inline void add(llint &x, llint y) {
x = (x + y) % INF;
}
void solve() {
inv[1] = 1;
FOR(i, 2, maxN - 1) {
inv[i] = inv[INF % i] * (INF - INF / i) % INF;
}
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
FOR(i, 1, N) {
a[i] = upper_bound(all.begin(), all.end(), a[i]) - all.begin();
b[i] = upper_bound(all.begin(), all.end(), b[i]) - all.begin();
}
FOR(i, 1, all.size() - 1) {
len[i] = all[i] - all[i - 1];
}
FOR(i, 0, all.size() - 1) {
dp[0][i] = 1;
}
llint res = 0;
FOR(i, 1, N) {
FOR(j, a[i], b[i]) {
add(dp[i][j], dp[i - 1][j - 1] * len[j]);
llint num = 1, choose = len[j] - 1;
FORD(k, i - 1, 1) if (a[k] <= j && j <= b[k]) {
++num;
choose = choose * (len[j] + num - 2) % INF * inv[num] % INF;
if (choose == 0) break;
add(dp[i][j], dp[k - 1][j - 1] * choose % INF);
}
}
dp[i][0] = 1;
FOR(j, 1, all.size() - 1) {
add(dp[i][j], dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]);
add(dp[i][j], INF);
}
}
cout << (dp[N][all.size() - 1] - 1 + INF) % INF << endl;
}
int main() {
openFile();
enter();
solve();
return 0;
}
Compilation message
boat.cpp: In function 'void solve()':
boat.cpp:70:8: warning: unused variable 'res' [-Wunused-variable]
llint res = 0;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10096 KB |
Output is correct |
2 |
Correct |
9 ms |
10096 KB |
Output is correct |
3 |
Correct |
9 ms |
10096 KB |
Output is correct |
4 |
Correct |
6 ms |
10096 KB |
Output is correct |
5 |
Correct |
6 ms |
10096 KB |
Output is correct |
6 |
Correct |
0 ms |
10096 KB |
Output is correct |
7 |
Correct |
6 ms |
10096 KB |
Output is correct |
8 |
Correct |
3 ms |
10096 KB |
Output is correct |
9 |
Correct |
6 ms |
10096 KB |
Output is correct |
10 |
Correct |
3 ms |
10096 KB |
Output is correct |
11 |
Correct |
6 ms |
10096 KB |
Output is correct |
12 |
Correct |
9 ms |
10096 KB |
Output is correct |
13 |
Correct |
6 ms |
10096 KB |
Output is correct |
14 |
Correct |
9 ms |
10096 KB |
Output is correct |
15 |
Correct |
9 ms |
10096 KB |
Output is correct |
16 |
Correct |
3 ms |
10096 KB |
Output is correct |
17 |
Correct |
3 ms |
10096 KB |
Output is correct |
18 |
Correct |
0 ms |
10096 KB |
Output is correct |
19 |
Correct |
3 ms |
10096 KB |
Output is correct |
20 |
Correct |
3 ms |
10096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10096 KB |
Output is correct |
2 |
Correct |
9 ms |
10096 KB |
Output is correct |
3 |
Correct |
9 ms |
10096 KB |
Output is correct |
4 |
Correct |
6 ms |
10096 KB |
Output is correct |
5 |
Correct |
6 ms |
10096 KB |
Output is correct |
6 |
Correct |
0 ms |
10096 KB |
Output is correct |
7 |
Correct |
6 ms |
10096 KB |
Output is correct |
8 |
Correct |
3 ms |
10096 KB |
Output is correct |
9 |
Correct |
6 ms |
10096 KB |
Output is correct |
10 |
Correct |
3 ms |
10096 KB |
Output is correct |
11 |
Correct |
6 ms |
10096 KB |
Output is correct |
12 |
Correct |
9 ms |
10096 KB |
Output is correct |
13 |
Correct |
6 ms |
10096 KB |
Output is correct |
14 |
Correct |
9 ms |
10096 KB |
Output is correct |
15 |
Correct |
9 ms |
10096 KB |
Output is correct |
16 |
Correct |
3 ms |
10096 KB |
Output is correct |
17 |
Correct |
3 ms |
10096 KB |
Output is correct |
18 |
Correct |
0 ms |
10096 KB |
Output is correct |
19 |
Correct |
3 ms |
10096 KB |
Output is correct |
20 |
Correct |
3 ms |
10096 KB |
Output is correct |
21 |
Correct |
233 ms |
10096 KB |
Output is correct |
22 |
Correct |
229 ms |
10096 KB |
Output is correct |
23 |
Correct |
199 ms |
10096 KB |
Output is correct |
24 |
Correct |
226 ms |
10096 KB |
Output is correct |
25 |
Correct |
226 ms |
10096 KB |
Output is correct |
26 |
Correct |
459 ms |
10096 KB |
Output is correct |
27 |
Correct |
453 ms |
10096 KB |
Output is correct |
28 |
Correct |
469 ms |
10096 KB |
Output is correct |
29 |
Correct |
476 ms |
10096 KB |
Output is correct |
30 |
Correct |
9 ms |
10096 KB |
Output is correct |
31 |
Correct |
6 ms |
10096 KB |
Output is correct |
32 |
Correct |
3 ms |
10096 KB |
Output is correct |
33 |
Correct |
9 ms |
10096 KB |
Output is correct |
34 |
Correct |
6 ms |
10096 KB |
Output is correct |
35 |
Correct |
9 ms |
10096 KB |
Output is correct |
36 |
Correct |
6 ms |
10096 KB |
Output is correct |
37 |
Correct |
9 ms |
10096 KB |
Output is correct |
38 |
Correct |
3 ms |
10096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10096 KB |
Output is correct |
2 |
Correct |
0 ms |
10096 KB |
Output is correct |
3 |
Correct |
3 ms |
10096 KB |
Output is correct |
4 |
Correct |
3 ms |
10096 KB |
Output is correct |
5 |
Correct |
3 ms |
10096 KB |
Output is correct |
6 |
Correct |
3 ms |
10096 KB |
Output is correct |
7 |
Correct |
3 ms |
10096 KB |
Output is correct |
8 |
Correct |
3 ms |
10096 KB |
Output is correct |
9 |
Correct |
3 ms |
10096 KB |
Output is correct |
10 |
Correct |
6 ms |
10096 KB |
Output is correct |
11 |
Correct |
3 ms |
10096 KB |
Output is correct |
12 |
Correct |
3 ms |
10096 KB |
Output is correct |
13 |
Correct |
3 ms |
10096 KB |
Output is correct |
14 |
Correct |
3 ms |
10096 KB |
Output is correct |
15 |
Correct |
0 ms |
10096 KB |
Output is correct |
16 |
Correct |
0 ms |
10096 KB |
Output is correct |
17 |
Correct |
0 ms |
10096 KB |
Output is correct |
18 |
Correct |
0 ms |
10096 KB |
Output is correct |
19 |
Correct |
0 ms |
10096 KB |
Output is correct |
20 |
Correct |
0 ms |
10096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10096 KB |
Output is correct |
2 |
Correct |
9 ms |
10096 KB |
Output is correct |
3 |
Correct |
9 ms |
10096 KB |
Output is correct |
4 |
Correct |
6 ms |
10096 KB |
Output is correct |
5 |
Correct |
6 ms |
10096 KB |
Output is correct |
6 |
Correct |
0 ms |
10096 KB |
Output is correct |
7 |
Correct |
6 ms |
10096 KB |
Output is correct |
8 |
Correct |
3 ms |
10096 KB |
Output is correct |
9 |
Correct |
6 ms |
10096 KB |
Output is correct |
10 |
Correct |
3 ms |
10096 KB |
Output is correct |
11 |
Correct |
6 ms |
10096 KB |
Output is correct |
12 |
Correct |
9 ms |
10096 KB |
Output is correct |
13 |
Correct |
6 ms |
10096 KB |
Output is correct |
14 |
Correct |
9 ms |
10096 KB |
Output is correct |
15 |
Correct |
9 ms |
10096 KB |
Output is correct |
16 |
Correct |
3 ms |
10096 KB |
Output is correct |
17 |
Correct |
3 ms |
10096 KB |
Output is correct |
18 |
Correct |
0 ms |
10096 KB |
Output is correct |
19 |
Correct |
3 ms |
10096 KB |
Output is correct |
20 |
Correct |
3 ms |
10096 KB |
Output is correct |
21 |
Correct |
233 ms |
10096 KB |
Output is correct |
22 |
Correct |
229 ms |
10096 KB |
Output is correct |
23 |
Correct |
199 ms |
10096 KB |
Output is correct |
24 |
Correct |
226 ms |
10096 KB |
Output is correct |
25 |
Correct |
226 ms |
10096 KB |
Output is correct |
26 |
Correct |
459 ms |
10096 KB |
Output is correct |
27 |
Correct |
453 ms |
10096 KB |
Output is correct |
28 |
Correct |
469 ms |
10096 KB |
Output is correct |
29 |
Correct |
476 ms |
10096 KB |
Output is correct |
30 |
Correct |
9 ms |
10096 KB |
Output is correct |
31 |
Correct |
6 ms |
10096 KB |
Output is correct |
32 |
Correct |
3 ms |
10096 KB |
Output is correct |
33 |
Correct |
9 ms |
10096 KB |
Output is correct |
34 |
Correct |
6 ms |
10096 KB |
Output is correct |
35 |
Correct |
9 ms |
10096 KB |
Output is correct |
36 |
Correct |
6 ms |
10096 KB |
Output is correct |
37 |
Correct |
9 ms |
10096 KB |
Output is correct |
38 |
Correct |
3 ms |
10096 KB |
Output is correct |
39 |
Correct |
3 ms |
10096 KB |
Output is correct |
40 |
Correct |
0 ms |
10096 KB |
Output is correct |
41 |
Correct |
3 ms |
10096 KB |
Output is correct |
42 |
Correct |
3 ms |
10096 KB |
Output is correct |
43 |
Correct |
3 ms |
10096 KB |
Output is correct |
44 |
Correct |
3 ms |
10096 KB |
Output is correct |
45 |
Correct |
3 ms |
10096 KB |
Output is correct |
46 |
Correct |
3 ms |
10096 KB |
Output is correct |
47 |
Correct |
3 ms |
10096 KB |
Output is correct |
48 |
Correct |
6 ms |
10096 KB |
Output is correct |
49 |
Correct |
3 ms |
10096 KB |
Output is correct |
50 |
Correct |
3 ms |
10096 KB |
Output is correct |
51 |
Correct |
3 ms |
10096 KB |
Output is correct |
52 |
Correct |
3 ms |
10096 KB |
Output is correct |
53 |
Correct |
0 ms |
10096 KB |
Output is correct |
54 |
Correct |
0 ms |
10096 KB |
Output is correct |
55 |
Correct |
0 ms |
10096 KB |
Output is correct |
56 |
Correct |
0 ms |
10096 KB |
Output is correct |
57 |
Correct |
0 ms |
10096 KB |
Output is correct |
58 |
Correct |
0 ms |
10096 KB |
Output is correct |
59 |
Correct |
313 ms |
10096 KB |
Output is correct |
60 |
Correct |
303 ms |
10096 KB |
Output is correct |
61 |
Correct |
269 ms |
10096 KB |
Output is correct |
62 |
Correct |
303 ms |
10096 KB |
Output is correct |
63 |
Correct |
279 ms |
10096 KB |
Output is correct |
64 |
Correct |
653 ms |
10096 KB |
Output is correct |
65 |
Correct |
689 ms |
10096 KB |
Output is correct |
66 |
Correct |
663 ms |
10096 KB |
Output is correct |
67 |
Correct |
649 ms |
10096 KB |
Output is correct |
68 |
Correct |
663 ms |
10096 KB |
Output is correct |
69 |
Correct |
253 ms |
10096 KB |
Output is correct |
70 |
Correct |
256 ms |
10096 KB |
Output is correct |
71 |
Correct |
246 ms |
10096 KB |
Output is correct |
72 |
Correct |
263 ms |
10096 KB |
Output is correct |
73 |
Correct |
276 ms |
10096 KB |
Output is correct |
74 |
Correct |
39 ms |
10096 KB |
Output is correct |
75 |
Correct |
36 ms |
10096 KB |
Output is correct |
76 |
Correct |
56 ms |
10096 KB |
Output is correct |
77 |
Correct |
36 ms |
10096 KB |
Output is correct |
78 |
Correct |
39 ms |
10096 KB |
Output is correct |