# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
343643 |
2021-01-04T10:24:41 Z |
parsabahrami |
Boat (APIO16_boat) |
C++17 |
|
539 ms |
2560 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
int Pow(int a, int b, int md, int res = 1) {
for (; b; b >>= 1, a = 1ll * a * a % md) {
if (b & 1) res = 1ll * a * res % md;
}
return res;
}
const int N = 1e3 + 10, MOD = 1e9 + 7;
int dp[N][N], I[N], L[N], R[N], n;
vector<int> comp = {0, MOD};
int add(int x, int y) {
int res = x + y;
if (res >= MOD) res -= MOD;
return res;
}
int main() {
for (int i = 1; i < N; i++) I[i] = Pow(i, MOD - 2, MOD);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &L[i], &R[i]);
R[i]++;
comp.push_back(L[i]);
comp.push_back(R[i]);
}
sort(comp.begin(), comp.end());
comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
int m = SZ(comp);
for (int i = 1; i < m; i++) dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = dp[i][j - 1];
if (L[i] > comp[j - 1] || R[i] < comp[j]) continue;
int len = comp[j] - comp[j - 1];
int C = 1ll * len * (len - 1) % MOD * ((MOD + 1) / 2) % MOD, k = 1;
dp[i][j] = add(dp[i][j], 1ll * dp[i - 1][j - 1] * len % MOD);
for (int last = i - 1; last >= 1; last--) {
if (L[last] > comp[j - 1] || R[last] < comp[j]) continue;
dp[i][j] = add(dp[i][j], 1ll * dp[last - 1][j - 1] * C % MOD);
C = (1ll * (len + k) * C % MOD * I[k + 2] % MOD) % MOD;
k++;
}
}
for (int j = 1; j < m; j++) dp[i][j] = add(dp[i][j], dp[i - 1][j]);
}
printf("%d\n", dp[n][m - 1] - 1);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
31 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
33 | scanf("%d%d", &L[i], &R[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2284 KB |
Output is correct |
2 |
Correct |
4 ms |
2284 KB |
Output is correct |
3 |
Correct |
4 ms |
2284 KB |
Output is correct |
4 |
Correct |
6 ms |
2284 KB |
Output is correct |
5 |
Correct |
5 ms |
2284 KB |
Output is correct |
6 |
Correct |
4 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
2284 KB |
Output is correct |
8 |
Correct |
4 ms |
2284 KB |
Output is correct |
9 |
Correct |
4 ms |
2284 KB |
Output is correct |
10 |
Correct |
4 ms |
2284 KB |
Output is correct |
11 |
Correct |
4 ms |
2284 KB |
Output is correct |
12 |
Correct |
5 ms |
2284 KB |
Output is correct |
13 |
Correct |
4 ms |
2284 KB |
Output is correct |
14 |
Correct |
4 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2412 KB |
Output is correct |
16 |
Correct |
3 ms |
2284 KB |
Output is correct |
17 |
Correct |
3 ms |
2284 KB |
Output is correct |
18 |
Correct |
3 ms |
2284 KB |
Output is correct |
19 |
Correct |
3 ms |
2284 KB |
Output is correct |
20 |
Correct |
3 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2284 KB |
Output is correct |
2 |
Correct |
4 ms |
2284 KB |
Output is correct |
3 |
Correct |
4 ms |
2284 KB |
Output is correct |
4 |
Correct |
6 ms |
2284 KB |
Output is correct |
5 |
Correct |
5 ms |
2284 KB |
Output is correct |
6 |
Correct |
4 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
2284 KB |
Output is correct |
8 |
Correct |
4 ms |
2284 KB |
Output is correct |
9 |
Correct |
4 ms |
2284 KB |
Output is correct |
10 |
Correct |
4 ms |
2284 KB |
Output is correct |
11 |
Correct |
4 ms |
2284 KB |
Output is correct |
12 |
Correct |
5 ms |
2284 KB |
Output is correct |
13 |
Correct |
4 ms |
2284 KB |
Output is correct |
14 |
Correct |
4 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2412 KB |
Output is correct |
16 |
Correct |
3 ms |
2284 KB |
Output is correct |
17 |
Correct |
3 ms |
2284 KB |
Output is correct |
18 |
Correct |
3 ms |
2284 KB |
Output is correct |
19 |
Correct |
3 ms |
2284 KB |
Output is correct |
20 |
Correct |
3 ms |
2284 KB |
Output is correct |
21 |
Correct |
219 ms |
2284 KB |
Output is correct |
22 |
Correct |
214 ms |
2412 KB |
Output is correct |
23 |
Correct |
187 ms |
2284 KB |
Output is correct |
24 |
Correct |
210 ms |
2284 KB |
Output is correct |
25 |
Correct |
211 ms |
2284 KB |
Output is correct |
26 |
Correct |
464 ms |
2284 KB |
Output is correct |
27 |
Correct |
480 ms |
2284 KB |
Output is correct |
28 |
Correct |
467 ms |
2412 KB |
Output is correct |
29 |
Correct |
462 ms |
2412 KB |
Output is correct |
30 |
Correct |
4 ms |
2284 KB |
Output is correct |
31 |
Correct |
4 ms |
2284 KB |
Output is correct |
32 |
Correct |
4 ms |
2284 KB |
Output is correct |
33 |
Correct |
4 ms |
2284 KB |
Output is correct |
34 |
Correct |
5 ms |
2284 KB |
Output is correct |
35 |
Correct |
5 ms |
2284 KB |
Output is correct |
36 |
Correct |
5 ms |
2284 KB |
Output is correct |
37 |
Correct |
5 ms |
2284 KB |
Output is correct |
38 |
Correct |
5 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
3 ms |
748 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
3 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
748 KB |
Output is correct |
6 |
Correct |
5 ms |
748 KB |
Output is correct |
7 |
Correct |
6 ms |
876 KB |
Output is correct |
8 |
Correct |
5 ms |
748 KB |
Output is correct |
9 |
Correct |
6 ms |
748 KB |
Output is correct |
10 |
Correct |
5 ms |
748 KB |
Output is correct |
11 |
Correct |
3 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
3 ms |
748 KB |
Output is correct |
14 |
Correct |
3 ms |
748 KB |
Output is correct |
15 |
Correct |
3 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2284 KB |
Output is correct |
2 |
Correct |
4 ms |
2284 KB |
Output is correct |
3 |
Correct |
4 ms |
2284 KB |
Output is correct |
4 |
Correct |
6 ms |
2284 KB |
Output is correct |
5 |
Correct |
5 ms |
2284 KB |
Output is correct |
6 |
Correct |
4 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
2284 KB |
Output is correct |
8 |
Correct |
4 ms |
2284 KB |
Output is correct |
9 |
Correct |
4 ms |
2284 KB |
Output is correct |
10 |
Correct |
4 ms |
2284 KB |
Output is correct |
11 |
Correct |
4 ms |
2284 KB |
Output is correct |
12 |
Correct |
5 ms |
2284 KB |
Output is correct |
13 |
Correct |
4 ms |
2284 KB |
Output is correct |
14 |
Correct |
4 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2412 KB |
Output is correct |
16 |
Correct |
3 ms |
2284 KB |
Output is correct |
17 |
Correct |
3 ms |
2284 KB |
Output is correct |
18 |
Correct |
3 ms |
2284 KB |
Output is correct |
19 |
Correct |
3 ms |
2284 KB |
Output is correct |
20 |
Correct |
3 ms |
2284 KB |
Output is correct |
21 |
Correct |
219 ms |
2284 KB |
Output is correct |
22 |
Correct |
214 ms |
2412 KB |
Output is correct |
23 |
Correct |
187 ms |
2284 KB |
Output is correct |
24 |
Correct |
210 ms |
2284 KB |
Output is correct |
25 |
Correct |
211 ms |
2284 KB |
Output is correct |
26 |
Correct |
464 ms |
2284 KB |
Output is correct |
27 |
Correct |
480 ms |
2284 KB |
Output is correct |
28 |
Correct |
467 ms |
2412 KB |
Output is correct |
29 |
Correct |
462 ms |
2412 KB |
Output is correct |
30 |
Correct |
4 ms |
2284 KB |
Output is correct |
31 |
Correct |
4 ms |
2284 KB |
Output is correct |
32 |
Correct |
4 ms |
2284 KB |
Output is correct |
33 |
Correct |
4 ms |
2284 KB |
Output is correct |
34 |
Correct |
5 ms |
2284 KB |
Output is correct |
35 |
Correct |
5 ms |
2284 KB |
Output is correct |
36 |
Correct |
5 ms |
2284 KB |
Output is correct |
37 |
Correct |
5 ms |
2284 KB |
Output is correct |
38 |
Correct |
5 ms |
2284 KB |
Output is correct |
39 |
Correct |
3 ms |
748 KB |
Output is correct |
40 |
Correct |
3 ms |
748 KB |
Output is correct |
41 |
Correct |
3 ms |
748 KB |
Output is correct |
42 |
Correct |
3 ms |
748 KB |
Output is correct |
43 |
Correct |
3 ms |
748 KB |
Output is correct |
44 |
Correct |
5 ms |
748 KB |
Output is correct |
45 |
Correct |
6 ms |
876 KB |
Output is correct |
46 |
Correct |
5 ms |
748 KB |
Output is correct |
47 |
Correct |
6 ms |
748 KB |
Output is correct |
48 |
Correct |
5 ms |
748 KB |
Output is correct |
49 |
Correct |
3 ms |
748 KB |
Output is correct |
50 |
Correct |
2 ms |
748 KB |
Output is correct |
51 |
Correct |
3 ms |
748 KB |
Output is correct |
52 |
Correct |
3 ms |
748 KB |
Output is correct |
53 |
Correct |
3 ms |
748 KB |
Output is correct |
54 |
Correct |
2 ms |
748 KB |
Output is correct |
55 |
Correct |
2 ms |
748 KB |
Output is correct |
56 |
Correct |
2 ms |
748 KB |
Output is correct |
57 |
Correct |
2 ms |
748 KB |
Output is correct |
58 |
Correct |
2 ms |
748 KB |
Output is correct |
59 |
Correct |
240 ms |
2340 KB |
Output is correct |
60 |
Correct |
220 ms |
2412 KB |
Output is correct |
61 |
Correct |
205 ms |
2284 KB |
Output is correct |
62 |
Correct |
242 ms |
2284 KB |
Output is correct |
63 |
Correct |
226 ms |
2384 KB |
Output is correct |
64 |
Correct |
531 ms |
2284 KB |
Output is correct |
65 |
Correct |
539 ms |
2284 KB |
Output is correct |
66 |
Correct |
537 ms |
2284 KB |
Output is correct |
67 |
Correct |
530 ms |
2560 KB |
Output is correct |
68 |
Correct |
529 ms |
2412 KB |
Output is correct |
69 |
Correct |
199 ms |
2412 KB |
Output is correct |
70 |
Correct |
203 ms |
2284 KB |
Output is correct |
71 |
Correct |
200 ms |
2284 KB |
Output is correct |
72 |
Correct |
212 ms |
2412 KB |
Output is correct |
73 |
Correct |
219 ms |
2284 KB |
Output is correct |
74 |
Correct |
51 ms |
2284 KB |
Output is correct |
75 |
Correct |
52 ms |
2284 KB |
Output is correct |
76 |
Correct |
50 ms |
2284 KB |
Output is correct |
77 |
Correct |
51 ms |
2412 KB |
Output is correct |
78 |
Correct |
52 ms |
2284 KB |
Output is correct |