# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
105098 |
2019-04-10T14:25:02 Z |
win11905 |
Boat (APIO16_boat) |
C++11 |
|
1304 ms |
5812 KB |
#include <bits/stdc++.h>
#define long long long
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e3+5;
const int M = 1e9+7;
int n;
int dp[N], pf[N][N];
vector<int> coor, vec[N];
vector<pii> que;
int powMod(int a, int b) {
int val = 1;
for(; b; b >>= 1) {
if(b & 1) val = (1ll * val * a) % M;
a = (1ll * a * a) % M;
}
return val;
}
int f(int i, int x) {
int up = 1, down = 1;
for(int j = x; j < i+x; ++j) up = (1ll * up * j) % M;
for(int j = 1; j <= i; ++j) down = (1ll * down * j) % M;
return (1ll * up * powMod(down, M-2)) % M;
}
int pref[N];
int main() {
scanf("%d", &n);
dp[0] = 1, coor.emplace_back(0);
for(int i = 0, a, b; i < n; ++i) {
scanf("%d %d", &a, &b), b++;
coor.emplace_back(a), coor.emplace_back(b);
que.emplace_back(a, b);
}
sort(all(coor));
for(int i = 0, l, r; i < n; ++i) {
tie(l, r) = que[i];
l = lower_bound(all(coor), l) - coor.begin(), r = lower_bound(all(coor), r) - coor.begin();
pref[l]++, pref[r]--;
}
for(int i = 1; i < coor.size()-1; ++i) {
pref[i] += pref[i-1];
for(int j = 1; j <= pref[i]; ++j) pf[i][j] = f(j, coor[i+1] - coor[i]);
}
for(int i = 0, l, r; i < n; ++i) {
tie(l, r) = que[i];
l = lower_bound(all(coor), l) - coor.begin(), r = lower_bound(all(coor), r) - coor.begin();
for(int z = r-1, sum = 0; z >= l; --z, sum = 0) {
for(int k = z-1; ~k; --k) sum = (sum + dp[k]) % M;
vec[z].emplace_back(sum), dp[z] = 0;
int sz = vec[z].size();
for(int j = 0; j < sz; ++j) dp[z] = (dp[z] + 1ll * vec[z][j] * pf[z][sz-j]) % M;
}
}
int ans = 0;
for(int i = 1; i < coor.size()-1; ++i) ans = (ans + dp[i]) % M;
printf("%d\n", ans);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < coor.size()-1; ++i) {
~~^~~~~~~~~~~~~~~
boat.cpp:64:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < coor.size()-1; ++i) ans = (ans + dp[i]) % M;
~~^~~~~~~~~~~~~~~
boat.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:39:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b), b++;
~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2432 KB |
Output is correct |
2 |
Correct |
5 ms |
2432 KB |
Output is correct |
3 |
Correct |
6 ms |
2304 KB |
Output is correct |
4 |
Correct |
7 ms |
2404 KB |
Output is correct |
5 |
Correct |
6 ms |
2432 KB |
Output is correct |
6 |
Correct |
6 ms |
2304 KB |
Output is correct |
7 |
Correct |
5 ms |
2432 KB |
Output is correct |
8 |
Correct |
6 ms |
2304 KB |
Output is correct |
9 |
Correct |
6 ms |
2432 KB |
Output is correct |
10 |
Correct |
5 ms |
2304 KB |
Output is correct |
11 |
Correct |
6 ms |
2428 KB |
Output is correct |
12 |
Correct |
6 ms |
2432 KB |
Output is correct |
13 |
Correct |
5 ms |
2432 KB |
Output is correct |
14 |
Correct |
6 ms |
2432 KB |
Output is correct |
15 |
Correct |
6 ms |
2432 KB |
Output is correct |
16 |
Correct |
13 ms |
2432 KB |
Output is correct |
17 |
Correct |
12 ms |
2432 KB |
Output is correct |
18 |
Correct |
14 ms |
2304 KB |
Output is correct |
19 |
Correct |
12 ms |
2304 KB |
Output is correct |
20 |
Correct |
12 ms |
2408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2432 KB |
Output is correct |
2 |
Correct |
5 ms |
2432 KB |
Output is correct |
3 |
Correct |
6 ms |
2304 KB |
Output is correct |
4 |
Correct |
7 ms |
2404 KB |
Output is correct |
5 |
Correct |
6 ms |
2432 KB |
Output is correct |
6 |
Correct |
6 ms |
2304 KB |
Output is correct |
7 |
Correct |
5 ms |
2432 KB |
Output is correct |
8 |
Correct |
6 ms |
2304 KB |
Output is correct |
9 |
Correct |
6 ms |
2432 KB |
Output is correct |
10 |
Correct |
5 ms |
2304 KB |
Output is correct |
11 |
Correct |
6 ms |
2428 KB |
Output is correct |
12 |
Correct |
6 ms |
2432 KB |
Output is correct |
13 |
Correct |
5 ms |
2432 KB |
Output is correct |
14 |
Correct |
6 ms |
2432 KB |
Output is correct |
15 |
Correct |
6 ms |
2432 KB |
Output is correct |
16 |
Correct |
13 ms |
2432 KB |
Output is correct |
17 |
Correct |
12 ms |
2432 KB |
Output is correct |
18 |
Correct |
14 ms |
2304 KB |
Output is correct |
19 |
Correct |
12 ms |
2304 KB |
Output is correct |
20 |
Correct |
12 ms |
2408 KB |
Output is correct |
21 |
Correct |
734 ms |
5400 KB |
Output is correct |
22 |
Correct |
691 ms |
5400 KB |
Output is correct |
23 |
Correct |
639 ms |
5144 KB |
Output is correct |
24 |
Correct |
683 ms |
5388 KB |
Output is correct |
25 |
Correct |
684 ms |
5316 KB |
Output is correct |
26 |
Correct |
1273 ms |
5756 KB |
Output is correct |
27 |
Correct |
1283 ms |
5720 KB |
Output is correct |
28 |
Correct |
1246 ms |
5724 KB |
Output is correct |
29 |
Correct |
1261 ms |
5788 KB |
Output is correct |
30 |
Correct |
9 ms |
4372 KB |
Output is correct |
31 |
Correct |
9 ms |
4352 KB |
Output is correct |
32 |
Correct |
10 ms |
4352 KB |
Output is correct |
33 |
Correct |
10 ms |
4352 KB |
Output is correct |
34 |
Correct |
10 ms |
4352 KB |
Output is correct |
35 |
Correct |
9 ms |
4480 KB |
Output is correct |
36 |
Correct |
9 ms |
4352 KB |
Output is correct |
37 |
Correct |
10 ms |
4352 KB |
Output is correct |
38 |
Correct |
10 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1152 KB |
Output is correct |
2 |
Correct |
9 ms |
1280 KB |
Output is correct |
3 |
Correct |
9 ms |
1152 KB |
Output is correct |
4 |
Correct |
10 ms |
1152 KB |
Output is correct |
5 |
Correct |
10 ms |
1152 KB |
Output is correct |
6 |
Correct |
13 ms |
1152 KB |
Output is correct |
7 |
Correct |
14 ms |
1152 KB |
Output is correct |
8 |
Correct |
15 ms |
1152 KB |
Output is correct |
9 |
Correct |
15 ms |
1152 KB |
Output is correct |
10 |
Correct |
15 ms |
1152 KB |
Output is correct |
11 |
Correct |
9 ms |
1152 KB |
Output is correct |
12 |
Correct |
8 ms |
1152 KB |
Output is correct |
13 |
Correct |
10 ms |
1280 KB |
Output is correct |
14 |
Correct |
8 ms |
1152 KB |
Output is correct |
15 |
Correct |
9 ms |
1152 KB |
Output is correct |
16 |
Correct |
9 ms |
1152 KB |
Output is correct |
17 |
Correct |
10 ms |
1152 KB |
Output is correct |
18 |
Correct |
9 ms |
1124 KB |
Output is correct |
19 |
Correct |
10 ms |
1152 KB |
Output is correct |
20 |
Correct |
10 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2432 KB |
Output is correct |
2 |
Correct |
5 ms |
2432 KB |
Output is correct |
3 |
Correct |
6 ms |
2304 KB |
Output is correct |
4 |
Correct |
7 ms |
2404 KB |
Output is correct |
5 |
Correct |
6 ms |
2432 KB |
Output is correct |
6 |
Correct |
6 ms |
2304 KB |
Output is correct |
7 |
Correct |
5 ms |
2432 KB |
Output is correct |
8 |
Correct |
6 ms |
2304 KB |
Output is correct |
9 |
Correct |
6 ms |
2432 KB |
Output is correct |
10 |
Correct |
5 ms |
2304 KB |
Output is correct |
11 |
Correct |
6 ms |
2428 KB |
Output is correct |
12 |
Correct |
6 ms |
2432 KB |
Output is correct |
13 |
Correct |
5 ms |
2432 KB |
Output is correct |
14 |
Correct |
6 ms |
2432 KB |
Output is correct |
15 |
Correct |
6 ms |
2432 KB |
Output is correct |
16 |
Correct |
13 ms |
2432 KB |
Output is correct |
17 |
Correct |
12 ms |
2432 KB |
Output is correct |
18 |
Correct |
14 ms |
2304 KB |
Output is correct |
19 |
Correct |
12 ms |
2304 KB |
Output is correct |
20 |
Correct |
12 ms |
2408 KB |
Output is correct |
21 |
Correct |
734 ms |
5400 KB |
Output is correct |
22 |
Correct |
691 ms |
5400 KB |
Output is correct |
23 |
Correct |
639 ms |
5144 KB |
Output is correct |
24 |
Correct |
683 ms |
5388 KB |
Output is correct |
25 |
Correct |
684 ms |
5316 KB |
Output is correct |
26 |
Correct |
1273 ms |
5756 KB |
Output is correct |
27 |
Correct |
1283 ms |
5720 KB |
Output is correct |
28 |
Correct |
1246 ms |
5724 KB |
Output is correct |
29 |
Correct |
1261 ms |
5788 KB |
Output is correct |
30 |
Correct |
9 ms |
4372 KB |
Output is correct |
31 |
Correct |
9 ms |
4352 KB |
Output is correct |
32 |
Correct |
10 ms |
4352 KB |
Output is correct |
33 |
Correct |
10 ms |
4352 KB |
Output is correct |
34 |
Correct |
10 ms |
4352 KB |
Output is correct |
35 |
Correct |
9 ms |
4480 KB |
Output is correct |
36 |
Correct |
9 ms |
4352 KB |
Output is correct |
37 |
Correct |
10 ms |
4352 KB |
Output is correct |
38 |
Correct |
10 ms |
4352 KB |
Output is correct |
39 |
Correct |
10 ms |
1152 KB |
Output is correct |
40 |
Correct |
9 ms |
1280 KB |
Output is correct |
41 |
Correct |
9 ms |
1152 KB |
Output is correct |
42 |
Correct |
10 ms |
1152 KB |
Output is correct |
43 |
Correct |
10 ms |
1152 KB |
Output is correct |
44 |
Correct |
13 ms |
1152 KB |
Output is correct |
45 |
Correct |
14 ms |
1152 KB |
Output is correct |
46 |
Correct |
15 ms |
1152 KB |
Output is correct |
47 |
Correct |
15 ms |
1152 KB |
Output is correct |
48 |
Correct |
15 ms |
1152 KB |
Output is correct |
49 |
Correct |
9 ms |
1152 KB |
Output is correct |
50 |
Correct |
8 ms |
1152 KB |
Output is correct |
51 |
Correct |
10 ms |
1280 KB |
Output is correct |
52 |
Correct |
8 ms |
1152 KB |
Output is correct |
53 |
Correct |
9 ms |
1152 KB |
Output is correct |
54 |
Correct |
9 ms |
1152 KB |
Output is correct |
55 |
Correct |
10 ms |
1152 KB |
Output is correct |
56 |
Correct |
9 ms |
1124 KB |
Output is correct |
57 |
Correct |
10 ms |
1152 KB |
Output is correct |
58 |
Correct |
10 ms |
1152 KB |
Output is correct |
59 |
Correct |
710 ms |
5264 KB |
Output is correct |
60 |
Correct |
662 ms |
5172 KB |
Output is correct |
61 |
Correct |
634 ms |
5292 KB |
Output is correct |
62 |
Correct |
745 ms |
5512 KB |
Output is correct |
63 |
Correct |
681 ms |
5364 KB |
Output is correct |
64 |
Correct |
1304 ms |
5784 KB |
Output is correct |
65 |
Correct |
1284 ms |
5752 KB |
Output is correct |
66 |
Correct |
1280 ms |
5648 KB |
Output is correct |
67 |
Correct |
1281 ms |
5812 KB |
Output is correct |
68 |
Correct |
1270 ms |
5756 KB |
Output is correct |
69 |
Correct |
645 ms |
5268 KB |
Output is correct |
70 |
Correct |
615 ms |
5260 KB |
Output is correct |
71 |
Correct |
620 ms |
5240 KB |
Output is correct |
72 |
Correct |
668 ms |
5264 KB |
Output is correct |
73 |
Correct |
666 ms |
5228 KB |
Output is correct |
74 |
Correct |
719 ms |
5284 KB |
Output is correct |
75 |
Correct |
671 ms |
5252 KB |
Output is correct |
76 |
Correct |
689 ms |
5292 KB |
Output is correct |
77 |
Correct |
692 ms |
5316 KB |
Output is correct |
78 |
Correct |
738 ms |
5508 KB |
Output is correct |