# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48534 | 2018-05-15T13:09:04 Z | Kmcode | Boat (APIO16_boat) | C++14 | 1430 ms | 21208 KB |
#include "bits/stdc++.h" using namespace std; #define MOD 1000000007 #define MAX 1102 int n; vector<pair<int, int> > v; vector<int> vv; long long int dp[MAX][MAX]; long long int way[MAX][MAX]; long long int c[MAX][MAX]; long long int ppow(long long int i, long long int j) { long long int res = 1; while (j) { if ((j & 1LL)) { res *= i; if (res >= MOD)res %= MOD; } i *= i; if (i >= MOD)i %= MOD; j >>= 1LL; } return res; } long long int k[MAX]; int main() { k[0] = 1; for (int i = 1; i < MAX; i++) { k[i] = k[i - 1]; k[i] *= (long long int)(i); if (k[i] >= MOD)k[i] %= MOD; } for (int i = 0; i < MAX; i++) { k[i] = ppow(k[i], MOD - 2); } c[0][0] = 1; for (int i = 0; i + 1 < MAX; i++) { for (int j = 0; j <= i; j++) { c[i + 1][j] += c[i][j]; c[i + 1][j + 1] += c[i][j]; if (c[i + 1][j] >= MOD)c[i + 1][j] -= MOD; if (c[i + 1][j + 1] >= MOD)c[i + 1][j + 1] -= MOD; } } cin >> n; vv.push_back(0); for (int i = 0; i < n; i++) { int a, b; scanf("%d%d", &a, &b); vv.push_back(a), vv.push_back(b+1); v.push_back(make_pair(a, b)); } sort(vv.begin(), vv.end()); vv.erase(unique(vv.begin(), vv.end()), vv.end()); vv.push_back(vv.back() + 1); dp[0][0] = 1; for (int i = 0; i + 1 < vv.size(); i++) { long long int rng = vv[i + 1] - vv[i]; long long int up = 1; long long int dw = 0; for (int j = 1; j <= 500; j++) { if (rng < j)break; up *= (long long int)(rng - j + 1LL); if (up >= MOD)up %= MOD; dw = k[j]; dw *= up; if (dw >= MOD)dw %= MOD; way[i][j] = dw; } for (int j = 500; j >= 1; j--) { long long int tmp = 0; for (int k = j; k >= 1; k--) { tmp += way[i][k] * c[j - 1][k - 1]; if (tmp >= MOD)tmp %= MOD; } way[i][j] = tmp; if (tmp < 0LL)while (1); } } long long int AA = 0; for (int i = 0; i < v.size(); i++) { long long int su = 0; for (int j = 0; j + 1 < vv.size(); j++) { int valid = 0; for (int k = i; k < v.size(); k++) { if (v[k].first <= vv[j] && vv[j + 1] - 1 <= v[k].second) { valid++; if (su < 0LL)while(1); dp[k + 1][j] += su*way[j][valid]; AA += su*way[j][valid]; if (AA >= MOD)AA %= MOD; if (dp[k + 1][j] >= MOD)dp[k + 1][j] %= MOD; } } su += dp[i][j]; if (su >= MOD)su %= MOD; } } if (AA < 0LL)exit(1); printf("%lld\n", AA); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 689 ms | 18492 KB | Output is correct |
2 | Correct | 667 ms | 18568 KB | Output is correct |
3 | Correct | 657 ms | 18568 KB | Output is correct |
4 | Correct | 709 ms | 18588 KB | Output is correct |
5 | Correct | 685 ms | 18588 KB | Output is correct |
6 | Correct | 607 ms | 18744 KB | Output is correct |
7 | Correct | 591 ms | 18744 KB | Output is correct |
8 | Correct | 603 ms | 18744 KB | Output is correct |
9 | Correct | 648 ms | 18744 KB | Output is correct |
10 | Correct | 631 ms | 18764 KB | Output is correct |
11 | Correct | 609 ms | 18764 KB | Output is correct |
12 | Correct | 604 ms | 18764 KB | Output is correct |
13 | Correct | 600 ms | 18768 KB | Output is correct |
14 | Correct | 599 ms | 18768 KB | Output is correct |
15 | Correct | 602 ms | 18768 KB | Output is correct |
16 | Correct | 150 ms | 18768 KB | Output is correct |
17 | Correct | 162 ms | 18768 KB | Output is correct |
18 | Correct | 154 ms | 18768 KB | Output is correct |
19 | Correct | 167 ms | 18768 KB | Output is correct |
20 | Correct | 157 ms | 18768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 689 ms | 18492 KB | Output is correct |
2 | Correct | 667 ms | 18568 KB | Output is correct |
3 | Correct | 657 ms | 18568 KB | Output is correct |
4 | Correct | 709 ms | 18588 KB | Output is correct |
5 | Correct | 685 ms | 18588 KB | Output is correct |
6 | Correct | 607 ms | 18744 KB | Output is correct |
7 | Correct | 591 ms | 18744 KB | Output is correct |
8 | Correct | 603 ms | 18744 KB | Output is correct |
9 | Correct | 648 ms | 18744 KB | Output is correct |
10 | Correct | 631 ms | 18764 KB | Output is correct |
11 | Correct | 609 ms | 18764 KB | Output is correct |
12 | Correct | 604 ms | 18764 KB | Output is correct |
13 | Correct | 600 ms | 18768 KB | Output is correct |
14 | Correct | 599 ms | 18768 KB | Output is correct |
15 | Correct | 602 ms | 18768 KB | Output is correct |
16 | Correct | 150 ms | 18768 KB | Output is correct |
17 | Correct | 162 ms | 18768 KB | Output is correct |
18 | Correct | 154 ms | 18768 KB | Output is correct |
19 | Correct | 167 ms | 18768 KB | Output is correct |
20 | Correct | 157 ms | 18768 KB | Output is correct |
21 | Correct | 687 ms | 19148 KB | Output is correct |
22 | Correct | 680 ms | 19148 KB | Output is correct |
23 | Correct | 647 ms | 19148 KB | Output is correct |
24 | Correct | 653 ms | 19148 KB | Output is correct |
25 | Correct | 632 ms | 19148 KB | Output is correct |
26 | Correct | 696 ms | 19436 KB | Output is correct |
27 | Correct | 734 ms | 19720 KB | Output is correct |
28 | Correct | 700 ms | 19720 KB | Output is correct |
29 | Correct | 718 ms | 19720 KB | Output is correct |
30 | Correct | 583 ms | 19720 KB | Output is correct |
31 | Correct | 581 ms | 19720 KB | Output is correct |
32 | Correct | 578 ms | 19720 KB | Output is correct |
33 | Correct | 575 ms | 19720 KB | Output is correct |
34 | Correct | 581 ms | 19720 KB | Output is correct |
35 | Correct | 653 ms | 19720 KB | Output is correct |
36 | Correct | 664 ms | 19720 KB | Output is correct |
37 | Correct | 667 ms | 19720 KB | Output is correct |
38 | Correct | 665 ms | 19720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 160 ms | 19720 KB | Output is correct |
2 | Correct | 159 ms | 19720 KB | Output is correct |
3 | Correct | 160 ms | 19720 KB | Output is correct |
4 | Correct | 159 ms | 19720 KB | Output is correct |
5 | Correct | 161 ms | 19720 KB | Output is correct |
6 | Correct | 157 ms | 19720 KB | Output is correct |
7 | Correct | 158 ms | 19720 KB | Output is correct |
8 | Correct | 161 ms | 19720 KB | Output is correct |
9 | Correct | 161 ms | 19720 KB | Output is correct |
10 | Correct | 172 ms | 19720 KB | Output is correct |
11 | Correct | 160 ms | 19720 KB | Output is correct |
12 | Correct | 158 ms | 19720 KB | Output is correct |
13 | Correct | 158 ms | 19720 KB | Output is correct |
14 | Correct | 159 ms | 19720 KB | Output is correct |
15 | Correct | 160 ms | 19720 KB | Output is correct |
16 | Correct | 84 ms | 19720 KB | Output is correct |
17 | Correct | 83 ms | 19720 KB | Output is correct |
18 | Correct | 83 ms | 19720 KB | Output is correct |
19 | Correct | 84 ms | 19720 KB | Output is correct |
20 | Correct | 83 ms | 19720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 689 ms | 18492 KB | Output is correct |
2 | Correct | 667 ms | 18568 KB | Output is correct |
3 | Correct | 657 ms | 18568 KB | Output is correct |
4 | Correct | 709 ms | 18588 KB | Output is correct |
5 | Correct | 685 ms | 18588 KB | Output is correct |
6 | Correct | 607 ms | 18744 KB | Output is correct |
7 | Correct | 591 ms | 18744 KB | Output is correct |
8 | Correct | 603 ms | 18744 KB | Output is correct |
9 | Correct | 648 ms | 18744 KB | Output is correct |
10 | Correct | 631 ms | 18764 KB | Output is correct |
11 | Correct | 609 ms | 18764 KB | Output is correct |
12 | Correct | 604 ms | 18764 KB | Output is correct |
13 | Correct | 600 ms | 18768 KB | Output is correct |
14 | Correct | 599 ms | 18768 KB | Output is correct |
15 | Correct | 602 ms | 18768 KB | Output is correct |
16 | Correct | 150 ms | 18768 KB | Output is correct |
17 | Correct | 162 ms | 18768 KB | Output is correct |
18 | Correct | 154 ms | 18768 KB | Output is correct |
19 | Correct | 167 ms | 18768 KB | Output is correct |
20 | Correct | 157 ms | 18768 KB | Output is correct |
21 | Correct | 687 ms | 19148 KB | Output is correct |
22 | Correct | 680 ms | 19148 KB | Output is correct |
23 | Correct | 647 ms | 19148 KB | Output is correct |
24 | Correct | 653 ms | 19148 KB | Output is correct |
25 | Correct | 632 ms | 19148 KB | Output is correct |
26 | Correct | 696 ms | 19436 KB | Output is correct |
27 | Correct | 734 ms | 19720 KB | Output is correct |
28 | Correct | 700 ms | 19720 KB | Output is correct |
29 | Correct | 718 ms | 19720 KB | Output is correct |
30 | Correct | 583 ms | 19720 KB | Output is correct |
31 | Correct | 581 ms | 19720 KB | Output is correct |
32 | Correct | 578 ms | 19720 KB | Output is correct |
33 | Correct | 575 ms | 19720 KB | Output is correct |
34 | Correct | 581 ms | 19720 KB | Output is correct |
35 | Correct | 653 ms | 19720 KB | Output is correct |
36 | Correct | 664 ms | 19720 KB | Output is correct |
37 | Correct | 667 ms | 19720 KB | Output is correct |
38 | Correct | 665 ms | 19720 KB | Output is correct |
39 | Correct | 160 ms | 19720 KB | Output is correct |
40 | Correct | 159 ms | 19720 KB | Output is correct |
41 | Correct | 160 ms | 19720 KB | Output is correct |
42 | Correct | 159 ms | 19720 KB | Output is correct |
43 | Correct | 161 ms | 19720 KB | Output is correct |
44 | Correct | 157 ms | 19720 KB | Output is correct |
45 | Correct | 158 ms | 19720 KB | Output is correct |
46 | Correct | 161 ms | 19720 KB | Output is correct |
47 | Correct | 161 ms | 19720 KB | Output is correct |
48 | Correct | 172 ms | 19720 KB | Output is correct |
49 | Correct | 160 ms | 19720 KB | Output is correct |
50 | Correct | 158 ms | 19720 KB | Output is correct |
51 | Correct | 158 ms | 19720 KB | Output is correct |
52 | Correct | 159 ms | 19720 KB | Output is correct |
53 | Correct | 160 ms | 19720 KB | Output is correct |
54 | Correct | 84 ms | 19720 KB | Output is correct |
55 | Correct | 83 ms | 19720 KB | Output is correct |
56 | Correct | 83 ms | 19720 KB | Output is correct |
57 | Correct | 84 ms | 19720 KB | Output is correct |
58 | Correct | 83 ms | 19720 KB | Output is correct |
59 | Correct | 1221 ms | 20344 KB | Output is correct |
60 | Correct | 1195 ms | 20344 KB | Output is correct |
61 | Correct | 1180 ms | 20344 KB | Output is correct |
62 | Correct | 1192 ms | 20344 KB | Output is correct |
63 | Correct | 1203 ms | 20376 KB | Output is correct |
64 | Correct | 1419 ms | 21028 KB | Output is correct |
65 | Correct | 1414 ms | 21028 KB | Output is correct |
66 | Correct | 1393 ms | 21028 KB | Output is correct |
67 | Correct | 1390 ms | 21028 KB | Output is correct |
68 | Correct | 1430 ms | 21208 KB | Output is correct |
69 | Correct | 1145 ms | 21208 KB | Output is correct |
70 | Correct | 1141 ms | 21208 KB | Output is correct |
71 | Correct | 1134 ms | 21208 KB | Output is correct |
72 | Correct | 1164 ms | 21208 KB | Output is correct |
73 | Correct | 1160 ms | 21208 KB | Output is correct |
74 | Correct | 244 ms | 21208 KB | Output is correct |
75 | Correct | 260 ms | 21208 KB | Output is correct |
76 | Correct | 247 ms | 21208 KB | Output is correct |
77 | Correct | 250 ms | 21208 KB | Output is correct |
78 | Correct | 248 ms | 21208 KB | Output is correct |