# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
886030 |
2023-12-11T11:59:53 Z |
NeroZein |
Boat (APIO16_boat) |
C++17 |
|
476 ms |
2664 KB |
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int md = (int) 1e9 + 7;
const int N = 503;
int iv[N];
int len[N * 2];
int dp[N][N * 2];
long long a[N], b[N];
void add(int& x, int y) {
x += y;
if (x >= md) x -= md;
}
int mul(int x, int y) {
return (int) ((long long) x * y % md);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<long long> c;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
c.push_back(a[i]);
c.push_back(++b[i]);
}
sort(c.begin(), c.end());
c.resize(unique(c.begin(), c.end()) - c.begin());
for (int i = 1; i <= n; ++i) {
a[i] = upper_bound(c.begin(), c.end(), a[i]) - c.begin();
b[i] = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
}
iv[1] = 1;
for (int i = 2; i <= n; ++i) {
iv[i] = mul(md - md / i, iv[md % i]);
}
int m = (int) c.size();
for (int i = 1; i < m; ++i) {
len[i] = c[i] - c[i - 1];
}
for (int i = 0; i <= m; ++i) {
dp[0][i] = 1;
}
for (int i = 1; i <= n; ++i) {
for (int j = a[i]; j < b[i]; ++j) {
int prod = len[j], cnt = 1;
for (int k = i - 1; k >= 0; --k) {
add(dp[i][j], mul(dp[k][j - 1], prod));
if (a[k] <= j && j < b[k]) {
prod = mul(prod, iv[cnt + 1]);
prod = mul(prod, len[j] + cnt);
cnt++;
}
}
}
for (int j = 1; j <= m; ++j) {
add(dp[i][j], dp[i][j - 1]);
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
add(ans, dp[i][m]);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
4 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Correct |
4 ms |
2396 KB |
Output is correct |
7 |
Correct |
4 ms |
2396 KB |
Output is correct |
8 |
Correct |
4 ms |
2396 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
4 ms |
2396 KB |
Output is correct |
11 |
Correct |
4 ms |
2416 KB |
Output is correct |
12 |
Correct |
4 ms |
2396 KB |
Output is correct |
13 |
Correct |
4 ms |
2448 KB |
Output is correct |
14 |
Correct |
4 ms |
2648 KB |
Output is correct |
15 |
Correct |
4 ms |
2264 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
4 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Correct |
4 ms |
2396 KB |
Output is correct |
7 |
Correct |
4 ms |
2396 KB |
Output is correct |
8 |
Correct |
4 ms |
2396 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
4 ms |
2396 KB |
Output is correct |
11 |
Correct |
4 ms |
2416 KB |
Output is correct |
12 |
Correct |
4 ms |
2396 KB |
Output is correct |
13 |
Correct |
4 ms |
2448 KB |
Output is correct |
14 |
Correct |
4 ms |
2648 KB |
Output is correct |
15 |
Correct |
4 ms |
2264 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
217 ms |
2388 KB |
Output is correct |
22 |
Correct |
209 ms |
2432 KB |
Output is correct |
23 |
Correct |
185 ms |
2428 KB |
Output is correct |
24 |
Correct |
204 ms |
2384 KB |
Output is correct |
25 |
Correct |
204 ms |
2384 KB |
Output is correct |
26 |
Correct |
415 ms |
2604 KB |
Output is correct |
27 |
Correct |
426 ms |
2656 KB |
Output is correct |
28 |
Correct |
414 ms |
2388 KB |
Output is correct |
29 |
Correct |
409 ms |
2664 KB |
Output is correct |
30 |
Correct |
5 ms |
2392 KB |
Output is correct |
31 |
Correct |
4 ms |
2396 KB |
Output is correct |
32 |
Correct |
5 ms |
2396 KB |
Output is correct |
33 |
Correct |
4 ms |
2396 KB |
Output is correct |
34 |
Correct |
5 ms |
2396 KB |
Output is correct |
35 |
Correct |
5 ms |
2392 KB |
Output is correct |
36 |
Correct |
5 ms |
2396 KB |
Output is correct |
37 |
Correct |
5 ms |
2396 KB |
Output is correct |
38 |
Correct |
5 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
856 KB |
Output is correct |
10 |
Correct |
4 ms |
860 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Correct |
2 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
4 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Correct |
4 ms |
2396 KB |
Output is correct |
7 |
Correct |
4 ms |
2396 KB |
Output is correct |
8 |
Correct |
4 ms |
2396 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
4 ms |
2396 KB |
Output is correct |
11 |
Correct |
4 ms |
2416 KB |
Output is correct |
12 |
Correct |
4 ms |
2396 KB |
Output is correct |
13 |
Correct |
4 ms |
2448 KB |
Output is correct |
14 |
Correct |
4 ms |
2648 KB |
Output is correct |
15 |
Correct |
4 ms |
2264 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
217 ms |
2388 KB |
Output is correct |
22 |
Correct |
209 ms |
2432 KB |
Output is correct |
23 |
Correct |
185 ms |
2428 KB |
Output is correct |
24 |
Correct |
204 ms |
2384 KB |
Output is correct |
25 |
Correct |
204 ms |
2384 KB |
Output is correct |
26 |
Correct |
415 ms |
2604 KB |
Output is correct |
27 |
Correct |
426 ms |
2656 KB |
Output is correct |
28 |
Correct |
414 ms |
2388 KB |
Output is correct |
29 |
Correct |
409 ms |
2664 KB |
Output is correct |
30 |
Correct |
5 ms |
2392 KB |
Output is correct |
31 |
Correct |
4 ms |
2396 KB |
Output is correct |
32 |
Correct |
5 ms |
2396 KB |
Output is correct |
33 |
Correct |
4 ms |
2396 KB |
Output is correct |
34 |
Correct |
5 ms |
2396 KB |
Output is correct |
35 |
Correct |
5 ms |
2392 KB |
Output is correct |
36 |
Correct |
5 ms |
2396 KB |
Output is correct |
37 |
Correct |
5 ms |
2396 KB |
Output is correct |
38 |
Correct |
5 ms |
2396 KB |
Output is correct |
39 |
Correct |
2 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
860 KB |
Output is correct |
41 |
Correct |
2 ms |
860 KB |
Output is correct |
42 |
Correct |
2 ms |
860 KB |
Output is correct |
43 |
Correct |
3 ms |
856 KB |
Output is correct |
44 |
Correct |
5 ms |
860 KB |
Output is correct |
45 |
Correct |
4 ms |
860 KB |
Output is correct |
46 |
Correct |
4 ms |
860 KB |
Output is correct |
47 |
Correct |
4 ms |
856 KB |
Output is correct |
48 |
Correct |
4 ms |
860 KB |
Output is correct |
49 |
Correct |
2 ms |
860 KB |
Output is correct |
50 |
Correct |
2 ms |
860 KB |
Output is correct |
51 |
Correct |
2 ms |
860 KB |
Output is correct |
52 |
Correct |
2 ms |
860 KB |
Output is correct |
53 |
Correct |
2 ms |
860 KB |
Output is correct |
54 |
Correct |
2 ms |
856 KB |
Output is correct |
55 |
Correct |
2 ms |
860 KB |
Output is correct |
56 |
Correct |
2 ms |
760 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
2 ms |
860 KB |
Output is correct |
59 |
Correct |
233 ms |
2364 KB |
Output is correct |
60 |
Correct |
215 ms |
2388 KB |
Output is correct |
61 |
Correct |
206 ms |
2240 KB |
Output is correct |
62 |
Correct |
234 ms |
2388 KB |
Output is correct |
63 |
Correct |
222 ms |
2264 KB |
Output is correct |
64 |
Correct |
472 ms |
2612 KB |
Output is correct |
65 |
Correct |
474 ms |
2388 KB |
Output is correct |
66 |
Correct |
472 ms |
2296 KB |
Output is correct |
67 |
Correct |
476 ms |
2476 KB |
Output is correct |
68 |
Correct |
472 ms |
2256 KB |
Output is correct |
69 |
Correct |
191 ms |
2492 KB |
Output is correct |
70 |
Correct |
187 ms |
2312 KB |
Output is correct |
71 |
Correct |
187 ms |
2320 KB |
Output is correct |
72 |
Correct |
200 ms |
2404 KB |
Output is correct |
73 |
Correct |
199 ms |
2384 KB |
Output is correct |
74 |
Correct |
48 ms |
2388 KB |
Output is correct |
75 |
Correct |
45 ms |
2388 KB |
Output is correct |
76 |
Correct |
48 ms |
2388 KB |
Output is correct |
77 |
Correct |
48 ms |
2252 KB |
Output is correct |
78 |
Correct |
49 ms |
2384 KB |
Output is correct |