// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = (int)1e3 + 5;
const int MOD = (int)1e9 + 7;
int fact[MAXN], rev[MAXN];
int dp[2][MAXN][MAXN];
int mem[MAXN][MAXN];
vector<int> T;
pii arr[MAXN];
int n;
int addMod(int a, int b, int m = MOD) {
a += b;
if (m <= a) {
a -= m;
}
return a;
}
int mulMod(int a, int b, int m = MOD) {
return a * 1ll * b % m;
}
int binPow(int a, int b, int m = MOD) {
int ret = 1;
while (b > 0) {
if (b & 1) {
ret = mulMod(ret, a, m);
}
a = mulMod(a, a, m);
b >>= 1;
}
return ret;
}
void pre() {
fact[0] = rev[0] = 1;
for (int i = 1; i < MAXN; ++i) {
fact[i] = mulMod(fact[i - 1], i);
rev[i] = binPow(fact[i], MOD - 2);
}
}
int C(int n, int k) {
if (n < 0 || k < 0 || k > n) {
return 0;
}
int a = 1, b = 1;
for (int i = n - k + 1; i <= n; ++i) {
a = mulMod(a, i);
}
for (int i = 1; i <= k; ++i) {
b = mulMod(b, i);
}
return mulMod(a, binPow(b, MOD - 2));
}
int f(int idx, int cnt) {
int x = T[idx + 1] - T[idx];
return C(x, cnt);
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &arr[i].fi, &arr[i].se);
T.pb(arr[i].fi);
T.pb(arr[i].se + 1);
}
T.pb(0);
sort(all(T));
T.resize(unique(all(T)) - T.begin());
for (int i = 1; i <= n; ++i) {
arr[i].fi = lower_bound(all(T), arr[i].fi) - T.begin();
arr[i].se = lower_bound(all(T), arr[i].se + 1) - T.begin();
}
for (int i = 0; i + 1 < T.size(); ++i) {
for (int j = 0; j <= n; ++j) {
mem[i][j] = f(i, j);
}
}
dp[0][0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int c = 0; c < T.size(); ++c) {
for (int cnt = 0; cnt <= n; ++cnt) {
dp[1][c][cnt] = dp[0][c][cnt];
}
}
int p = 0, w = 0;
for (int c = arr[i].fi; c < arr[i].se; ++c) {
for (int cnt = 1; cnt <= n; ++cnt) {
dp[1][c][cnt] = addMod(dp[1][c][cnt], dp[0][c][cnt - 1]);
}
while (p < c) {
for (int cnt = 0; cnt <= n; ++cnt) {
w = addMod(w, mulMod(dp[0][p][cnt], mem[p][cnt]));
}
++p;
}
dp[1][c][1] = addMod(dp[1][c][1], w);
}
for (int c = 0; c < T.size(); ++c) {
for (int cnt = 0; cnt <= n; ++cnt) {
dp[0][c][cnt] = dp[1][c][cnt];
}
}
}
int ans = 0;
for (int c = 0; c + 1 < T.size(); ++c) {
for (int cnt = 1; cnt <= n; ++cnt) {
ans = addMod(ans, mulMod(dp[0][c][cnt], mem[c][cnt]));
}
}
printf("%d\n", ans);
}
int main() {
int tt = 1;
pre();
while (tt--) {
solve();
}
return 0;
}
Compilation message
boat.cpp: In function 'void solve()':
boat.cpp:117:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i + 1 < T.size(); ++i) {
~~~~~~^~~~~~~~~~
boat.cpp:126:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int c = 0; c < T.size(); ++c) {
~~^~~~~~~~~~
boat.cpp:150:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int c = 0; c < T.size(); ++c) {
~~^~~~~~~~~~
boat.cpp:159:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int c = 0; c + 1 < T.size(); ++c) {
~~~~~~^~~~~~~~~~
boat.cpp:100:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:103:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &arr[i].fi, &arr[i].se);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1732 ms |
12408 KB |
Output is correct |
2 |
Correct |
1760 ms |
12248 KB |
Output is correct |
3 |
Correct |
1824 ms |
12248 KB |
Output is correct |
4 |
Correct |
1748 ms |
12276 KB |
Output is correct |
5 |
Correct |
1731 ms |
12280 KB |
Output is correct |
6 |
Correct |
1721 ms |
12152 KB |
Output is correct |
7 |
Correct |
1745 ms |
12100 KB |
Output is correct |
8 |
Correct |
1748 ms |
12092 KB |
Output is correct |
9 |
Correct |
1762 ms |
12200 KB |
Output is correct |
10 |
Correct |
1724 ms |
12200 KB |
Output is correct |
11 |
Correct |
1731 ms |
12196 KB |
Output is correct |
12 |
Correct |
1690 ms |
12292 KB |
Output is correct |
13 |
Correct |
1773 ms |
12236 KB |
Output is correct |
14 |
Correct |
1735 ms |
12280 KB |
Output is correct |
15 |
Correct |
1742 ms |
12316 KB |
Output is correct |
16 |
Correct |
235 ms |
2424 KB |
Output is correct |
17 |
Correct |
252 ms |
2652 KB |
Output is correct |
18 |
Correct |
241 ms |
2552 KB |
Output is correct |
19 |
Correct |
251 ms |
2552 KB |
Output is correct |
20 |
Correct |
247 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1732 ms |
12408 KB |
Output is correct |
2 |
Correct |
1760 ms |
12248 KB |
Output is correct |
3 |
Correct |
1824 ms |
12248 KB |
Output is correct |
4 |
Correct |
1748 ms |
12276 KB |
Output is correct |
5 |
Correct |
1731 ms |
12280 KB |
Output is correct |
6 |
Correct |
1721 ms |
12152 KB |
Output is correct |
7 |
Correct |
1745 ms |
12100 KB |
Output is correct |
8 |
Correct |
1748 ms |
12092 KB |
Output is correct |
9 |
Correct |
1762 ms |
12200 KB |
Output is correct |
10 |
Correct |
1724 ms |
12200 KB |
Output is correct |
11 |
Correct |
1731 ms |
12196 KB |
Output is correct |
12 |
Correct |
1690 ms |
12292 KB |
Output is correct |
13 |
Correct |
1773 ms |
12236 KB |
Output is correct |
14 |
Correct |
1735 ms |
12280 KB |
Output is correct |
15 |
Correct |
1742 ms |
12316 KB |
Output is correct |
16 |
Correct |
235 ms |
2424 KB |
Output is correct |
17 |
Correct |
252 ms |
2652 KB |
Output is correct |
18 |
Correct |
241 ms |
2552 KB |
Output is correct |
19 |
Correct |
251 ms |
2552 KB |
Output is correct |
20 |
Correct |
247 ms |
2680 KB |
Output is correct |
21 |
Correct |
1092 ms |
11160 KB |
Output is correct |
22 |
Correct |
1124 ms |
11308 KB |
Output is correct |
23 |
Correct |
1063 ms |
11000 KB |
Output is correct |
24 |
Correct |
1057 ms |
11128 KB |
Output is correct |
25 |
Correct |
1105 ms |
11128 KB |
Output is correct |
26 |
Correct |
1128 ms |
10872 KB |
Output is correct |
27 |
Correct |
1187 ms |
10872 KB |
Output is correct |
28 |
Correct |
1103 ms |
10872 KB |
Output is correct |
29 |
Correct |
1127 ms |
10744 KB |
Output is correct |
30 |
Correct |
1603 ms |
12192 KB |
Output is correct |
31 |
Correct |
1667 ms |
12152 KB |
Output is correct |
32 |
Correct |
1602 ms |
12160 KB |
Output is correct |
33 |
Correct |
1635 ms |
12280 KB |
Output is correct |
34 |
Correct |
1673 ms |
12336 KB |
Output is correct |
35 |
Correct |
1597 ms |
12280 KB |
Output is correct |
36 |
Correct |
1612 ms |
12284 KB |
Output is correct |
37 |
Correct |
1688 ms |
12160 KB |
Output is correct |
38 |
Correct |
1644 ms |
12248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
2680 KB |
Output is correct |
2 |
Correct |
29 ms |
2808 KB |
Output is correct |
3 |
Correct |
30 ms |
2680 KB |
Output is correct |
4 |
Correct |
32 ms |
2812 KB |
Output is correct |
5 |
Correct |
30 ms |
2680 KB |
Output is correct |
6 |
Correct |
30 ms |
2680 KB |
Output is correct |
7 |
Correct |
31 ms |
2680 KB |
Output is correct |
8 |
Correct |
30 ms |
2680 KB |
Output is correct |
9 |
Correct |
30 ms |
2680 KB |
Output is correct |
10 |
Correct |
30 ms |
2680 KB |
Output is correct |
11 |
Correct |
30 ms |
2680 KB |
Output is correct |
12 |
Correct |
31 ms |
2808 KB |
Output is correct |
13 |
Correct |
29 ms |
2680 KB |
Output is correct |
14 |
Correct |
29 ms |
2680 KB |
Output is correct |
15 |
Correct |
30 ms |
2680 KB |
Output is correct |
16 |
Correct |
17 ms |
1656 KB |
Output is correct |
17 |
Correct |
18 ms |
1656 KB |
Output is correct |
18 |
Correct |
16 ms |
1660 KB |
Output is correct |
19 |
Correct |
17 ms |
1656 KB |
Output is correct |
20 |
Correct |
17 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1732 ms |
12408 KB |
Output is correct |
2 |
Correct |
1760 ms |
12248 KB |
Output is correct |
3 |
Correct |
1824 ms |
12248 KB |
Output is correct |
4 |
Correct |
1748 ms |
12276 KB |
Output is correct |
5 |
Correct |
1731 ms |
12280 KB |
Output is correct |
6 |
Correct |
1721 ms |
12152 KB |
Output is correct |
7 |
Correct |
1745 ms |
12100 KB |
Output is correct |
8 |
Correct |
1748 ms |
12092 KB |
Output is correct |
9 |
Correct |
1762 ms |
12200 KB |
Output is correct |
10 |
Correct |
1724 ms |
12200 KB |
Output is correct |
11 |
Correct |
1731 ms |
12196 KB |
Output is correct |
12 |
Correct |
1690 ms |
12292 KB |
Output is correct |
13 |
Correct |
1773 ms |
12236 KB |
Output is correct |
14 |
Correct |
1735 ms |
12280 KB |
Output is correct |
15 |
Correct |
1742 ms |
12316 KB |
Output is correct |
16 |
Correct |
235 ms |
2424 KB |
Output is correct |
17 |
Correct |
252 ms |
2652 KB |
Output is correct |
18 |
Correct |
241 ms |
2552 KB |
Output is correct |
19 |
Correct |
251 ms |
2552 KB |
Output is correct |
20 |
Correct |
247 ms |
2680 KB |
Output is correct |
21 |
Correct |
1092 ms |
11160 KB |
Output is correct |
22 |
Correct |
1124 ms |
11308 KB |
Output is correct |
23 |
Correct |
1063 ms |
11000 KB |
Output is correct |
24 |
Correct |
1057 ms |
11128 KB |
Output is correct |
25 |
Correct |
1105 ms |
11128 KB |
Output is correct |
26 |
Correct |
1128 ms |
10872 KB |
Output is correct |
27 |
Correct |
1187 ms |
10872 KB |
Output is correct |
28 |
Correct |
1103 ms |
10872 KB |
Output is correct |
29 |
Correct |
1127 ms |
10744 KB |
Output is correct |
30 |
Correct |
1603 ms |
12192 KB |
Output is correct |
31 |
Correct |
1667 ms |
12152 KB |
Output is correct |
32 |
Correct |
1602 ms |
12160 KB |
Output is correct |
33 |
Correct |
1635 ms |
12280 KB |
Output is correct |
34 |
Correct |
1673 ms |
12336 KB |
Output is correct |
35 |
Correct |
1597 ms |
12280 KB |
Output is correct |
36 |
Correct |
1612 ms |
12284 KB |
Output is correct |
37 |
Correct |
1688 ms |
12160 KB |
Output is correct |
38 |
Correct |
1644 ms |
12248 KB |
Output is correct |
39 |
Correct |
30 ms |
2680 KB |
Output is correct |
40 |
Correct |
29 ms |
2808 KB |
Output is correct |
41 |
Correct |
30 ms |
2680 KB |
Output is correct |
42 |
Correct |
32 ms |
2812 KB |
Output is correct |
43 |
Correct |
30 ms |
2680 KB |
Output is correct |
44 |
Correct |
30 ms |
2680 KB |
Output is correct |
45 |
Correct |
31 ms |
2680 KB |
Output is correct |
46 |
Correct |
30 ms |
2680 KB |
Output is correct |
47 |
Correct |
30 ms |
2680 KB |
Output is correct |
48 |
Correct |
30 ms |
2680 KB |
Output is correct |
49 |
Correct |
30 ms |
2680 KB |
Output is correct |
50 |
Correct |
31 ms |
2808 KB |
Output is correct |
51 |
Correct |
29 ms |
2680 KB |
Output is correct |
52 |
Correct |
29 ms |
2680 KB |
Output is correct |
53 |
Correct |
30 ms |
2680 KB |
Output is correct |
54 |
Correct |
17 ms |
1656 KB |
Output is correct |
55 |
Correct |
18 ms |
1656 KB |
Output is correct |
56 |
Correct |
16 ms |
1660 KB |
Output is correct |
57 |
Correct |
17 ms |
1656 KB |
Output is correct |
58 |
Correct |
17 ms |
1784 KB |
Output is correct |
59 |
Execution timed out |
2079 ms |
12280 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |