# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
679242 |
2023-01-07T21:07:34 Z |
stevancv |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
7440 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sadd(a, b) a = Add(a, b)
#define smul(a, b) a = Mul(a, b)
using namespace std;
const int N = 1000 + 2;
const int mod = 1e9 + 7;
int fak[N], inv[N];
int Add(int a, int b) {
a += b;
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return a;
}
int Mul(int a, int b) {
ll c = a; c *= b; c %= mod;
return c;
}
int Exp(int a, int b) {
int ans = 1;
while (b > 0) {
if (b & 1) smul(ans, a);
smul(a, a);
b >>= 1;
}
return ans;
}
int koef[2 * N][N], dp[2 * N][N];
bool pos[2 * N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fak[0] = inv[0] = 1;
for (int i = 1; i < N; i++) {
fak[i] = Mul(fak[i - 1], i);
inv[i] = Exp(fak[i], mod - 2);
}
int n; cin >> n;
vector<int> a(n), b(n), all;
all.push_back(-1);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
a[i] -= 1;
all.push_back(a[i]);
all.push_back(b[i]);
}
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
int x = all.size();
for (int i = 1; i < x; i++) {
int l = all[i] - all[i - 1];
for (int j = 1; j <= n; j++) {
int p = l, q = 1;
for (int k = 1; k <= j; k++) {
sadd(koef[i][j], Mul(Mul(p, inv[k]), Mul(q, inv[k - 1])));
smul(p, l - k);
smul(q, j - k);
}
}
}
for (int i = 0; i < n; i++) {
a[i] = lower_bound(all.begin(), all.end(), a[i]) - all.begin();
b[i] = lower_bound(all.begin(), all.end(), b[i]) - all.begin();
}
for (int j = 0; j < x; j++) dp[0][j] = 1;
for (int i = 0; i < n; i++) {
for (int j = a[i] + 1; j <= b[i]; j++) {
int y = 1;
for (int k = i; k >= 0; k--) {
sadd(dp[i + 1][j], Mul(dp[k][j - 1], koef[j][y]));
if (pos[j][k - 1]) y += 1;
}
pos[j][i] = 1;
}
for (int j = 1; j < x; j++) sadd(dp[i + 1][j], dp[i + 1][j - 1]);
}
int ans = 0;
for (int i = 1; i <= n; i++) sadd(ans, dp[i][x - 1]);
cout << ans << en;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1407 ms |
7264 KB |
Output is correct |
2 |
Correct |
1403 ms |
7164 KB |
Output is correct |
3 |
Correct |
1367 ms |
7204 KB |
Output is correct |
4 |
Correct |
1417 ms |
7272 KB |
Output is correct |
5 |
Correct |
1378 ms |
7140 KB |
Output is correct |
6 |
Correct |
1372 ms |
7324 KB |
Output is correct |
7 |
Correct |
1383 ms |
7164 KB |
Output is correct |
8 |
Correct |
1405 ms |
7272 KB |
Output is correct |
9 |
Correct |
1369 ms |
7296 KB |
Output is correct |
10 |
Correct |
1382 ms |
7240 KB |
Output is correct |
11 |
Correct |
1371 ms |
7204 KB |
Output is correct |
12 |
Correct |
1377 ms |
7344 KB |
Output is correct |
13 |
Correct |
1366 ms |
7220 KB |
Output is correct |
14 |
Correct |
1346 ms |
7244 KB |
Output is correct |
15 |
Correct |
1345 ms |
7348 KB |
Output is correct |
16 |
Correct |
240 ms |
3132 KB |
Output is correct |
17 |
Correct |
258 ms |
3116 KB |
Output is correct |
18 |
Correct |
251 ms |
3168 KB |
Output is correct |
19 |
Correct |
261 ms |
3144 KB |
Output is correct |
20 |
Correct |
252 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1407 ms |
7264 KB |
Output is correct |
2 |
Correct |
1403 ms |
7164 KB |
Output is correct |
3 |
Correct |
1367 ms |
7204 KB |
Output is correct |
4 |
Correct |
1417 ms |
7272 KB |
Output is correct |
5 |
Correct |
1378 ms |
7140 KB |
Output is correct |
6 |
Correct |
1372 ms |
7324 KB |
Output is correct |
7 |
Correct |
1383 ms |
7164 KB |
Output is correct |
8 |
Correct |
1405 ms |
7272 KB |
Output is correct |
9 |
Correct |
1369 ms |
7296 KB |
Output is correct |
10 |
Correct |
1382 ms |
7240 KB |
Output is correct |
11 |
Correct |
1371 ms |
7204 KB |
Output is correct |
12 |
Correct |
1377 ms |
7344 KB |
Output is correct |
13 |
Correct |
1366 ms |
7220 KB |
Output is correct |
14 |
Correct |
1346 ms |
7244 KB |
Output is correct |
15 |
Correct |
1345 ms |
7348 KB |
Output is correct |
16 |
Correct |
240 ms |
3132 KB |
Output is correct |
17 |
Correct |
258 ms |
3116 KB |
Output is correct |
18 |
Correct |
251 ms |
3168 KB |
Output is correct |
19 |
Correct |
261 ms |
3144 KB |
Output is correct |
20 |
Correct |
252 ms |
3148 KB |
Output is correct |
21 |
Correct |
1213 ms |
6872 KB |
Output is correct |
22 |
Correct |
1200 ms |
6812 KB |
Output is correct |
23 |
Correct |
1167 ms |
6988 KB |
Output is correct |
24 |
Correct |
1172 ms |
6776 KB |
Output is correct |
25 |
Correct |
1186 ms |
6796 KB |
Output is correct |
26 |
Correct |
1320 ms |
6564 KB |
Output is correct |
27 |
Correct |
1351 ms |
6724 KB |
Output is correct |
28 |
Correct |
1305 ms |
6596 KB |
Output is correct |
29 |
Correct |
1331 ms |
6700 KB |
Output is correct |
30 |
Correct |
1330 ms |
7188 KB |
Output is correct |
31 |
Correct |
1324 ms |
7192 KB |
Output is correct |
32 |
Correct |
1339 ms |
7204 KB |
Output is correct |
33 |
Correct |
1323 ms |
7440 KB |
Output is correct |
34 |
Correct |
1317 ms |
7248 KB |
Output is correct |
35 |
Correct |
1321 ms |
7304 KB |
Output is correct |
36 |
Correct |
1339 ms |
7164 KB |
Output is correct |
37 |
Correct |
1337 ms |
7160 KB |
Output is correct |
38 |
Correct |
1330 ms |
7140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1612 KB |
Output is correct |
2 |
Correct |
19 ms |
1676 KB |
Output is correct |
3 |
Correct |
18 ms |
1624 KB |
Output is correct |
4 |
Correct |
18 ms |
1656 KB |
Output is correct |
5 |
Correct |
18 ms |
1612 KB |
Output is correct |
6 |
Correct |
20 ms |
1660 KB |
Output is correct |
7 |
Correct |
20 ms |
1684 KB |
Output is correct |
8 |
Correct |
19 ms |
1620 KB |
Output is correct |
9 |
Correct |
19 ms |
1704 KB |
Output is correct |
10 |
Correct |
19 ms |
1620 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
17 ms |
1600 KB |
Output is correct |
13 |
Correct |
18 ms |
1676 KB |
Output is correct |
14 |
Correct |
18 ms |
1640 KB |
Output is correct |
15 |
Correct |
17 ms |
1684 KB |
Output is correct |
16 |
Correct |
10 ms |
1292 KB |
Output is correct |
17 |
Correct |
10 ms |
1224 KB |
Output is correct |
18 |
Correct |
10 ms |
1236 KB |
Output is correct |
19 |
Correct |
9 ms |
1200 KB |
Output is correct |
20 |
Correct |
10 ms |
1212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1407 ms |
7264 KB |
Output is correct |
2 |
Correct |
1403 ms |
7164 KB |
Output is correct |
3 |
Correct |
1367 ms |
7204 KB |
Output is correct |
4 |
Correct |
1417 ms |
7272 KB |
Output is correct |
5 |
Correct |
1378 ms |
7140 KB |
Output is correct |
6 |
Correct |
1372 ms |
7324 KB |
Output is correct |
7 |
Correct |
1383 ms |
7164 KB |
Output is correct |
8 |
Correct |
1405 ms |
7272 KB |
Output is correct |
9 |
Correct |
1369 ms |
7296 KB |
Output is correct |
10 |
Correct |
1382 ms |
7240 KB |
Output is correct |
11 |
Correct |
1371 ms |
7204 KB |
Output is correct |
12 |
Correct |
1377 ms |
7344 KB |
Output is correct |
13 |
Correct |
1366 ms |
7220 KB |
Output is correct |
14 |
Correct |
1346 ms |
7244 KB |
Output is correct |
15 |
Correct |
1345 ms |
7348 KB |
Output is correct |
16 |
Correct |
240 ms |
3132 KB |
Output is correct |
17 |
Correct |
258 ms |
3116 KB |
Output is correct |
18 |
Correct |
251 ms |
3168 KB |
Output is correct |
19 |
Correct |
261 ms |
3144 KB |
Output is correct |
20 |
Correct |
252 ms |
3148 KB |
Output is correct |
21 |
Correct |
1213 ms |
6872 KB |
Output is correct |
22 |
Correct |
1200 ms |
6812 KB |
Output is correct |
23 |
Correct |
1167 ms |
6988 KB |
Output is correct |
24 |
Correct |
1172 ms |
6776 KB |
Output is correct |
25 |
Correct |
1186 ms |
6796 KB |
Output is correct |
26 |
Correct |
1320 ms |
6564 KB |
Output is correct |
27 |
Correct |
1351 ms |
6724 KB |
Output is correct |
28 |
Correct |
1305 ms |
6596 KB |
Output is correct |
29 |
Correct |
1331 ms |
6700 KB |
Output is correct |
30 |
Correct |
1330 ms |
7188 KB |
Output is correct |
31 |
Correct |
1324 ms |
7192 KB |
Output is correct |
32 |
Correct |
1339 ms |
7204 KB |
Output is correct |
33 |
Correct |
1323 ms |
7440 KB |
Output is correct |
34 |
Correct |
1317 ms |
7248 KB |
Output is correct |
35 |
Correct |
1321 ms |
7304 KB |
Output is correct |
36 |
Correct |
1339 ms |
7164 KB |
Output is correct |
37 |
Correct |
1337 ms |
7160 KB |
Output is correct |
38 |
Correct |
1330 ms |
7140 KB |
Output is correct |
39 |
Correct |
19 ms |
1612 KB |
Output is correct |
40 |
Correct |
19 ms |
1676 KB |
Output is correct |
41 |
Correct |
18 ms |
1624 KB |
Output is correct |
42 |
Correct |
18 ms |
1656 KB |
Output is correct |
43 |
Correct |
18 ms |
1612 KB |
Output is correct |
44 |
Correct |
20 ms |
1660 KB |
Output is correct |
45 |
Correct |
20 ms |
1684 KB |
Output is correct |
46 |
Correct |
19 ms |
1620 KB |
Output is correct |
47 |
Correct |
19 ms |
1704 KB |
Output is correct |
48 |
Correct |
19 ms |
1620 KB |
Output is correct |
49 |
Correct |
18 ms |
1620 KB |
Output is correct |
50 |
Correct |
17 ms |
1600 KB |
Output is correct |
51 |
Correct |
18 ms |
1676 KB |
Output is correct |
52 |
Correct |
18 ms |
1640 KB |
Output is correct |
53 |
Correct |
17 ms |
1684 KB |
Output is correct |
54 |
Correct |
10 ms |
1292 KB |
Output is correct |
55 |
Correct |
10 ms |
1224 KB |
Output is correct |
56 |
Correct |
10 ms |
1236 KB |
Output is correct |
57 |
Correct |
9 ms |
1200 KB |
Output is correct |
58 |
Correct |
10 ms |
1212 KB |
Output is correct |
59 |
Execution timed out |
2021 ms |
7368 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |