// 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];
vector<int> T;
pii arr[MAXN];
int n;
void addMod(int &a, int b, int m = MOD) {
a += b;
if (m <= a) {
a -= m;
}
}
void mulMod(int &a, int b, int m = MOD) {
a = (a * 1ll * b) % m;
}
int binPow(int a, int b) {
int ret = 1;
while (b > 0) {
if (b & 1) {
mulMod(ret, a);
}
mulMod(a, a);
b >>= 1;
}
return ret;
}
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();
}
fact[0] = rev[0] = 1;
for (int i = 1; i < MAXN; ++i) {
fact[i] = fact[i - 1];
mulMod(fact[i], i);
rev[i] = binPow(fact[i], MOD - 2);
}
dp[0][0][0] = 1;
for (int i = 1; i <= n; ++i) {
int p = 0, w = 0;
for (int c = arr[i].fi; c < arr[i].se; ++c) {
int lim = T[c + 1] - T[c];
for (int cnt = 1; cnt <= i; ++cnt) {
int tmp = dp[0][c][cnt - 1];
mulMod(tmp, max(0, lim - cnt + 1));
addMod(dp[1][c][cnt], tmp);
}
while (p < c) {
for (int cnt = 0; cnt <= i; ++cnt) {
int tmp = dp[0][p][cnt];
mulMod(tmp, rev[cnt]);
addMod(w, tmp);
}
++p;
}
int tmp = w;
mulMod(tmp, lim);
addMod(dp[1][c][1], tmp);
}
for (int c = 0; c < T.size(); ++c) {
for (int cnt = 0; cnt <= i; ++cnt) {
addMod(dp[0][c][cnt], dp[1][c][cnt]);
dp[1][c][cnt] = 0;
}
}
}
int ans = 0;
for (int c = 1; c + 1 < T.size(); ++c) {
for (int cnt = 1; cnt <= n; ++cnt) {
int tmp = dp[0][c][cnt];
mulMod(tmp, rev[cnt]);
addMod(ans, tmp);
}
}
printf("%d\n", ans);
}
int main() {
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message
boat.cpp: In function 'void solve()':
boat.cpp:118:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int c = 0; c < T.size(); ++c) {
~~^~~~~~~~~~
boat.cpp:128:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int c = 1; c + 1 < T.size(); ++c) {
~~~~~~^~~~~~~~~~
boat.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:67: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 |
440 ms |
8184 KB |
Output is correct |
2 |
Correct |
436 ms |
8184 KB |
Output is correct |
3 |
Correct |
426 ms |
8312 KB |
Output is correct |
4 |
Correct |
416 ms |
8184 KB |
Output is correct |
5 |
Correct |
437 ms |
8264 KB |
Output is correct |
6 |
Correct |
502 ms |
8312 KB |
Output is correct |
7 |
Correct |
497 ms |
8316 KB |
Output is correct |
8 |
Correct |
497 ms |
8312 KB |
Output is correct |
9 |
Correct |
486 ms |
8184 KB |
Output is correct |
10 |
Correct |
516 ms |
8312 KB |
Output is correct |
11 |
Correct |
492 ms |
8312 KB |
Output is correct |
12 |
Correct |
477 ms |
8312 KB |
Output is correct |
13 |
Correct |
487 ms |
8312 KB |
Output is correct |
14 |
Correct |
498 ms |
8440 KB |
Output is correct |
15 |
Correct |
518 ms |
8184 KB |
Output is correct |
16 |
Correct |
61 ms |
1784 KB |
Output is correct |
17 |
Correct |
64 ms |
1912 KB |
Output is correct |
18 |
Correct |
62 ms |
1784 KB |
Output is correct |
19 |
Correct |
63 ms |
1784 KB |
Output is correct |
20 |
Correct |
65 ms |
1660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
440 ms |
8184 KB |
Output is correct |
2 |
Correct |
436 ms |
8184 KB |
Output is correct |
3 |
Correct |
426 ms |
8312 KB |
Output is correct |
4 |
Correct |
416 ms |
8184 KB |
Output is correct |
5 |
Correct |
437 ms |
8264 KB |
Output is correct |
6 |
Correct |
502 ms |
8312 KB |
Output is correct |
7 |
Correct |
497 ms |
8316 KB |
Output is correct |
8 |
Correct |
497 ms |
8312 KB |
Output is correct |
9 |
Correct |
486 ms |
8184 KB |
Output is correct |
10 |
Correct |
516 ms |
8312 KB |
Output is correct |
11 |
Correct |
492 ms |
8312 KB |
Output is correct |
12 |
Correct |
477 ms |
8312 KB |
Output is correct |
13 |
Correct |
487 ms |
8312 KB |
Output is correct |
14 |
Correct |
498 ms |
8440 KB |
Output is correct |
15 |
Correct |
518 ms |
8184 KB |
Output is correct |
16 |
Correct |
61 ms |
1784 KB |
Output is correct |
17 |
Correct |
64 ms |
1912 KB |
Output is correct |
18 |
Correct |
62 ms |
1784 KB |
Output is correct |
19 |
Correct |
63 ms |
1784 KB |
Output is correct |
20 |
Correct |
65 ms |
1660 KB |
Output is correct |
21 |
Correct |
666 ms |
7576 KB |
Output is correct |
22 |
Correct |
706 ms |
7792 KB |
Output is correct |
23 |
Correct |
640 ms |
7752 KB |
Output is correct |
24 |
Correct |
755 ms |
7544 KB |
Output is correct |
25 |
Correct |
585 ms |
7544 KB |
Output is correct |
26 |
Correct |
842 ms |
7416 KB |
Output is correct |
27 |
Correct |
874 ms |
7544 KB |
Output is correct |
28 |
Correct |
711 ms |
7416 KB |
Output is correct |
29 |
Correct |
708 ms |
7416 KB |
Output is correct |
30 |
Correct |
704 ms |
8312 KB |
Output is correct |
31 |
Correct |
525 ms |
8312 KB |
Output is correct |
32 |
Correct |
512 ms |
8312 KB |
Output is correct |
33 |
Correct |
580 ms |
8312 KB |
Output is correct |
34 |
Correct |
521 ms |
8312 KB |
Output is correct |
35 |
Correct |
451 ms |
8312 KB |
Output is correct |
36 |
Correct |
447 ms |
8312 KB |
Output is correct |
37 |
Correct |
451 ms |
8184 KB |
Output is correct |
38 |
Correct |
640 ms |
8440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1916 KB |
Output is correct |
2 |
Correct |
16 ms |
1912 KB |
Output is correct |
3 |
Correct |
11 ms |
1912 KB |
Output is correct |
4 |
Correct |
20 ms |
1912 KB |
Output is correct |
5 |
Correct |
11 ms |
1912 KB |
Output is correct |
6 |
Correct |
14 ms |
1912 KB |
Output is correct |
7 |
Correct |
16 ms |
1912 KB |
Output is correct |
8 |
Correct |
12 ms |
1912 KB |
Output is correct |
9 |
Correct |
12 ms |
1912 KB |
Output is correct |
10 |
Correct |
12 ms |
1912 KB |
Output is correct |
11 |
Correct |
11 ms |
1916 KB |
Output is correct |
12 |
Correct |
10 ms |
1912 KB |
Output is correct |
13 |
Correct |
11 ms |
1912 KB |
Output is correct |
14 |
Correct |
11 ms |
1912 KB |
Output is correct |
15 |
Correct |
11 ms |
1912 KB |
Output is correct |
16 |
Correct |
9 ms |
1272 KB |
Output is correct |
17 |
Correct |
8 ms |
1272 KB |
Output is correct |
18 |
Correct |
8 ms |
1272 KB |
Output is correct |
19 |
Correct |
9 ms |
1272 KB |
Output is correct |
20 |
Correct |
10 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
440 ms |
8184 KB |
Output is correct |
2 |
Correct |
436 ms |
8184 KB |
Output is correct |
3 |
Correct |
426 ms |
8312 KB |
Output is correct |
4 |
Correct |
416 ms |
8184 KB |
Output is correct |
5 |
Correct |
437 ms |
8264 KB |
Output is correct |
6 |
Correct |
502 ms |
8312 KB |
Output is correct |
7 |
Correct |
497 ms |
8316 KB |
Output is correct |
8 |
Correct |
497 ms |
8312 KB |
Output is correct |
9 |
Correct |
486 ms |
8184 KB |
Output is correct |
10 |
Correct |
516 ms |
8312 KB |
Output is correct |
11 |
Correct |
492 ms |
8312 KB |
Output is correct |
12 |
Correct |
477 ms |
8312 KB |
Output is correct |
13 |
Correct |
487 ms |
8312 KB |
Output is correct |
14 |
Correct |
498 ms |
8440 KB |
Output is correct |
15 |
Correct |
518 ms |
8184 KB |
Output is correct |
16 |
Correct |
61 ms |
1784 KB |
Output is correct |
17 |
Correct |
64 ms |
1912 KB |
Output is correct |
18 |
Correct |
62 ms |
1784 KB |
Output is correct |
19 |
Correct |
63 ms |
1784 KB |
Output is correct |
20 |
Correct |
65 ms |
1660 KB |
Output is correct |
21 |
Correct |
666 ms |
7576 KB |
Output is correct |
22 |
Correct |
706 ms |
7792 KB |
Output is correct |
23 |
Correct |
640 ms |
7752 KB |
Output is correct |
24 |
Correct |
755 ms |
7544 KB |
Output is correct |
25 |
Correct |
585 ms |
7544 KB |
Output is correct |
26 |
Correct |
842 ms |
7416 KB |
Output is correct |
27 |
Correct |
874 ms |
7544 KB |
Output is correct |
28 |
Correct |
711 ms |
7416 KB |
Output is correct |
29 |
Correct |
708 ms |
7416 KB |
Output is correct |
30 |
Correct |
704 ms |
8312 KB |
Output is correct |
31 |
Correct |
525 ms |
8312 KB |
Output is correct |
32 |
Correct |
512 ms |
8312 KB |
Output is correct |
33 |
Correct |
580 ms |
8312 KB |
Output is correct |
34 |
Correct |
521 ms |
8312 KB |
Output is correct |
35 |
Correct |
451 ms |
8312 KB |
Output is correct |
36 |
Correct |
447 ms |
8312 KB |
Output is correct |
37 |
Correct |
451 ms |
8184 KB |
Output is correct |
38 |
Correct |
640 ms |
8440 KB |
Output is correct |
39 |
Correct |
14 ms |
1916 KB |
Output is correct |
40 |
Correct |
16 ms |
1912 KB |
Output is correct |
41 |
Correct |
11 ms |
1912 KB |
Output is correct |
42 |
Correct |
20 ms |
1912 KB |
Output is correct |
43 |
Correct |
11 ms |
1912 KB |
Output is correct |
44 |
Correct |
14 ms |
1912 KB |
Output is correct |
45 |
Correct |
16 ms |
1912 KB |
Output is correct |
46 |
Correct |
12 ms |
1912 KB |
Output is correct |
47 |
Correct |
12 ms |
1912 KB |
Output is correct |
48 |
Correct |
12 ms |
1912 KB |
Output is correct |
49 |
Correct |
11 ms |
1916 KB |
Output is correct |
50 |
Correct |
10 ms |
1912 KB |
Output is correct |
51 |
Correct |
11 ms |
1912 KB |
Output is correct |
52 |
Correct |
11 ms |
1912 KB |
Output is correct |
53 |
Correct |
11 ms |
1912 KB |
Output is correct |
54 |
Correct |
9 ms |
1272 KB |
Output is correct |
55 |
Correct |
8 ms |
1272 KB |
Output is correct |
56 |
Correct |
8 ms |
1272 KB |
Output is correct |
57 |
Correct |
9 ms |
1272 KB |
Output is correct |
58 |
Correct |
10 ms |
1144 KB |
Output is correct |
59 |
Correct |
645 ms |
8400 KB |
Output is correct |
60 |
Correct |
628 ms |
8440 KB |
Output is correct |
61 |
Correct |
634 ms |
8312 KB |
Output is correct |
62 |
Correct |
638 ms |
8312 KB |
Output is correct |
63 |
Correct |
662 ms |
8316 KB |
Output is correct |
64 |
Correct |
778 ms |
8440 KB |
Output is correct |
65 |
Correct |
789 ms |
8440 KB |
Output is correct |
66 |
Correct |
783 ms |
8312 KB |
Output is correct |
67 |
Correct |
774 ms |
8312 KB |
Output is correct |
68 |
Correct |
765 ms |
8312 KB |
Output is correct |
69 |
Correct |
637 ms |
8312 KB |
Output is correct |
70 |
Correct |
628 ms |
8312 KB |
Output is correct |
71 |
Correct |
609 ms |
8184 KB |
Output is correct |
72 |
Correct |
637 ms |
8312 KB |
Output is correct |
73 |
Correct |
635 ms |
8312 KB |
Output is correct |
74 |
Correct |
111 ms |
1912 KB |
Output is correct |
75 |
Correct |
110 ms |
1784 KB |
Output is correct |
76 |
Correct |
111 ms |
1784 KB |
Output is correct |
77 |
Correct |
111 ms |
1784 KB |
Output is correct |
78 |
Correct |
110 ms |
1784 KB |
Output is correct |