// In the name of god
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template < class T > using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define lc(x) (x) << 1
#define rc(x) (x) << 1 | 1
#define F first
#define S second
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define mp make_pair
ll poww(ll a, ll b, ll md) {
ll ans = 1;
for(; b; b >>= 1, a = a * a % md){
if(b & 1){
ans = ans * a % md;
}
}
return ans % md;
}
const int MAXN = 1000 + 10;
const int MAXLG = 18;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
int n, a[MAXN], b[MAXN];
vector<int> vec;
ll dp[MAXN][MAXN], x[MAXN], ans, inv[MAXN];
int main()
{
scanf("%d", &n);
for(int i = 0; i <= n; i++){
inv[i] = poww(i, MOD - 2, MOD);
}
for(int i = 1; i <= n; i++){
scanf("%d %d", a + i, b + i);
b[i]++;
vec.push_back(b[i]);
vec.push_back(a[i]);
}
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
for(int i = 1; i < (int)vec.size(); i++){
x[i] = vec[i] - vec[i - 1];
}
for(int i = 1; i <= n; i++){
a[i] = lower_bound(all(vec), a[i]) - vec.begin();
b[i] = lower_bound(all(vec), b[i]) - vec.begin();
}
for(int i = 0; i < (int)vec.size(); i++){
dp[0][i] = 1;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j < (int)vec.size(); j++){
if(!(a[i] < j && b[i] >= j)){
continue;
}
ll tmp = x[j], kmp = x[j], vlc = 1;
for(int k = i - 1; k >= 0; k--){
dp[i][j] += (dp[k][j - 1] * tmp) % MOD;
dp[i][j] %= MOD;
if(a[k] < j && b[k] >= j){
kmp++;
vlc++;
kmp %= MOD;
vlc %= MOD;
tmp *= (kmp * inv[vlc]) % MOD;
tmp %= MOD;
}
}
//printf(":: %d %d %lld\n", i, j, dp[i][j]);
}
for(int j = 1; j < (int)vec.size();j++){
dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
}
for(int i = 1; i <= n; i++){
ans += dp[i][(int)vec.size() - 1];
ans %= MOD;
}
printf("%lld\n", ans);
}
Compilation message
boat.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
3 | #pragma comment(linker, "/stack:200000000")
|
boat.cpp: In function 'int main()':
boat.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d %d", a + i, b + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4172 KB |
Output is correct |
2 |
Correct |
7 ms |
4172 KB |
Output is correct |
3 |
Correct |
7 ms |
4172 KB |
Output is correct |
4 |
Correct |
7 ms |
4172 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
7 ms |
4208 KB |
Output is correct |
7 |
Correct |
7 ms |
4300 KB |
Output is correct |
8 |
Correct |
8 ms |
4196 KB |
Output is correct |
9 |
Correct |
7 ms |
4172 KB |
Output is correct |
10 |
Correct |
8 ms |
4172 KB |
Output is correct |
11 |
Correct |
7 ms |
4204 KB |
Output is correct |
12 |
Correct |
7 ms |
4300 KB |
Output is correct |
13 |
Correct |
7 ms |
4300 KB |
Output is correct |
14 |
Correct |
7 ms |
4196 KB |
Output is correct |
15 |
Correct |
7 ms |
4208 KB |
Output is correct |
16 |
Correct |
4 ms |
3020 KB |
Output is correct |
17 |
Correct |
4 ms |
3020 KB |
Output is correct |
18 |
Correct |
4 ms |
3020 KB |
Output is correct |
19 |
Correct |
4 ms |
3020 KB |
Output is correct |
20 |
Correct |
4 ms |
3020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4172 KB |
Output is correct |
2 |
Correct |
7 ms |
4172 KB |
Output is correct |
3 |
Correct |
7 ms |
4172 KB |
Output is correct |
4 |
Correct |
7 ms |
4172 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
7 ms |
4208 KB |
Output is correct |
7 |
Correct |
7 ms |
4300 KB |
Output is correct |
8 |
Correct |
8 ms |
4196 KB |
Output is correct |
9 |
Correct |
7 ms |
4172 KB |
Output is correct |
10 |
Correct |
8 ms |
4172 KB |
Output is correct |
11 |
Correct |
7 ms |
4204 KB |
Output is correct |
12 |
Correct |
7 ms |
4300 KB |
Output is correct |
13 |
Correct |
7 ms |
4300 KB |
Output is correct |
14 |
Correct |
7 ms |
4196 KB |
Output is correct |
15 |
Correct |
7 ms |
4208 KB |
Output is correct |
16 |
Correct |
4 ms |
3020 KB |
Output is correct |
17 |
Correct |
4 ms |
3020 KB |
Output is correct |
18 |
Correct |
4 ms |
3020 KB |
Output is correct |
19 |
Correct |
4 ms |
3020 KB |
Output is correct |
20 |
Correct |
4 ms |
3020 KB |
Output is correct |
21 |
Correct |
450 ms |
4292 KB |
Output is correct |
22 |
Correct |
412 ms |
4164 KB |
Output is correct |
23 |
Correct |
387 ms |
4200 KB |
Output is correct |
24 |
Correct |
415 ms |
4192 KB |
Output is correct |
25 |
Correct |
468 ms |
4176 KB |
Output is correct |
26 |
Correct |
711 ms |
4176 KB |
Output is correct |
27 |
Correct |
746 ms |
4396 KB |
Output is correct |
28 |
Correct |
703 ms |
4184 KB |
Output is correct |
29 |
Correct |
692 ms |
4172 KB |
Output is correct |
30 |
Correct |
8 ms |
4300 KB |
Output is correct |
31 |
Correct |
8 ms |
4276 KB |
Output is correct |
32 |
Correct |
8 ms |
4168 KB |
Output is correct |
33 |
Correct |
8 ms |
4236 KB |
Output is correct |
34 |
Correct |
9 ms |
4312 KB |
Output is correct |
35 |
Correct |
9 ms |
4300 KB |
Output is correct |
36 |
Correct |
9 ms |
4300 KB |
Output is correct |
37 |
Correct |
9 ms |
4304 KB |
Output is correct |
38 |
Correct |
8 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
844 KB |
Output is correct |
2 |
Correct |
4 ms |
844 KB |
Output is correct |
3 |
Correct |
4 ms |
844 KB |
Output is correct |
4 |
Correct |
4 ms |
844 KB |
Output is correct |
5 |
Correct |
5 ms |
824 KB |
Output is correct |
6 |
Correct |
7 ms |
844 KB |
Output is correct |
7 |
Correct |
7 ms |
844 KB |
Output is correct |
8 |
Correct |
7 ms |
844 KB |
Output is correct |
9 |
Correct |
7 ms |
844 KB |
Output is correct |
10 |
Correct |
8 ms |
844 KB |
Output is correct |
11 |
Correct |
4 ms |
844 KB |
Output is correct |
12 |
Correct |
4 ms |
844 KB |
Output is correct |
13 |
Correct |
4 ms |
844 KB |
Output is correct |
14 |
Correct |
4 ms |
844 KB |
Output is correct |
15 |
Correct |
5 ms |
844 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
3 ms |
716 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
19 |
Correct |
3 ms |
716 KB |
Output is correct |
20 |
Correct |
3 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4172 KB |
Output is correct |
2 |
Correct |
7 ms |
4172 KB |
Output is correct |
3 |
Correct |
7 ms |
4172 KB |
Output is correct |
4 |
Correct |
7 ms |
4172 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
7 ms |
4208 KB |
Output is correct |
7 |
Correct |
7 ms |
4300 KB |
Output is correct |
8 |
Correct |
8 ms |
4196 KB |
Output is correct |
9 |
Correct |
7 ms |
4172 KB |
Output is correct |
10 |
Correct |
8 ms |
4172 KB |
Output is correct |
11 |
Correct |
7 ms |
4204 KB |
Output is correct |
12 |
Correct |
7 ms |
4300 KB |
Output is correct |
13 |
Correct |
7 ms |
4300 KB |
Output is correct |
14 |
Correct |
7 ms |
4196 KB |
Output is correct |
15 |
Correct |
7 ms |
4208 KB |
Output is correct |
16 |
Correct |
4 ms |
3020 KB |
Output is correct |
17 |
Correct |
4 ms |
3020 KB |
Output is correct |
18 |
Correct |
4 ms |
3020 KB |
Output is correct |
19 |
Correct |
4 ms |
3020 KB |
Output is correct |
20 |
Correct |
4 ms |
3020 KB |
Output is correct |
21 |
Correct |
450 ms |
4292 KB |
Output is correct |
22 |
Correct |
412 ms |
4164 KB |
Output is correct |
23 |
Correct |
387 ms |
4200 KB |
Output is correct |
24 |
Correct |
415 ms |
4192 KB |
Output is correct |
25 |
Correct |
468 ms |
4176 KB |
Output is correct |
26 |
Correct |
711 ms |
4176 KB |
Output is correct |
27 |
Correct |
746 ms |
4396 KB |
Output is correct |
28 |
Correct |
703 ms |
4184 KB |
Output is correct |
29 |
Correct |
692 ms |
4172 KB |
Output is correct |
30 |
Correct |
8 ms |
4300 KB |
Output is correct |
31 |
Correct |
8 ms |
4276 KB |
Output is correct |
32 |
Correct |
8 ms |
4168 KB |
Output is correct |
33 |
Correct |
8 ms |
4236 KB |
Output is correct |
34 |
Correct |
9 ms |
4312 KB |
Output is correct |
35 |
Correct |
9 ms |
4300 KB |
Output is correct |
36 |
Correct |
9 ms |
4300 KB |
Output is correct |
37 |
Correct |
9 ms |
4304 KB |
Output is correct |
38 |
Correct |
8 ms |
4300 KB |
Output is correct |
39 |
Correct |
4 ms |
844 KB |
Output is correct |
40 |
Correct |
4 ms |
844 KB |
Output is correct |
41 |
Correct |
4 ms |
844 KB |
Output is correct |
42 |
Correct |
4 ms |
844 KB |
Output is correct |
43 |
Correct |
5 ms |
824 KB |
Output is correct |
44 |
Correct |
7 ms |
844 KB |
Output is correct |
45 |
Correct |
7 ms |
844 KB |
Output is correct |
46 |
Correct |
7 ms |
844 KB |
Output is correct |
47 |
Correct |
7 ms |
844 KB |
Output is correct |
48 |
Correct |
8 ms |
844 KB |
Output is correct |
49 |
Correct |
4 ms |
844 KB |
Output is correct |
50 |
Correct |
4 ms |
844 KB |
Output is correct |
51 |
Correct |
4 ms |
844 KB |
Output is correct |
52 |
Correct |
4 ms |
844 KB |
Output is correct |
53 |
Correct |
5 ms |
844 KB |
Output is correct |
54 |
Correct |
3 ms |
716 KB |
Output is correct |
55 |
Correct |
3 ms |
716 KB |
Output is correct |
56 |
Correct |
3 ms |
716 KB |
Output is correct |
57 |
Correct |
3 ms |
716 KB |
Output is correct |
58 |
Correct |
3 ms |
716 KB |
Output is correct |
59 |
Correct |
465 ms |
4352 KB |
Output is correct |
60 |
Correct |
435 ms |
4208 KB |
Output is correct |
61 |
Correct |
399 ms |
4400 KB |
Output is correct |
62 |
Correct |
447 ms |
4236 KB |
Output is correct |
63 |
Correct |
436 ms |
4204 KB |
Output is correct |
64 |
Correct |
816 ms |
4468 KB |
Output is correct |
65 |
Correct |
810 ms |
4264 KB |
Output is correct |
66 |
Correct |
805 ms |
4372 KB |
Output is correct |
67 |
Correct |
790 ms |
4240 KB |
Output is correct |
68 |
Correct |
797 ms |
4292 KB |
Output is correct |
69 |
Correct |
353 ms |
4256 KB |
Output is correct |
70 |
Correct |
355 ms |
4236 KB |
Output is correct |
71 |
Correct |
351 ms |
4220 KB |
Output is correct |
72 |
Correct |
364 ms |
4480 KB |
Output is correct |
73 |
Correct |
392 ms |
4280 KB |
Output is correct |
74 |
Correct |
91 ms |
3000 KB |
Output is correct |
75 |
Correct |
84 ms |
2972 KB |
Output is correct |
76 |
Correct |
89 ms |
3016 KB |
Output is correct |
77 |
Correct |
88 ms |
2984 KB |
Output is correct |
78 |
Correct |
95 ms |
2992 KB |
Output is correct |