# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
40995 |
2018-02-10T22:55:51 Z |
Alexa2001 |
Boat (APIO16_boat) |
C++14 |
|
1440 ms |
3184 KB |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 505, Mod = 1e9 + 7;
typedef long long ll;
int start[Nmax], finish[Nmax], dp[2*Nmax][Nmax], inv[Nmax], take[Nmax], sz[2*Nmax], nr[Nmax];
int i, n, m;
int inm(int x, int y) { return (ll)x*y%Mod; }
int inm(int x, int y, int z) { return inm( inm(x, y), z ); }
void add_to(int &x, int y) { x = (x+y)%Mod; }
int power(int a, int b)
{
int ans = 1;
while(b)
{
if(b&1) ans = inm(ans, a);
a = inm(a, a);
b >>= 1;
}
return ans;
}
void prepare()
{
map<int,int> mp;
cin >> n;
for(i=1; i<=n; ++i)
{
cin >> start[i] >> finish[i];
mp[start[i]] = mp[finish[i]+1] = 1;
}
int cnt = 0;
for(auto &it : mp) it.second = ++cnt;
int lst = mp.begin()->first;
mp.erase(mp.begin());
for(auto &it : mp)
sz[++m] = it.first - lst, lst = it.first;
for(i=1; i<=n; ++i)
start[i] = mp[start[i]], finish[i] = mp[finish[i]+1] - 1;
for(i=1; i<=n; ++i)
inv[i] = power(i, Mod-2);
}
void compute(int x)
{
int i, j;
nr[0] = 1;
for(i=1; i<=n; ++i)
{
if(i<=x) nr[i] = inm(nr[i-1], inv[i], x-i+1);
else nr[i] = 0;
take[i] = nr[i];
for(j=1; j<i && j<=x; ++j)
{
nr[j] = inm(nr[j], inm((i-1), inv[i-j]));
add_to(take[i], nr[j]);
}
}
}
int solve()
{
int i, j, k, good;
dp[0][0] = 1;
for(i=1; i<=m; ++i)
{
compute(sz[i]);
dp[i][0] = 1;
for(j=1; j<=n; ++j)
{
dp[i][j] = dp[i-1][j];
good = 1;
if( !(start[j] <= i && i <= finish[j]) ) continue;
for(k=j-1; k>=0; --k)
{
add_to(dp[i][j], inm(take[good], dp[i-1][k]));
good += (start[k] <= i && i <= finish[k]);
}
}
}
int ans = 0;
for(i=1; i<=n; ++i) add_to(ans, dp[m][i]);
return ans;
}
int main()
{
// freopen("input", "r", stdin);
prepare();
cout << solve() << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
515 ms |
2508 KB |
Output is correct |
2 |
Correct |
523 ms |
2508 KB |
Output is correct |
3 |
Correct |
515 ms |
2600 KB |
Output is correct |
4 |
Correct |
522 ms |
2632 KB |
Output is correct |
5 |
Correct |
517 ms |
2632 KB |
Output is correct |
6 |
Correct |
512 ms |
2636 KB |
Output is correct |
7 |
Correct |
530 ms |
2844 KB |
Output is correct |
8 |
Correct |
514 ms |
2844 KB |
Output is correct |
9 |
Correct |
510 ms |
2844 KB |
Output is correct |
10 |
Correct |
518 ms |
2844 KB |
Output is correct |
11 |
Correct |
509 ms |
2844 KB |
Output is correct |
12 |
Correct |
535 ms |
2844 KB |
Output is correct |
13 |
Correct |
513 ms |
2844 KB |
Output is correct |
14 |
Correct |
541 ms |
2844 KB |
Output is correct |
15 |
Correct |
547 ms |
2916 KB |
Output is correct |
16 |
Correct |
93 ms |
2916 KB |
Output is correct |
17 |
Correct |
100 ms |
2916 KB |
Output is correct |
18 |
Correct |
104 ms |
2916 KB |
Output is correct |
19 |
Correct |
100 ms |
2916 KB |
Output is correct |
20 |
Correct |
97 ms |
2916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
515 ms |
2508 KB |
Output is correct |
2 |
Correct |
523 ms |
2508 KB |
Output is correct |
3 |
Correct |
515 ms |
2600 KB |
Output is correct |
4 |
Correct |
522 ms |
2632 KB |
Output is correct |
5 |
Correct |
517 ms |
2632 KB |
Output is correct |
6 |
Correct |
512 ms |
2636 KB |
Output is correct |
7 |
Correct |
530 ms |
2844 KB |
Output is correct |
8 |
Correct |
514 ms |
2844 KB |
Output is correct |
9 |
Correct |
510 ms |
2844 KB |
Output is correct |
10 |
Correct |
518 ms |
2844 KB |
Output is correct |
11 |
Correct |
509 ms |
2844 KB |
Output is correct |
12 |
Correct |
535 ms |
2844 KB |
Output is correct |
13 |
Correct |
513 ms |
2844 KB |
Output is correct |
14 |
Correct |
541 ms |
2844 KB |
Output is correct |
15 |
Correct |
547 ms |
2916 KB |
Output is correct |
16 |
Correct |
93 ms |
2916 KB |
Output is correct |
17 |
Correct |
100 ms |
2916 KB |
Output is correct |
18 |
Correct |
104 ms |
2916 KB |
Output is correct |
19 |
Correct |
100 ms |
2916 KB |
Output is correct |
20 |
Correct |
97 ms |
2916 KB |
Output is correct |
21 |
Correct |
276 ms |
2916 KB |
Output is correct |
22 |
Correct |
278 ms |
2916 KB |
Output is correct |
23 |
Correct |
253 ms |
2916 KB |
Output is correct |
24 |
Correct |
279 ms |
2916 KB |
Output is correct |
25 |
Correct |
263 ms |
2916 KB |
Output is correct |
26 |
Correct |
403 ms |
2916 KB |
Output is correct |
27 |
Correct |
383 ms |
2916 KB |
Output is correct |
28 |
Correct |
378 ms |
2916 KB |
Output is correct |
29 |
Correct |
365 ms |
2916 KB |
Output is correct |
30 |
Correct |
508 ms |
2916 KB |
Output is correct |
31 |
Correct |
489 ms |
2916 KB |
Output is correct |
32 |
Correct |
498 ms |
2916 KB |
Output is correct |
33 |
Correct |
495 ms |
2916 KB |
Output is correct |
34 |
Correct |
493 ms |
2916 KB |
Output is correct |
35 |
Correct |
497 ms |
2948 KB |
Output is correct |
36 |
Correct |
487 ms |
2948 KB |
Output is correct |
37 |
Correct |
496 ms |
2948 KB |
Output is correct |
38 |
Correct |
487 ms |
2948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2948 KB |
Output is correct |
2 |
Correct |
12 ms |
2948 KB |
Output is correct |
3 |
Correct |
12 ms |
2948 KB |
Output is correct |
4 |
Correct |
13 ms |
2948 KB |
Output is correct |
5 |
Correct |
14 ms |
2948 KB |
Output is correct |
6 |
Correct |
14 ms |
2948 KB |
Output is correct |
7 |
Correct |
14 ms |
2948 KB |
Output is correct |
8 |
Correct |
13 ms |
2948 KB |
Output is correct |
9 |
Correct |
13 ms |
2948 KB |
Output is correct |
10 |
Correct |
13 ms |
2948 KB |
Output is correct |
11 |
Correct |
13 ms |
2948 KB |
Output is correct |
12 |
Correct |
12 ms |
2948 KB |
Output is correct |
13 |
Correct |
12 ms |
2948 KB |
Output is correct |
14 |
Correct |
13 ms |
2948 KB |
Output is correct |
15 |
Correct |
13 ms |
2948 KB |
Output is correct |
16 |
Correct |
7 ms |
2948 KB |
Output is correct |
17 |
Correct |
7 ms |
2948 KB |
Output is correct |
18 |
Correct |
7 ms |
2948 KB |
Output is correct |
19 |
Correct |
8 ms |
2948 KB |
Output is correct |
20 |
Correct |
7 ms |
2948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
515 ms |
2508 KB |
Output is correct |
2 |
Correct |
523 ms |
2508 KB |
Output is correct |
3 |
Correct |
515 ms |
2600 KB |
Output is correct |
4 |
Correct |
522 ms |
2632 KB |
Output is correct |
5 |
Correct |
517 ms |
2632 KB |
Output is correct |
6 |
Correct |
512 ms |
2636 KB |
Output is correct |
7 |
Correct |
530 ms |
2844 KB |
Output is correct |
8 |
Correct |
514 ms |
2844 KB |
Output is correct |
9 |
Correct |
510 ms |
2844 KB |
Output is correct |
10 |
Correct |
518 ms |
2844 KB |
Output is correct |
11 |
Correct |
509 ms |
2844 KB |
Output is correct |
12 |
Correct |
535 ms |
2844 KB |
Output is correct |
13 |
Correct |
513 ms |
2844 KB |
Output is correct |
14 |
Correct |
541 ms |
2844 KB |
Output is correct |
15 |
Correct |
547 ms |
2916 KB |
Output is correct |
16 |
Correct |
93 ms |
2916 KB |
Output is correct |
17 |
Correct |
100 ms |
2916 KB |
Output is correct |
18 |
Correct |
104 ms |
2916 KB |
Output is correct |
19 |
Correct |
100 ms |
2916 KB |
Output is correct |
20 |
Correct |
97 ms |
2916 KB |
Output is correct |
21 |
Correct |
276 ms |
2916 KB |
Output is correct |
22 |
Correct |
278 ms |
2916 KB |
Output is correct |
23 |
Correct |
253 ms |
2916 KB |
Output is correct |
24 |
Correct |
279 ms |
2916 KB |
Output is correct |
25 |
Correct |
263 ms |
2916 KB |
Output is correct |
26 |
Correct |
403 ms |
2916 KB |
Output is correct |
27 |
Correct |
383 ms |
2916 KB |
Output is correct |
28 |
Correct |
378 ms |
2916 KB |
Output is correct |
29 |
Correct |
365 ms |
2916 KB |
Output is correct |
30 |
Correct |
508 ms |
2916 KB |
Output is correct |
31 |
Correct |
489 ms |
2916 KB |
Output is correct |
32 |
Correct |
498 ms |
2916 KB |
Output is correct |
33 |
Correct |
495 ms |
2916 KB |
Output is correct |
34 |
Correct |
493 ms |
2916 KB |
Output is correct |
35 |
Correct |
497 ms |
2948 KB |
Output is correct |
36 |
Correct |
487 ms |
2948 KB |
Output is correct |
37 |
Correct |
496 ms |
2948 KB |
Output is correct |
38 |
Correct |
487 ms |
2948 KB |
Output is correct |
39 |
Correct |
12 ms |
2948 KB |
Output is correct |
40 |
Correct |
12 ms |
2948 KB |
Output is correct |
41 |
Correct |
12 ms |
2948 KB |
Output is correct |
42 |
Correct |
13 ms |
2948 KB |
Output is correct |
43 |
Correct |
14 ms |
2948 KB |
Output is correct |
44 |
Correct |
14 ms |
2948 KB |
Output is correct |
45 |
Correct |
14 ms |
2948 KB |
Output is correct |
46 |
Correct |
13 ms |
2948 KB |
Output is correct |
47 |
Correct |
13 ms |
2948 KB |
Output is correct |
48 |
Correct |
13 ms |
2948 KB |
Output is correct |
49 |
Correct |
13 ms |
2948 KB |
Output is correct |
50 |
Correct |
12 ms |
2948 KB |
Output is correct |
51 |
Correct |
12 ms |
2948 KB |
Output is correct |
52 |
Correct |
13 ms |
2948 KB |
Output is correct |
53 |
Correct |
13 ms |
2948 KB |
Output is correct |
54 |
Correct |
7 ms |
2948 KB |
Output is correct |
55 |
Correct |
7 ms |
2948 KB |
Output is correct |
56 |
Correct |
7 ms |
2948 KB |
Output is correct |
57 |
Correct |
8 ms |
2948 KB |
Output is correct |
58 |
Correct |
7 ms |
2948 KB |
Output is correct |
59 |
Correct |
1319 ms |
3004 KB |
Output is correct |
60 |
Correct |
1279 ms |
3068 KB |
Output is correct |
61 |
Correct |
1264 ms |
3184 KB |
Output is correct |
62 |
Correct |
1276 ms |
3184 KB |
Output is correct |
63 |
Correct |
1270 ms |
3184 KB |
Output is correct |
64 |
Correct |
1440 ms |
3184 KB |
Output is correct |
65 |
Correct |
1409 ms |
3184 KB |
Output is correct |
66 |
Correct |
1416 ms |
3184 KB |
Output is correct |
67 |
Correct |
1402 ms |
3184 KB |
Output is correct |
68 |
Correct |
1424 ms |
3184 KB |
Output is correct |
69 |
Correct |
1234 ms |
3184 KB |
Output is correct |
70 |
Correct |
1218 ms |
3184 KB |
Output is correct |
71 |
Correct |
1241 ms |
3184 KB |
Output is correct |
72 |
Correct |
1228 ms |
3184 KB |
Output is correct |
73 |
Correct |
1255 ms |
3184 KB |
Output is correct |
74 |
Correct |
159 ms |
3184 KB |
Output is correct |
75 |
Correct |
163 ms |
3184 KB |
Output is correct |
76 |
Correct |
159 ms |
3184 KB |
Output is correct |
77 |
Correct |
158 ms |
3184 KB |
Output is correct |
78 |
Correct |
161 ms |
3184 KB |
Output is correct |