#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for (int i = s; i < t; i++)
#define per(i, s, t) for (int i = s; i >= t; i--)
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
const int INF = (int) (1e9 + 1e6 + 123);
template<typename A, typename B> bool mini(A& x, const B& y) {
if (y < x) {
x = y;
return true;
}
return false;
}
template<typename A, typename B> bool maxi(A& x, const B& y) {
if (y > x) {
x = y;
return true;
}
return false;
}
void run();
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
run();
return 0;
}
const int N = 505;
const int MOD = 1000000000 + 7;
const long long MOD2 = MOD * 1LL * MOD;
void add(int& x, int y) {
x += y;
if (x >= MOD) {
x -= MOD;
}
}
int power(int x, int y) {
if (y == 0) {
return 1;
}
if (y % 2 == 0) {
return power(x * 1LL * x % MOD, y / 2);
} else {
return power(x, y - 1) * 1LL * x % MOD;
}
}
int n;
int a[N], b[N];
vector<int> cool;
int fact[N];
int rfact[N];
int dp[2 * N][N];
int prec[2 * N][N];
int cnk(int n, int k) {
if (k > n) {
return 0;
}
int res = 1;
rep(i, 0, k) {
res = res * 1LL * (n - i) % MOD;
}
res = res * 1LL * rfact[k] % MOD;
return res;
}
void upd(int l, int r) {
long long pref = 0;
rep(block, 0, sz(cool)) {
long long was = pref;
rep(cnt, 0, N) {
pref += dp[block][cnt] * 1LL * prec[block][cnt];
if (pref >= MOD2) {
pref -= MOD2;
}
}
pref %= MOD;
int len = cool[block + 1] - cool[block];
if (l <= block && block <= r) {
per(cnt, N - 1, 2) {
add(dp[block][cnt], dp[block][cnt - 1]);
}
add(dp[block][1], was);
}
}
}
void run() {
cin >> n;
rep(i, 0, n) {
cin >> a[i] >> b[i];
cool.push_back(a[i]);
cool.push_back(b[i] + 1);
}
cool.push_back(0);
sort(all(cool));
cool.resize(unique(all(cool)) - cool.begin());
cool.push_back(INF);
fact[0] = 1;
rep(i, 1, N) {
fact[i] = fact[i - 1] * 1LL * i % MOD;
}
rep(i, 0, N) {
rfact[i] = power(fact[i], MOD - 2);
}
rep(i, 0, sz(cool) - 1) {
int len = cool[i + 1] - cool[i];
rep(j, 0, N) {
prec[i][j] = cnk(len, j);
}
}
dp[0][0] = 1;
rep(i, 0, n) {
int l = 0;
while (cool[l] != a[i]) {
l++;
}
int r = l;
while (cool[r + 1] <= b[i]) {
r++;
}
upd(l, r);
}
int ans = MOD - 1;
rep(i, 0, sz(cool) - 1) {
rep(j, 0, N) {
add(ans, dp[i][j] * 1LL * prec[i][j] % MOD);
}
}
cout << ans << "\n";
}
Compilation message
boat.cpp: In function 'void upd(int, int)':
boat.cpp:95:7: warning: unused variable 'len' [-Wunused-variable]
int len = cool[block + 1] - cool[block];
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
811 ms |
4252 KB |
Output is correct |
2 |
Correct |
711 ms |
4300 KB |
Output is correct |
3 |
Correct |
749 ms |
4520 KB |
Output is correct |
4 |
Correct |
772 ms |
4372 KB |
Output is correct |
5 |
Correct |
775 ms |
4488 KB |
Output is correct |
6 |
Correct |
718 ms |
4396 KB |
Output is correct |
7 |
Correct |
733 ms |
4448 KB |
Output is correct |
8 |
Correct |
710 ms |
4532 KB |
Output is correct |
9 |
Correct |
726 ms |
4320 KB |
Output is correct |
10 |
Correct |
776 ms |
4496 KB |
Output is correct |
11 |
Correct |
708 ms |
4472 KB |
Output is correct |
12 |
Correct |
761 ms |
4456 KB |
Output is correct |
13 |
Correct |
792 ms |
4472 KB |
Output is correct |
14 |
Correct |
734 ms |
4324 KB |
Output is correct |
15 |
Correct |
785 ms |
4368 KB |
Output is correct |
16 |
Correct |
130 ms |
1016 KB |
Output is correct |
17 |
Correct |
141 ms |
1084 KB |
Output is correct |
18 |
Correct |
152 ms |
1272 KB |
Output is correct |
19 |
Correct |
146 ms |
1272 KB |
Output is correct |
20 |
Correct |
136 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
811 ms |
4252 KB |
Output is correct |
2 |
Correct |
711 ms |
4300 KB |
Output is correct |
3 |
Correct |
749 ms |
4520 KB |
Output is correct |
4 |
Correct |
772 ms |
4372 KB |
Output is correct |
5 |
Correct |
775 ms |
4488 KB |
Output is correct |
6 |
Correct |
718 ms |
4396 KB |
Output is correct |
7 |
Correct |
733 ms |
4448 KB |
Output is correct |
8 |
Correct |
710 ms |
4532 KB |
Output is correct |
9 |
Correct |
726 ms |
4320 KB |
Output is correct |
10 |
Correct |
776 ms |
4496 KB |
Output is correct |
11 |
Correct |
708 ms |
4472 KB |
Output is correct |
12 |
Correct |
761 ms |
4456 KB |
Output is correct |
13 |
Correct |
792 ms |
4472 KB |
Output is correct |
14 |
Correct |
734 ms |
4324 KB |
Output is correct |
15 |
Correct |
785 ms |
4368 KB |
Output is correct |
16 |
Correct |
130 ms |
1016 KB |
Output is correct |
17 |
Correct |
141 ms |
1084 KB |
Output is correct |
18 |
Correct |
152 ms |
1272 KB |
Output is correct |
19 |
Correct |
146 ms |
1272 KB |
Output is correct |
20 |
Correct |
136 ms |
1144 KB |
Output is correct |
21 |
Correct |
443 ms |
4120 KB |
Output is correct |
22 |
Correct |
451 ms |
4088 KB |
Output is correct |
23 |
Correct |
525 ms |
4088 KB |
Output is correct |
24 |
Correct |
457 ms |
4028 KB |
Output is correct |
25 |
Correct |
426 ms |
4088 KB |
Output is correct |
26 |
Correct |
468 ms |
3932 KB |
Output is correct |
27 |
Correct |
494 ms |
3960 KB |
Output is correct |
28 |
Correct |
427 ms |
3832 KB |
Output is correct |
29 |
Correct |
461 ms |
3832 KB |
Output is correct |
30 |
Correct |
712 ms |
4412 KB |
Output is correct |
31 |
Correct |
695 ms |
4472 KB |
Output is correct |
32 |
Correct |
706 ms |
4428 KB |
Output is correct |
33 |
Correct |
692 ms |
4344 KB |
Output is correct |
34 |
Correct |
712 ms |
4472 KB |
Output is correct |
35 |
Correct |
710 ms |
4356 KB |
Output is correct |
36 |
Correct |
729 ms |
4344 KB |
Output is correct |
37 |
Correct |
723 ms |
4344 KB |
Output is correct |
38 |
Correct |
713 ms |
4400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
1300 KB |
Output is correct |
2 |
Correct |
167 ms |
1276 KB |
Output is correct |
3 |
Correct |
172 ms |
1336 KB |
Output is correct |
4 |
Correct |
168 ms |
1104 KB |
Output is correct |
5 |
Correct |
169 ms |
1184 KB |
Output is correct |
6 |
Correct |
164 ms |
1116 KB |
Output is correct |
7 |
Correct |
161 ms |
1100 KB |
Output is correct |
8 |
Correct |
161 ms |
1144 KB |
Output is correct |
9 |
Correct |
159 ms |
1176 KB |
Output is correct |
10 |
Correct |
169 ms |
1192 KB |
Output is correct |
11 |
Correct |
162 ms |
1212 KB |
Output is correct |
12 |
Correct |
162 ms |
1144 KB |
Output is correct |
13 |
Correct |
162 ms |
1192 KB |
Output is correct |
14 |
Correct |
162 ms |
1196 KB |
Output is correct |
15 |
Correct |
164 ms |
1368 KB |
Output is correct |
16 |
Correct |
77 ms |
888 KB |
Output is correct |
17 |
Correct |
73 ms |
784 KB |
Output is correct |
18 |
Correct |
77 ms |
760 KB |
Output is correct |
19 |
Correct |
78 ms |
792 KB |
Output is correct |
20 |
Correct |
80 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
811 ms |
4252 KB |
Output is correct |
2 |
Correct |
711 ms |
4300 KB |
Output is correct |
3 |
Correct |
749 ms |
4520 KB |
Output is correct |
4 |
Correct |
772 ms |
4372 KB |
Output is correct |
5 |
Correct |
775 ms |
4488 KB |
Output is correct |
6 |
Correct |
718 ms |
4396 KB |
Output is correct |
7 |
Correct |
733 ms |
4448 KB |
Output is correct |
8 |
Correct |
710 ms |
4532 KB |
Output is correct |
9 |
Correct |
726 ms |
4320 KB |
Output is correct |
10 |
Correct |
776 ms |
4496 KB |
Output is correct |
11 |
Correct |
708 ms |
4472 KB |
Output is correct |
12 |
Correct |
761 ms |
4456 KB |
Output is correct |
13 |
Correct |
792 ms |
4472 KB |
Output is correct |
14 |
Correct |
734 ms |
4324 KB |
Output is correct |
15 |
Correct |
785 ms |
4368 KB |
Output is correct |
16 |
Correct |
130 ms |
1016 KB |
Output is correct |
17 |
Correct |
141 ms |
1084 KB |
Output is correct |
18 |
Correct |
152 ms |
1272 KB |
Output is correct |
19 |
Correct |
146 ms |
1272 KB |
Output is correct |
20 |
Correct |
136 ms |
1144 KB |
Output is correct |
21 |
Correct |
443 ms |
4120 KB |
Output is correct |
22 |
Correct |
451 ms |
4088 KB |
Output is correct |
23 |
Correct |
525 ms |
4088 KB |
Output is correct |
24 |
Correct |
457 ms |
4028 KB |
Output is correct |
25 |
Correct |
426 ms |
4088 KB |
Output is correct |
26 |
Correct |
468 ms |
3932 KB |
Output is correct |
27 |
Correct |
494 ms |
3960 KB |
Output is correct |
28 |
Correct |
427 ms |
3832 KB |
Output is correct |
29 |
Correct |
461 ms |
3832 KB |
Output is correct |
30 |
Correct |
712 ms |
4412 KB |
Output is correct |
31 |
Correct |
695 ms |
4472 KB |
Output is correct |
32 |
Correct |
706 ms |
4428 KB |
Output is correct |
33 |
Correct |
692 ms |
4344 KB |
Output is correct |
34 |
Correct |
712 ms |
4472 KB |
Output is correct |
35 |
Correct |
710 ms |
4356 KB |
Output is correct |
36 |
Correct |
729 ms |
4344 KB |
Output is correct |
37 |
Correct |
723 ms |
4344 KB |
Output is correct |
38 |
Correct |
713 ms |
4400 KB |
Output is correct |
39 |
Correct |
162 ms |
1300 KB |
Output is correct |
40 |
Correct |
167 ms |
1276 KB |
Output is correct |
41 |
Correct |
172 ms |
1336 KB |
Output is correct |
42 |
Correct |
168 ms |
1104 KB |
Output is correct |
43 |
Correct |
169 ms |
1184 KB |
Output is correct |
44 |
Correct |
164 ms |
1116 KB |
Output is correct |
45 |
Correct |
161 ms |
1100 KB |
Output is correct |
46 |
Correct |
161 ms |
1144 KB |
Output is correct |
47 |
Correct |
159 ms |
1176 KB |
Output is correct |
48 |
Correct |
169 ms |
1192 KB |
Output is correct |
49 |
Correct |
162 ms |
1212 KB |
Output is correct |
50 |
Correct |
162 ms |
1144 KB |
Output is correct |
51 |
Correct |
162 ms |
1192 KB |
Output is correct |
52 |
Correct |
162 ms |
1196 KB |
Output is correct |
53 |
Correct |
164 ms |
1368 KB |
Output is correct |
54 |
Correct |
77 ms |
888 KB |
Output is correct |
55 |
Correct |
73 ms |
784 KB |
Output is correct |
56 |
Correct |
77 ms |
760 KB |
Output is correct |
57 |
Correct |
78 ms |
792 KB |
Output is correct |
58 |
Correct |
80 ms |
892 KB |
Output is correct |
59 |
Correct |
1206 ms |
4584 KB |
Output is correct |
60 |
Correct |
1196 ms |
4344 KB |
Output is correct |
61 |
Correct |
1167 ms |
4468 KB |
Output is correct |
62 |
Correct |
1193 ms |
4452 KB |
Output is correct |
63 |
Correct |
1208 ms |
4528 KB |
Output is correct |
64 |
Correct |
1234 ms |
4452 KB |
Output is correct |
65 |
Correct |
1217 ms |
4480 KB |
Output is correct |
66 |
Correct |
1225 ms |
4344 KB |
Output is correct |
67 |
Correct |
1235 ms |
4492 KB |
Output is correct |
68 |
Correct |
1223 ms |
4436 KB |
Output is correct |
69 |
Correct |
1145 ms |
4512 KB |
Output is correct |
70 |
Correct |
1212 ms |
4312 KB |
Output is correct |
71 |
Correct |
1206 ms |
4464 KB |
Output is correct |
72 |
Correct |
1223 ms |
4472 KB |
Output is correct |
73 |
Correct |
1246 ms |
4472 KB |
Output is correct |
74 |
Correct |
156 ms |
1144 KB |
Output is correct |
75 |
Correct |
167 ms |
1144 KB |
Output is correct |
76 |
Correct |
167 ms |
1148 KB |
Output is correct |
77 |
Correct |
159 ms |
1116 KB |
Output is correct |
78 |
Correct |
160 ms |
1164 KB |
Output is correct |