# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
554359 |
2022-04-28T08:41:39 Z |
AmShZ |
Boat (APIO16_boat) |
C++11 |
|
1101 ms |
16456 KB |
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
# define F first
# define S second
# define endl '\n'
# define sep ' '
# define pb push_back
# define fast_io ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
const ll md = 1e9 + 7;//998244353;
const int xn = 1e3 + 10;
const int xm = 1e5 + 10;
const int SQ = 320;
const int sq = 1e3 + 10;
const ll inf = 1e18 + 10;
ll power(ll a, ll b) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md : power(a * a % md, b / 2) % md));}
ll zarb(ll a, ll b){return (a * b + 10 * md) % md;}
ll jaam(ll a, ll b){return (a + b + 10 * md) % md;}
int n, C[xn][xn], invi[xn], CR[xn][xn];
int F[xn][xn], ted, dp[xn][xn];
pii A[xn];
set <int> st;
vector <int> vec;
vector <pii> seg;
void Solve(int ind, int t){
C[ind][0] = F[ind][0] = 1;
for (int i = 1; i <= min(n, t); ++ i)
C[ind][i] = 1ll * C[ind][i - 1] * (t - i + 1) % md * invi[i] % md;
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= min(i, t); ++ j)
F[ind][i] = (F[ind][i] + 1ll * CR[i - 1][j - 1] * C[ind][j] % md) % md;
}
int main(){
fast_io;
for (int i = 0; i < xn; ++ i)
CR[i][0] = 1;
for (int i = 1; i < xn; ++ i)
for (int j = 1; j <= i; ++ j)
CR[i][j] = (CR[i - 1][j] + CR[i - 1][j - 1]) % md;
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> A[i].F >> A[i].S, ++ A[i].S;
for (int i = 1; i <= n; i ++)
st.insert(A[i].F), st.insert(A[i].S);
for (int x : st)
vec.push_back(x);
for (int i = 1; i < vec.size(); i ++)
seg.emplace_back(vec[i - 1], vec[i]);
for (int i = 1; i < xn; i ++)
invi[i] = power(i, md - 2);
for (int i = 0; i < seg.size(); i ++)
Solve(i, seg[i].S - seg[i].F);
for (int i = 0; i < xn; ++ i)
dp[i][0] = dp[0][i] = 1;
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= seg.size(); j ++){
dp[i][j] = dp[i][j - 1], ted = 0;
for (int k = i; k >= 1; -- k)
if (A[k].F <= seg[j - 1].F && seg[j - 1].S <= A[k].S)
dp[i][j] = (dp[i][j] + 1ll * dp[k - 1][j - 1] * F[j - 1][++ ted] % md) % md;
}
}
cout << (dp[n][seg.size()] + md - 1) % md << endl;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 1; i < vec.size(); i ++)
| ~~^~~~~~~~~~~~
boat.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < seg.size(); i ++)
| ~~^~~~~~~~~~~~
boat.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int j = 1; j <= seg.size(); j ++){
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
554 ms |
16172 KB |
Output is correct |
2 |
Correct |
583 ms |
16284 KB |
Output is correct |
3 |
Correct |
527 ms |
16276 KB |
Output is correct |
4 |
Correct |
529 ms |
16280 KB |
Output is correct |
5 |
Correct |
530 ms |
16328 KB |
Output is correct |
6 |
Correct |
430 ms |
16280 KB |
Output is correct |
7 |
Correct |
412 ms |
16328 KB |
Output is correct |
8 |
Correct |
422 ms |
16376 KB |
Output is correct |
9 |
Correct |
454 ms |
16276 KB |
Output is correct |
10 |
Correct |
411 ms |
16204 KB |
Output is correct |
11 |
Correct |
424 ms |
16284 KB |
Output is correct |
12 |
Correct |
429 ms |
16332 KB |
Output is correct |
13 |
Correct |
411 ms |
16204 KB |
Output is correct |
14 |
Correct |
422 ms |
16248 KB |
Output is correct |
15 |
Correct |
433 ms |
16276 KB |
Output is correct |
16 |
Correct |
110 ms |
9684 KB |
Output is correct |
17 |
Correct |
107 ms |
9732 KB |
Output is correct |
18 |
Correct |
102 ms |
9768 KB |
Output is correct |
19 |
Correct |
109 ms |
9832 KB |
Output is correct |
20 |
Correct |
107 ms |
9788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
554 ms |
16172 KB |
Output is correct |
2 |
Correct |
583 ms |
16284 KB |
Output is correct |
3 |
Correct |
527 ms |
16276 KB |
Output is correct |
4 |
Correct |
529 ms |
16280 KB |
Output is correct |
5 |
Correct |
530 ms |
16328 KB |
Output is correct |
6 |
Correct |
430 ms |
16280 KB |
Output is correct |
7 |
Correct |
412 ms |
16328 KB |
Output is correct |
8 |
Correct |
422 ms |
16376 KB |
Output is correct |
9 |
Correct |
454 ms |
16276 KB |
Output is correct |
10 |
Correct |
411 ms |
16204 KB |
Output is correct |
11 |
Correct |
424 ms |
16284 KB |
Output is correct |
12 |
Correct |
429 ms |
16332 KB |
Output is correct |
13 |
Correct |
411 ms |
16204 KB |
Output is correct |
14 |
Correct |
422 ms |
16248 KB |
Output is correct |
15 |
Correct |
433 ms |
16276 KB |
Output is correct |
16 |
Correct |
110 ms |
9684 KB |
Output is correct |
17 |
Correct |
107 ms |
9732 KB |
Output is correct |
18 |
Correct |
102 ms |
9768 KB |
Output is correct |
19 |
Correct |
109 ms |
9832 KB |
Output is correct |
20 |
Correct |
107 ms |
9788 KB |
Output is correct |
21 |
Correct |
359 ms |
15576 KB |
Output is correct |
22 |
Correct |
359 ms |
15692 KB |
Output is correct |
23 |
Correct |
337 ms |
15532 KB |
Output is correct |
24 |
Correct |
351 ms |
15564 KB |
Output is correct |
25 |
Correct |
361 ms |
15636 KB |
Output is correct |
26 |
Correct |
453 ms |
15320 KB |
Output is correct |
27 |
Correct |
454 ms |
15444 KB |
Output is correct |
28 |
Correct |
447 ms |
15316 KB |
Output is correct |
29 |
Correct |
452 ms |
15288 KB |
Output is correct |
30 |
Correct |
408 ms |
16136 KB |
Output is correct |
31 |
Correct |
398 ms |
16188 KB |
Output is correct |
32 |
Correct |
405 ms |
16256 KB |
Output is correct |
33 |
Correct |
402 ms |
16204 KB |
Output is correct |
34 |
Correct |
402 ms |
16308 KB |
Output is correct |
35 |
Correct |
520 ms |
16332 KB |
Output is correct |
36 |
Correct |
517 ms |
16268 KB |
Output is correct |
37 |
Correct |
511 ms |
16280 KB |
Output is correct |
38 |
Correct |
506 ms |
16244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
9888 KB |
Output is correct |
2 |
Correct |
13 ms |
9828 KB |
Output is correct |
3 |
Correct |
14 ms |
9812 KB |
Output is correct |
4 |
Correct |
13 ms |
9812 KB |
Output is correct |
5 |
Correct |
13 ms |
9832 KB |
Output is correct |
6 |
Correct |
14 ms |
9912 KB |
Output is correct |
7 |
Correct |
14 ms |
9912 KB |
Output is correct |
8 |
Correct |
15 ms |
9812 KB |
Output is correct |
9 |
Correct |
15 ms |
9872 KB |
Output is correct |
10 |
Correct |
15 ms |
9812 KB |
Output is correct |
11 |
Correct |
14 ms |
9872 KB |
Output is correct |
12 |
Correct |
13 ms |
9916 KB |
Output is correct |
13 |
Correct |
14 ms |
9832 KB |
Output is correct |
14 |
Correct |
14 ms |
9836 KB |
Output is correct |
15 |
Correct |
14 ms |
9836 KB |
Output is correct |
16 |
Correct |
9 ms |
9180 KB |
Output is correct |
17 |
Correct |
9 ms |
9172 KB |
Output is correct |
18 |
Correct |
10 ms |
9192 KB |
Output is correct |
19 |
Correct |
9 ms |
9172 KB |
Output is correct |
20 |
Correct |
9 ms |
9188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
554 ms |
16172 KB |
Output is correct |
2 |
Correct |
583 ms |
16284 KB |
Output is correct |
3 |
Correct |
527 ms |
16276 KB |
Output is correct |
4 |
Correct |
529 ms |
16280 KB |
Output is correct |
5 |
Correct |
530 ms |
16328 KB |
Output is correct |
6 |
Correct |
430 ms |
16280 KB |
Output is correct |
7 |
Correct |
412 ms |
16328 KB |
Output is correct |
8 |
Correct |
422 ms |
16376 KB |
Output is correct |
9 |
Correct |
454 ms |
16276 KB |
Output is correct |
10 |
Correct |
411 ms |
16204 KB |
Output is correct |
11 |
Correct |
424 ms |
16284 KB |
Output is correct |
12 |
Correct |
429 ms |
16332 KB |
Output is correct |
13 |
Correct |
411 ms |
16204 KB |
Output is correct |
14 |
Correct |
422 ms |
16248 KB |
Output is correct |
15 |
Correct |
433 ms |
16276 KB |
Output is correct |
16 |
Correct |
110 ms |
9684 KB |
Output is correct |
17 |
Correct |
107 ms |
9732 KB |
Output is correct |
18 |
Correct |
102 ms |
9768 KB |
Output is correct |
19 |
Correct |
109 ms |
9832 KB |
Output is correct |
20 |
Correct |
107 ms |
9788 KB |
Output is correct |
21 |
Correct |
359 ms |
15576 KB |
Output is correct |
22 |
Correct |
359 ms |
15692 KB |
Output is correct |
23 |
Correct |
337 ms |
15532 KB |
Output is correct |
24 |
Correct |
351 ms |
15564 KB |
Output is correct |
25 |
Correct |
361 ms |
15636 KB |
Output is correct |
26 |
Correct |
453 ms |
15320 KB |
Output is correct |
27 |
Correct |
454 ms |
15444 KB |
Output is correct |
28 |
Correct |
447 ms |
15316 KB |
Output is correct |
29 |
Correct |
452 ms |
15288 KB |
Output is correct |
30 |
Correct |
408 ms |
16136 KB |
Output is correct |
31 |
Correct |
398 ms |
16188 KB |
Output is correct |
32 |
Correct |
405 ms |
16256 KB |
Output is correct |
33 |
Correct |
402 ms |
16204 KB |
Output is correct |
34 |
Correct |
402 ms |
16308 KB |
Output is correct |
35 |
Correct |
520 ms |
16332 KB |
Output is correct |
36 |
Correct |
517 ms |
16268 KB |
Output is correct |
37 |
Correct |
511 ms |
16280 KB |
Output is correct |
38 |
Correct |
506 ms |
16244 KB |
Output is correct |
39 |
Correct |
15 ms |
9888 KB |
Output is correct |
40 |
Correct |
13 ms |
9828 KB |
Output is correct |
41 |
Correct |
14 ms |
9812 KB |
Output is correct |
42 |
Correct |
13 ms |
9812 KB |
Output is correct |
43 |
Correct |
13 ms |
9832 KB |
Output is correct |
44 |
Correct |
14 ms |
9912 KB |
Output is correct |
45 |
Correct |
14 ms |
9912 KB |
Output is correct |
46 |
Correct |
15 ms |
9812 KB |
Output is correct |
47 |
Correct |
15 ms |
9872 KB |
Output is correct |
48 |
Correct |
15 ms |
9812 KB |
Output is correct |
49 |
Correct |
14 ms |
9872 KB |
Output is correct |
50 |
Correct |
13 ms |
9916 KB |
Output is correct |
51 |
Correct |
14 ms |
9832 KB |
Output is correct |
52 |
Correct |
14 ms |
9836 KB |
Output is correct |
53 |
Correct |
14 ms |
9836 KB |
Output is correct |
54 |
Correct |
9 ms |
9180 KB |
Output is correct |
55 |
Correct |
9 ms |
9172 KB |
Output is correct |
56 |
Correct |
10 ms |
9192 KB |
Output is correct |
57 |
Correct |
9 ms |
9172 KB |
Output is correct |
58 |
Correct |
9 ms |
9188 KB |
Output is correct |
59 |
Correct |
974 ms |
16280 KB |
Output is correct |
60 |
Correct |
922 ms |
16336 KB |
Output is correct |
61 |
Correct |
939 ms |
16456 KB |
Output is correct |
62 |
Correct |
952 ms |
16412 KB |
Output is correct |
63 |
Correct |
931 ms |
16228 KB |
Output is correct |
64 |
Correct |
1054 ms |
16352 KB |
Output is correct |
65 |
Correct |
1064 ms |
16284 KB |
Output is correct |
66 |
Correct |
1059 ms |
16420 KB |
Output is correct |
67 |
Correct |
1063 ms |
16256 KB |
Output is correct |
68 |
Correct |
1101 ms |
16280 KB |
Output is correct |
69 |
Correct |
949 ms |
16368 KB |
Output is correct |
70 |
Correct |
979 ms |
16308 KB |
Output is correct |
71 |
Correct |
981 ms |
16384 KB |
Output is correct |
72 |
Correct |
972 ms |
16360 KB |
Output is correct |
73 |
Correct |
969 ms |
16224 KB |
Output is correct |
74 |
Correct |
140 ms |
9676 KB |
Output is correct |
75 |
Correct |
155 ms |
9772 KB |
Output is correct |
76 |
Correct |
150 ms |
9756 KB |
Output is correct |
77 |
Correct |
145 ms |
9684 KB |
Output is correct |
78 |
Correct |
141 ms |
9656 KB |
Output is correct |