# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
793379 |
2023-07-25T18:49:13 Z |
kingfran1907 |
Boat (APIO16_boat) |
C++14 |
|
347 ms |
4360 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const int maxn = 1010;
const int mod = 1e9+7;
int mul(int a, int b) {
llint out = (llint)a * b;
return out % mod;
}
int pot(int a, int b) {
if (b == 0) return 1;
if (b % 2 == 1) return mul(a, pot(a, b - 1));
int out = pot(a, b / 2);
return mul(out, out);
}
int n;
int a[maxn], b[maxn];
llint dp[maxn][maxn];
int inv[maxn];
int len[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", a+i, b+i);
vector< int > v;
for (int i = 1; i <= n; i++) {
v.push_back(a[i]);
v.push_back(b[i] + 1);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for (int i = 1; i <= n; i++) {
a[i] = upper_bound(v.begin(), v.end(), a[i]) - v.begin();
b[i] = upper_bound(v.begin(), v.end(), b[i]) - v.begin();
}
for (int i = 0; i < v.size() - 1; i++) len[i + 1] = v[i + 1] - v[i];
//for (int i = 0; i < v.size() - 1; i++) printf("%d ", len[i]); printf("\n\n");
for (int i = 1; i <= n; i++) inv[i] = pot(i, mod - 2);
for (int i = 0; i < v.size(); i++) dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = a[i]; j <= b[i]; j++) {
if (a[i] <= j && j <= b[i]) {
dp[i][j] = mul(len[j], dp[i - 1][j - 1]);
int kol = 1;
int pov = len[j] - 1;
for (int k = i - 1; k > 0; k--) {
if (a[k] <= j && j <= b[k]) {
pov = mul(pov, mul(len[j] - 1 + kol, inv[kol + 1])); kol++;
dp[i][j] += mul(dp[k - 1][j - 1], pov), dp[i][j] %= mod;
}
}
}
}
for (int j = 0; j < v.size(); j++) {
dp[i][j] += dp[i - 1][j], dp[i][j] %= mod;
if (j > 0) {
dp[i][j] += dp[i][j - 1], dp[i][j] %= mod;
dp[i][j] += mod - dp[i - 1][j - 1], dp[i][j] %= mod;
}
}
//for (int j = 0; j < v.size(); j++) printf("%d ", dp[i][j]);
//printf("\n");
}
printf("%d\n", (mod + dp[n][v.size() - 1] - 1) % mod);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0; i < v.size() - 1; i++) len[i + 1] = v[i + 1] - v[i];
| ~~^~~~~~~~~~~~~~
boat.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < v.size(); i++) dp[0][i] = 1;
| ~~^~~~~~~~~~
boat.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int j = 0; j < v.size(); j++) {
| ~~^~~~~~~~~~
boat.cpp:73:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'llint' {aka 'long long int'} [-Wformat=]
73 | printf("%d\n", (mod + dp[n][v.size() - 1] - 1) % mod);
| ~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| int llint {aka long long int}
| %lld
boat.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d%d", a+i, b+i);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
8 ms |
4260 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
7 ms |
4180 KB |
Output is correct |
6 |
Correct |
7 ms |
4180 KB |
Output is correct |
7 |
Correct |
7 ms |
4180 KB |
Output is correct |
8 |
Correct |
7 ms |
4180 KB |
Output is correct |
9 |
Correct |
7 ms |
4256 KB |
Output is correct |
10 |
Correct |
7 ms |
4180 KB |
Output is correct |
11 |
Correct |
7 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4180 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
7 ms |
4180 KB |
Output is correct |
15 |
Correct |
8 ms |
4192 KB |
Output is correct |
16 |
Correct |
3 ms |
3028 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
3 ms |
3028 KB |
Output is correct |
19 |
Correct |
3 ms |
3028 KB |
Output is correct |
20 |
Correct |
3 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
8 ms |
4260 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
7 ms |
4180 KB |
Output is correct |
6 |
Correct |
7 ms |
4180 KB |
Output is correct |
7 |
Correct |
7 ms |
4180 KB |
Output is correct |
8 |
Correct |
7 ms |
4180 KB |
Output is correct |
9 |
Correct |
7 ms |
4256 KB |
Output is correct |
10 |
Correct |
7 ms |
4180 KB |
Output is correct |
11 |
Correct |
7 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4180 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
7 ms |
4180 KB |
Output is correct |
15 |
Correct |
8 ms |
4192 KB |
Output is correct |
16 |
Correct |
3 ms |
3028 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
3 ms |
3028 KB |
Output is correct |
19 |
Correct |
3 ms |
3028 KB |
Output is correct |
20 |
Correct |
3 ms |
3028 KB |
Output is correct |
21 |
Correct |
158 ms |
4348 KB |
Output is correct |
22 |
Correct |
145 ms |
4172 KB |
Output is correct |
23 |
Correct |
130 ms |
4252 KB |
Output is correct |
24 |
Correct |
150 ms |
4248 KB |
Output is correct |
25 |
Correct |
151 ms |
4360 KB |
Output is correct |
26 |
Correct |
303 ms |
4236 KB |
Output is correct |
27 |
Correct |
327 ms |
4256 KB |
Output is correct |
28 |
Correct |
291 ms |
4172 KB |
Output is correct |
29 |
Correct |
303 ms |
4280 KB |
Output is correct |
30 |
Correct |
8 ms |
4280 KB |
Output is correct |
31 |
Correct |
7 ms |
4180 KB |
Output is correct |
32 |
Correct |
7 ms |
4308 KB |
Output is correct |
33 |
Correct |
10 ms |
4248 KB |
Output is correct |
34 |
Correct |
7 ms |
4180 KB |
Output is correct |
35 |
Correct |
8 ms |
4308 KB |
Output is correct |
36 |
Correct |
8 ms |
4308 KB |
Output is correct |
37 |
Correct |
9 ms |
4308 KB |
Output is correct |
38 |
Correct |
9 ms |
4284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Correct |
2 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
2 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
820 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
852 KB |
Output is correct |
12 |
Correct |
2 ms |
852 KB |
Output is correct |
13 |
Correct |
2 ms |
828 KB |
Output is correct |
14 |
Correct |
2 ms |
852 KB |
Output is correct |
15 |
Correct |
2 ms |
852 KB |
Output is correct |
16 |
Correct |
2 ms |
788 KB |
Output is correct |
17 |
Correct |
2 ms |
828 KB |
Output is correct |
18 |
Correct |
2 ms |
820 KB |
Output is correct |
19 |
Correct |
2 ms |
772 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
8 ms |
4260 KB |
Output is correct |
4 |
Correct |
7 ms |
4180 KB |
Output is correct |
5 |
Correct |
7 ms |
4180 KB |
Output is correct |
6 |
Correct |
7 ms |
4180 KB |
Output is correct |
7 |
Correct |
7 ms |
4180 KB |
Output is correct |
8 |
Correct |
7 ms |
4180 KB |
Output is correct |
9 |
Correct |
7 ms |
4256 KB |
Output is correct |
10 |
Correct |
7 ms |
4180 KB |
Output is correct |
11 |
Correct |
7 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4180 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
7 ms |
4180 KB |
Output is correct |
15 |
Correct |
8 ms |
4192 KB |
Output is correct |
16 |
Correct |
3 ms |
3028 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
3 ms |
3028 KB |
Output is correct |
19 |
Correct |
3 ms |
3028 KB |
Output is correct |
20 |
Correct |
3 ms |
3028 KB |
Output is correct |
21 |
Correct |
158 ms |
4348 KB |
Output is correct |
22 |
Correct |
145 ms |
4172 KB |
Output is correct |
23 |
Correct |
130 ms |
4252 KB |
Output is correct |
24 |
Correct |
150 ms |
4248 KB |
Output is correct |
25 |
Correct |
151 ms |
4360 KB |
Output is correct |
26 |
Correct |
303 ms |
4236 KB |
Output is correct |
27 |
Correct |
327 ms |
4256 KB |
Output is correct |
28 |
Correct |
291 ms |
4172 KB |
Output is correct |
29 |
Correct |
303 ms |
4280 KB |
Output is correct |
30 |
Correct |
8 ms |
4280 KB |
Output is correct |
31 |
Correct |
7 ms |
4180 KB |
Output is correct |
32 |
Correct |
7 ms |
4308 KB |
Output is correct |
33 |
Correct |
10 ms |
4248 KB |
Output is correct |
34 |
Correct |
7 ms |
4180 KB |
Output is correct |
35 |
Correct |
8 ms |
4308 KB |
Output is correct |
36 |
Correct |
8 ms |
4308 KB |
Output is correct |
37 |
Correct |
9 ms |
4308 KB |
Output is correct |
38 |
Correct |
9 ms |
4284 KB |
Output is correct |
39 |
Correct |
2 ms |
852 KB |
Output is correct |
40 |
Correct |
2 ms |
852 KB |
Output is correct |
41 |
Correct |
3 ms |
852 KB |
Output is correct |
42 |
Correct |
2 ms |
852 KB |
Output is correct |
43 |
Correct |
2 ms |
852 KB |
Output is correct |
44 |
Correct |
3 ms |
852 KB |
Output is correct |
45 |
Correct |
4 ms |
852 KB |
Output is correct |
46 |
Correct |
4 ms |
852 KB |
Output is correct |
47 |
Correct |
4 ms |
820 KB |
Output is correct |
48 |
Correct |
4 ms |
852 KB |
Output is correct |
49 |
Correct |
2 ms |
852 KB |
Output is correct |
50 |
Correct |
2 ms |
852 KB |
Output is correct |
51 |
Correct |
2 ms |
828 KB |
Output is correct |
52 |
Correct |
2 ms |
852 KB |
Output is correct |
53 |
Correct |
2 ms |
852 KB |
Output is correct |
54 |
Correct |
2 ms |
788 KB |
Output is correct |
55 |
Correct |
2 ms |
828 KB |
Output is correct |
56 |
Correct |
2 ms |
820 KB |
Output is correct |
57 |
Correct |
2 ms |
772 KB |
Output is correct |
58 |
Correct |
2 ms |
724 KB |
Output is correct |
59 |
Correct |
159 ms |
4240 KB |
Output is correct |
60 |
Correct |
145 ms |
4232 KB |
Output is correct |
61 |
Correct |
147 ms |
4252 KB |
Output is correct |
62 |
Correct |
163 ms |
4184 KB |
Output is correct |
63 |
Correct |
156 ms |
4260 KB |
Output is correct |
64 |
Correct |
332 ms |
4216 KB |
Output is correct |
65 |
Correct |
333 ms |
4176 KB |
Output is correct |
66 |
Correct |
336 ms |
4196 KB |
Output is correct |
67 |
Correct |
347 ms |
4208 KB |
Output is correct |
68 |
Correct |
335 ms |
4200 KB |
Output is correct |
69 |
Correct |
132 ms |
4192 KB |
Output is correct |
70 |
Correct |
144 ms |
4288 KB |
Output is correct |
71 |
Correct |
133 ms |
4276 KB |
Output is correct |
72 |
Correct |
139 ms |
4228 KB |
Output is correct |
73 |
Correct |
140 ms |
4220 KB |
Output is correct |
74 |
Correct |
36 ms |
2932 KB |
Output is correct |
75 |
Correct |
39 ms |
3032 KB |
Output is correct |
76 |
Correct |
35 ms |
2960 KB |
Output is correct |
77 |
Correct |
35 ms |
2992 KB |
Output is correct |
78 |
Correct |
37 ms |
2948 KB |
Output is correct |