# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
499803 |
2021-12-29T13:16:25 Z |
Stickfish |
Boat (APIO16_boat) |
C++17 |
|
1763 ms |
12256 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const int MAXN = 502;
ll fact[MAXN * 2];
ll rfact[MAXN * 2];
ll pw(ll a, ll m) {
if (!m)
return 1;
a %= MOD;
if (m % 2)
return (a * pw(a, m - 1)) % MOD;
return pw(a * a, m / 2);
}
ll choose[MAXN * 2][MAXN];
ll dp[MAXN * 2][MAXN];
ll ndp[MAXN * 2][MAXN];
ll a[MAXN];
ll b[MAXN];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
rfact[0] = fact[0] = 1;
for (int i = 1; i < 2 * MAXN; ++i) {
fact[i] = (fact[i - 1] * i) % MOD;
rfact[i] = pw(fact[i], MOD - 2);
}
int n;
cin >> n;
vector<ll> cpr = {0};
vector<ll> sz;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
++b[i];
cpr.push_back(a[i]);
cpr.push_back(b[i]);
}
sort(cpr.begin(), cpr.end());
cpr.resize(unique(cpr.begin(), cpr.end()) - cpr.begin());
int m = cpr.size();
for (int i = 0; i + 1 < m; ++i) {
sz.push_back(cpr[i + 1] - cpr[i]);
choose[i][0] = 1;
for (ll k = 1; k <= n && k <= sz[i]; ++k) {
choose[i][k] = (choose[i][k - 1] * (sz[i] - k + 1)) % MOD;
choose[i][k] = (choose[i][k] * pw(k, MOD - 2)) % MOD;
//cout << sz[i] << ' ' << k << ": " << choose[i][k] << endl;
}
}
//printf("\n");
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(cpr.begin(), cpr.end(), a[i]) - cpr.begin();
b[i] = lower_bound(cpr.begin(), cpr.end(), b[i]) - cpr.begin();
}
for (int i = 0; i < m; ++i)
dp[i][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
for (int k = 0; k <= n; ++k)
ndp[j][k] = 0;
}
for (int j = b[i] - 1; j >= a[i]; --j) {
for (ll k = 1; k <= i + 1; ++k) {
ndp[j][k] = (ndp[j][k] + dp[j][k - 1]) % MOD;
}
}
for (int j = 1; j < m; ++j) {
ndp[j][0] = ndp[j - 1][0];
for (ll k = 1; k <= n; ++k) {
if (choose[j - 1][k] == 0)
break;
ndp[j][0] += ndp[j - 1][k] * choose[j - 1][k];
ndp[j][0] %= MOD;
}
ndp[j][0] %= MOD;
}
for (int j = 0; j < m; ++j) {
for (int k = 0; k <= n; ++k)
dp[j][k] = (dp[j][k] + ndp[j][k]) % MOD;
}
//printf("---\n");
//for (int j = 0; j < m; ++j) {
//for (int k = 0; k <= n; ++k)
//printf("%Ld ", dp[j][k]);
//printf("\n");
//}
}
cout << dp[m - 1][0] - 1 << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1113 ms |
12156 KB |
Output is correct |
2 |
Correct |
1103 ms |
12180 KB |
Output is correct |
3 |
Correct |
1143 ms |
12152 KB |
Output is correct |
4 |
Correct |
1154 ms |
12240 KB |
Output is correct |
5 |
Correct |
1087 ms |
12156 KB |
Output is correct |
6 |
Correct |
1091 ms |
12120 KB |
Output is correct |
7 |
Correct |
1108 ms |
12236 KB |
Output is correct |
8 |
Correct |
1134 ms |
12156 KB |
Output is correct |
9 |
Correct |
1104 ms |
12160 KB |
Output is correct |
10 |
Correct |
1077 ms |
12152 KB |
Output is correct |
11 |
Correct |
1136 ms |
12240 KB |
Output is correct |
12 |
Correct |
1080 ms |
12152 KB |
Output is correct |
13 |
Correct |
1081 ms |
12152 KB |
Output is correct |
14 |
Correct |
1100 ms |
12240 KB |
Output is correct |
15 |
Correct |
1140 ms |
12156 KB |
Output is correct |
16 |
Correct |
180 ms |
2500 KB |
Output is correct |
17 |
Correct |
193 ms |
2508 KB |
Output is correct |
18 |
Correct |
180 ms |
2508 KB |
Output is correct |
19 |
Correct |
188 ms |
2612 KB |
Output is correct |
20 |
Correct |
190 ms |
2548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1113 ms |
12156 KB |
Output is correct |
2 |
Correct |
1103 ms |
12180 KB |
Output is correct |
3 |
Correct |
1143 ms |
12152 KB |
Output is correct |
4 |
Correct |
1154 ms |
12240 KB |
Output is correct |
5 |
Correct |
1087 ms |
12156 KB |
Output is correct |
6 |
Correct |
1091 ms |
12120 KB |
Output is correct |
7 |
Correct |
1108 ms |
12236 KB |
Output is correct |
8 |
Correct |
1134 ms |
12156 KB |
Output is correct |
9 |
Correct |
1104 ms |
12160 KB |
Output is correct |
10 |
Correct |
1077 ms |
12152 KB |
Output is correct |
11 |
Correct |
1136 ms |
12240 KB |
Output is correct |
12 |
Correct |
1080 ms |
12152 KB |
Output is correct |
13 |
Correct |
1081 ms |
12152 KB |
Output is correct |
14 |
Correct |
1100 ms |
12240 KB |
Output is correct |
15 |
Correct |
1140 ms |
12156 KB |
Output is correct |
16 |
Correct |
180 ms |
2500 KB |
Output is correct |
17 |
Correct |
193 ms |
2508 KB |
Output is correct |
18 |
Correct |
180 ms |
2508 KB |
Output is correct |
19 |
Correct |
188 ms |
2612 KB |
Output is correct |
20 |
Correct |
190 ms |
2548 KB |
Output is correct |
21 |
Correct |
561 ms |
11116 KB |
Output is correct |
22 |
Correct |
530 ms |
11256 KB |
Output is correct |
23 |
Correct |
550 ms |
11076 KB |
Output is correct |
24 |
Correct |
536 ms |
10972 KB |
Output is correct |
25 |
Correct |
518 ms |
11040 KB |
Output is correct |
26 |
Correct |
554 ms |
10740 KB |
Output is correct |
27 |
Correct |
570 ms |
10944 KB |
Output is correct |
28 |
Correct |
545 ms |
10688 KB |
Output is correct |
29 |
Correct |
559 ms |
10700 KB |
Output is correct |
30 |
Correct |
1058 ms |
12132 KB |
Output is correct |
31 |
Correct |
1097 ms |
12148 KB |
Output is correct |
32 |
Correct |
1044 ms |
12120 KB |
Output is correct |
33 |
Correct |
1070 ms |
12248 KB |
Output is correct |
34 |
Correct |
1056 ms |
12112 KB |
Output is correct |
35 |
Correct |
1061 ms |
12124 KB |
Output is correct |
36 |
Correct |
1030 ms |
12124 KB |
Output is correct |
37 |
Correct |
1095 ms |
12028 KB |
Output is correct |
38 |
Correct |
1022 ms |
12096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
2624 KB |
Output is correct |
2 |
Correct |
20 ms |
2636 KB |
Output is correct |
3 |
Correct |
41 ms |
2612 KB |
Output is correct |
4 |
Correct |
19 ms |
2732 KB |
Output is correct |
5 |
Correct |
19 ms |
2736 KB |
Output is correct |
6 |
Correct |
19 ms |
2728 KB |
Output is correct |
7 |
Correct |
18 ms |
2636 KB |
Output is correct |
8 |
Correct |
19 ms |
2616 KB |
Output is correct |
9 |
Correct |
20 ms |
2640 KB |
Output is correct |
10 |
Correct |
18 ms |
2728 KB |
Output is correct |
11 |
Correct |
18 ms |
2728 KB |
Output is correct |
12 |
Correct |
19 ms |
2732 KB |
Output is correct |
13 |
Correct |
18 ms |
2736 KB |
Output is correct |
14 |
Correct |
18 ms |
2636 KB |
Output is correct |
15 |
Correct |
18 ms |
2728 KB |
Output is correct |
16 |
Correct |
9 ms |
1612 KB |
Output is correct |
17 |
Correct |
9 ms |
1612 KB |
Output is correct |
18 |
Correct |
10 ms |
1612 KB |
Output is correct |
19 |
Correct |
9 ms |
1624 KB |
Output is correct |
20 |
Correct |
12 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1113 ms |
12156 KB |
Output is correct |
2 |
Correct |
1103 ms |
12180 KB |
Output is correct |
3 |
Correct |
1143 ms |
12152 KB |
Output is correct |
4 |
Correct |
1154 ms |
12240 KB |
Output is correct |
5 |
Correct |
1087 ms |
12156 KB |
Output is correct |
6 |
Correct |
1091 ms |
12120 KB |
Output is correct |
7 |
Correct |
1108 ms |
12236 KB |
Output is correct |
8 |
Correct |
1134 ms |
12156 KB |
Output is correct |
9 |
Correct |
1104 ms |
12160 KB |
Output is correct |
10 |
Correct |
1077 ms |
12152 KB |
Output is correct |
11 |
Correct |
1136 ms |
12240 KB |
Output is correct |
12 |
Correct |
1080 ms |
12152 KB |
Output is correct |
13 |
Correct |
1081 ms |
12152 KB |
Output is correct |
14 |
Correct |
1100 ms |
12240 KB |
Output is correct |
15 |
Correct |
1140 ms |
12156 KB |
Output is correct |
16 |
Correct |
180 ms |
2500 KB |
Output is correct |
17 |
Correct |
193 ms |
2508 KB |
Output is correct |
18 |
Correct |
180 ms |
2508 KB |
Output is correct |
19 |
Correct |
188 ms |
2612 KB |
Output is correct |
20 |
Correct |
190 ms |
2548 KB |
Output is correct |
21 |
Correct |
561 ms |
11116 KB |
Output is correct |
22 |
Correct |
530 ms |
11256 KB |
Output is correct |
23 |
Correct |
550 ms |
11076 KB |
Output is correct |
24 |
Correct |
536 ms |
10972 KB |
Output is correct |
25 |
Correct |
518 ms |
11040 KB |
Output is correct |
26 |
Correct |
554 ms |
10740 KB |
Output is correct |
27 |
Correct |
570 ms |
10944 KB |
Output is correct |
28 |
Correct |
545 ms |
10688 KB |
Output is correct |
29 |
Correct |
559 ms |
10700 KB |
Output is correct |
30 |
Correct |
1058 ms |
12132 KB |
Output is correct |
31 |
Correct |
1097 ms |
12148 KB |
Output is correct |
32 |
Correct |
1044 ms |
12120 KB |
Output is correct |
33 |
Correct |
1070 ms |
12248 KB |
Output is correct |
34 |
Correct |
1056 ms |
12112 KB |
Output is correct |
35 |
Correct |
1061 ms |
12124 KB |
Output is correct |
36 |
Correct |
1030 ms |
12124 KB |
Output is correct |
37 |
Correct |
1095 ms |
12028 KB |
Output is correct |
38 |
Correct |
1022 ms |
12096 KB |
Output is correct |
39 |
Correct |
19 ms |
2624 KB |
Output is correct |
40 |
Correct |
20 ms |
2636 KB |
Output is correct |
41 |
Correct |
41 ms |
2612 KB |
Output is correct |
42 |
Correct |
19 ms |
2732 KB |
Output is correct |
43 |
Correct |
19 ms |
2736 KB |
Output is correct |
44 |
Correct |
19 ms |
2728 KB |
Output is correct |
45 |
Correct |
18 ms |
2636 KB |
Output is correct |
46 |
Correct |
19 ms |
2616 KB |
Output is correct |
47 |
Correct |
20 ms |
2640 KB |
Output is correct |
48 |
Correct |
18 ms |
2728 KB |
Output is correct |
49 |
Correct |
18 ms |
2728 KB |
Output is correct |
50 |
Correct |
19 ms |
2732 KB |
Output is correct |
51 |
Correct |
18 ms |
2736 KB |
Output is correct |
52 |
Correct |
18 ms |
2636 KB |
Output is correct |
53 |
Correct |
18 ms |
2728 KB |
Output is correct |
54 |
Correct |
9 ms |
1612 KB |
Output is correct |
55 |
Correct |
9 ms |
1612 KB |
Output is correct |
56 |
Correct |
10 ms |
1612 KB |
Output is correct |
57 |
Correct |
9 ms |
1624 KB |
Output is correct |
58 |
Correct |
12 ms |
1612 KB |
Output is correct |
59 |
Correct |
1742 ms |
12156 KB |
Output is correct |
60 |
Correct |
1709 ms |
12160 KB |
Output is correct |
61 |
Correct |
1685 ms |
12164 KB |
Output is correct |
62 |
Correct |
1704 ms |
12164 KB |
Output is correct |
63 |
Correct |
1697 ms |
12160 KB |
Output is correct |
64 |
Correct |
1744 ms |
12156 KB |
Output is correct |
65 |
Correct |
1736 ms |
12164 KB |
Output is correct |
66 |
Correct |
1739 ms |
12256 KB |
Output is correct |
67 |
Correct |
1748 ms |
12160 KB |
Output is correct |
68 |
Correct |
1763 ms |
12224 KB |
Output is correct |
69 |
Correct |
1683 ms |
12160 KB |
Output is correct |
70 |
Correct |
1716 ms |
12156 KB |
Output is correct |
71 |
Correct |
1654 ms |
12172 KB |
Output is correct |
72 |
Correct |
1733 ms |
12160 KB |
Output is correct |
73 |
Correct |
1680 ms |
12156 KB |
Output is correct |
74 |
Correct |
206 ms |
2528 KB |
Output is correct |
75 |
Correct |
224 ms |
2576 KB |
Output is correct |
76 |
Correct |
205 ms |
2508 KB |
Output is correct |
77 |
Correct |
211 ms |
2508 KB |
Output is correct |
78 |
Correct |
223 ms |
2508 KB |
Output is correct |