# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
218039 |
2020-03-31T14:31:35 Z |
perveevm |
Boat (APIO16_boat) |
C++14 |
|
584 ms |
2560 KB |
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#ifdef PERVEEVM_LOCAL
#define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
#define debug(x) 238;
#endif
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define NAME "File"
using ll = long long;
using ld = long double;
#ifdef PERVEEVM_LOCAL
std::mt19937 rnd(238);
#else
std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 510;
const int MOD = (int)1e9 + 7;
int add(int a, int b, int mod = MOD) {
if (a + b >= mod) {
return a + b - mod;
}
return a + b;
}
int sub(int a, int b, int mod = MOD) {
if (a - b < 0) {
return a - b + mod;
}
return a - b;
}
int mul(int a, int b, int mod = MOD) {
return (int)(1ll * a * b % mod);
}
int binpow(int a, int n, int mod = MOD) {
if (n == 0) {
return 1;
}
if (n % 2 == 0) {
return binpow(mul(a, a, mod), n / 2, mod);
} else {
return mul(binpow(a, n - 1, mod), a, mod);
}
}
int rev(int a, int mod = MOD) {
return binpow(a, mod - 2, mod);
}
int a[N], b[N];
int dp[2 * N][N];
int f[2 * N], rf[2 * N];
int r[2 * N];
void precalc() {
f[0] = 1;
rf[0] = 1;
for (int i = 1; i < 2 * N; ++i) {
f[i] = mul(f[i - 1], i);
rf[i] = rev(f[i]);
r[i] = rev(i);
}
}
int C(int n, int k) {
if (n < k) {
return 0;
}
return mul(f[n], mul(rf[k], rf[n - k]));
}
void run() {
precalc();
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
++b[i];
}
std::vector<int> trans;
for (int i = 1; i <= n; ++i) {
trans.push_back(a[i]);
trans.push_back(b[i]);
}
std::sort(trans.begin(), trans.end());
trans.resize(std::unique(trans.begin(), trans.end()) - trans.begin());
for (int i = 1; i <= n; ++i) {
a[i] = std::lower_bound(trans.begin(), trans.end(), a[i]) - trans.begin() + 1;
b[i] = std::lower_bound(trans.begin(), trans.end(), b[i]) - trans.begin() + 1;
}
dp[0][0] = 1;
// dp[i][j] - ans if last segment is i'th or less and last boat is j'th
for (int i = 1; i < (int)trans.size(); ++i) {
dp[i][0] = 1;
for (int j = 1; j <= n; ++j) {
dp[i][j] = dp[i - 1][j];
if (i < a[j] || b[j] <= i) {
continue;
}
int len = trans[i] - trans[i - 1];
int curC = len;
int cnt = 1;
for (int k = j - 1; k >= 0; --k) {
dp[i][j] = add(dp[i][j], mul(dp[i - 1][k], curC));
if (a[k] <= i && i < b[k]) {
++cnt;
curC = mul(curC, len + cnt - 1);
curC = mul(curC, r[cnt]);
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
ans = add(ans, dp[(int)trans.size() - 1][i]);
}
printf("%d\n", ans);
}
int main(void) {
// freopen(NAME".in", "r", stdin);
// freopen(NAME".out", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
run();
auto end = std::chrono::high_resolution_clock::now();
#ifdef PERVEEVM_LOCAL
std::cerr << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << std::endl;
#endif
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:155:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
auto start = std::chrono::high_resolution_clock::now();
^~~~~
boat.cpp:157:10: warning: variable 'end' set but not used [-Wunused-but-set-variable]
auto end = std::chrono::high_resolution_clock::now();
^~~
boat.cpp: In function 'void run()':
boat.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
8 ms |
2304 KB |
Output is correct |
5 |
Correct |
9 ms |
2304 KB |
Output is correct |
6 |
Correct |
8 ms |
2304 KB |
Output is correct |
7 |
Correct |
7 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
8 ms |
2304 KB |
Output is correct |
10 |
Correct |
8 ms |
2304 KB |
Output is correct |
11 |
Correct |
9 ms |
2304 KB |
Output is correct |
12 |
Correct |
9 ms |
2304 KB |
Output is correct |
13 |
Correct |
8 ms |
2304 KB |
Output is correct |
14 |
Correct |
8 ms |
2304 KB |
Output is correct |
15 |
Correct |
8 ms |
2304 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
7 ms |
768 KB |
Output is correct |
18 |
Correct |
7 ms |
768 KB |
Output is correct |
19 |
Correct |
7 ms |
768 KB |
Output is correct |
20 |
Correct |
7 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
8 ms |
2304 KB |
Output is correct |
5 |
Correct |
9 ms |
2304 KB |
Output is correct |
6 |
Correct |
8 ms |
2304 KB |
Output is correct |
7 |
Correct |
7 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
8 ms |
2304 KB |
Output is correct |
10 |
Correct |
8 ms |
2304 KB |
Output is correct |
11 |
Correct |
9 ms |
2304 KB |
Output is correct |
12 |
Correct |
9 ms |
2304 KB |
Output is correct |
13 |
Correct |
8 ms |
2304 KB |
Output is correct |
14 |
Correct |
8 ms |
2304 KB |
Output is correct |
15 |
Correct |
8 ms |
2304 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
7 ms |
768 KB |
Output is correct |
18 |
Correct |
7 ms |
768 KB |
Output is correct |
19 |
Correct |
7 ms |
768 KB |
Output is correct |
20 |
Correct |
7 ms |
768 KB |
Output is correct |
21 |
Correct |
288 ms |
2176 KB |
Output is correct |
22 |
Correct |
259 ms |
2168 KB |
Output is correct |
23 |
Correct |
242 ms |
2168 KB |
Output is correct |
24 |
Correct |
258 ms |
2168 KB |
Output is correct |
25 |
Correct |
267 ms |
2144 KB |
Output is correct |
26 |
Correct |
504 ms |
2232 KB |
Output is correct |
27 |
Correct |
516 ms |
2168 KB |
Output is correct |
28 |
Correct |
504 ms |
2040 KB |
Output is correct |
29 |
Correct |
501 ms |
2296 KB |
Output is correct |
30 |
Correct |
9 ms |
2304 KB |
Output is correct |
31 |
Correct |
9 ms |
2304 KB |
Output is correct |
32 |
Correct |
8 ms |
2304 KB |
Output is correct |
33 |
Correct |
9 ms |
2304 KB |
Output is correct |
34 |
Correct |
9 ms |
2304 KB |
Output is correct |
35 |
Correct |
9 ms |
2304 KB |
Output is correct |
36 |
Correct |
10 ms |
2432 KB |
Output is correct |
37 |
Correct |
9 ms |
2304 KB |
Output is correct |
38 |
Correct |
10 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
768 KB |
Output is correct |
2 |
Correct |
7 ms |
768 KB |
Output is correct |
3 |
Correct |
8 ms |
768 KB |
Output is correct |
4 |
Correct |
8 ms |
768 KB |
Output is correct |
5 |
Correct |
8 ms |
768 KB |
Output is correct |
6 |
Correct |
10 ms |
768 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
11 ms |
768 KB |
Output is correct |
9 |
Correct |
10 ms |
768 KB |
Output is correct |
10 |
Correct |
10 ms |
768 KB |
Output is correct |
11 |
Correct |
8 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
8 ms |
768 KB |
Output is correct |
14 |
Correct |
8 ms |
768 KB |
Output is correct |
15 |
Correct |
8 ms |
768 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
7 ms |
512 KB |
Output is correct |
18 |
Correct |
7 ms |
512 KB |
Output is correct |
19 |
Correct |
7 ms |
512 KB |
Output is correct |
20 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2304 KB |
Output is correct |
2 |
Correct |
8 ms |
2304 KB |
Output is correct |
3 |
Correct |
8 ms |
2304 KB |
Output is correct |
4 |
Correct |
8 ms |
2304 KB |
Output is correct |
5 |
Correct |
9 ms |
2304 KB |
Output is correct |
6 |
Correct |
8 ms |
2304 KB |
Output is correct |
7 |
Correct |
7 ms |
2304 KB |
Output is correct |
8 |
Correct |
8 ms |
2304 KB |
Output is correct |
9 |
Correct |
8 ms |
2304 KB |
Output is correct |
10 |
Correct |
8 ms |
2304 KB |
Output is correct |
11 |
Correct |
9 ms |
2304 KB |
Output is correct |
12 |
Correct |
9 ms |
2304 KB |
Output is correct |
13 |
Correct |
8 ms |
2304 KB |
Output is correct |
14 |
Correct |
8 ms |
2304 KB |
Output is correct |
15 |
Correct |
8 ms |
2304 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
7 ms |
768 KB |
Output is correct |
18 |
Correct |
7 ms |
768 KB |
Output is correct |
19 |
Correct |
7 ms |
768 KB |
Output is correct |
20 |
Correct |
7 ms |
768 KB |
Output is correct |
21 |
Correct |
288 ms |
2176 KB |
Output is correct |
22 |
Correct |
259 ms |
2168 KB |
Output is correct |
23 |
Correct |
242 ms |
2168 KB |
Output is correct |
24 |
Correct |
258 ms |
2168 KB |
Output is correct |
25 |
Correct |
267 ms |
2144 KB |
Output is correct |
26 |
Correct |
504 ms |
2232 KB |
Output is correct |
27 |
Correct |
516 ms |
2168 KB |
Output is correct |
28 |
Correct |
504 ms |
2040 KB |
Output is correct |
29 |
Correct |
501 ms |
2296 KB |
Output is correct |
30 |
Correct |
9 ms |
2304 KB |
Output is correct |
31 |
Correct |
9 ms |
2304 KB |
Output is correct |
32 |
Correct |
8 ms |
2304 KB |
Output is correct |
33 |
Correct |
9 ms |
2304 KB |
Output is correct |
34 |
Correct |
9 ms |
2304 KB |
Output is correct |
35 |
Correct |
9 ms |
2304 KB |
Output is correct |
36 |
Correct |
10 ms |
2432 KB |
Output is correct |
37 |
Correct |
9 ms |
2304 KB |
Output is correct |
38 |
Correct |
10 ms |
2304 KB |
Output is correct |
39 |
Correct |
8 ms |
768 KB |
Output is correct |
40 |
Correct |
7 ms |
768 KB |
Output is correct |
41 |
Correct |
8 ms |
768 KB |
Output is correct |
42 |
Correct |
8 ms |
768 KB |
Output is correct |
43 |
Correct |
8 ms |
768 KB |
Output is correct |
44 |
Correct |
10 ms |
768 KB |
Output is correct |
45 |
Correct |
10 ms |
768 KB |
Output is correct |
46 |
Correct |
11 ms |
768 KB |
Output is correct |
47 |
Correct |
10 ms |
768 KB |
Output is correct |
48 |
Correct |
10 ms |
768 KB |
Output is correct |
49 |
Correct |
8 ms |
768 KB |
Output is correct |
50 |
Correct |
7 ms |
768 KB |
Output is correct |
51 |
Correct |
8 ms |
768 KB |
Output is correct |
52 |
Correct |
8 ms |
768 KB |
Output is correct |
53 |
Correct |
8 ms |
768 KB |
Output is correct |
54 |
Correct |
7 ms |
640 KB |
Output is correct |
55 |
Correct |
7 ms |
512 KB |
Output is correct |
56 |
Correct |
7 ms |
512 KB |
Output is correct |
57 |
Correct |
7 ms |
512 KB |
Output is correct |
58 |
Correct |
7 ms |
512 KB |
Output is correct |
59 |
Correct |
297 ms |
2556 KB |
Output is correct |
60 |
Correct |
273 ms |
2296 KB |
Output is correct |
61 |
Correct |
254 ms |
2296 KB |
Output is correct |
62 |
Correct |
299 ms |
2296 KB |
Output is correct |
63 |
Correct |
282 ms |
2296 KB |
Output is correct |
64 |
Correct |
584 ms |
2484 KB |
Output is correct |
65 |
Correct |
579 ms |
2424 KB |
Output is correct |
66 |
Correct |
581 ms |
2560 KB |
Output is correct |
67 |
Correct |
577 ms |
2424 KB |
Output is correct |
68 |
Correct |
578 ms |
2424 KB |
Output is correct |
69 |
Correct |
240 ms |
2296 KB |
Output is correct |
70 |
Correct |
243 ms |
2296 KB |
Output is correct |
71 |
Correct |
241 ms |
2356 KB |
Output is correct |
72 |
Correct |
249 ms |
2300 KB |
Output is correct |
73 |
Correct |
253 ms |
2296 KB |
Output is correct |
74 |
Correct |
62 ms |
760 KB |
Output is correct |
75 |
Correct |
60 ms |
760 KB |
Output is correct |
76 |
Correct |
61 ms |
760 KB |
Output is correct |
77 |
Correct |
62 ms |
760 KB |
Output is correct |
78 |
Correct |
63 ms |
760 KB |
Output is correct |